diff options
author | Richard Mudgett <rmudgett@digium.com> | 2016-04-12 15:29:52 -0500 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2016-04-22 16:44:05 -0500 |
commit | ba63aa7c9e01919d53588e0e35066db554613d53 (patch) | |
tree | 4f0f0c72bdc19a21ff92c41e8911f0bdd873899c /main/stasis_message.c | |
parent | d5ee6acf28f67670b5afa1be0161280b33a5a9e9 (diff) |
Manager: Short circuit AMI message processing.
Improve AMI message processing performance if there are no consumers
listening for the messages. We now skip creating the AMI event message
text strings.
Change-Id: I7b22fc5ec4e500d00635c1a467aa8ea68a1bb2b3
Diffstat (limited to 'main/stasis_message.c')
-rw-r--r-- | main/stasis_message.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/main/stasis_message.c b/main/stasis_message.c index c797cdfa0..99721ef3c 100644 --- a/main/stasis_message.c +++ b/main/stasis_message.c @@ -170,17 +170,17 @@ const struct timeval *stasis_message_timestamp(const struct stasis_message *msg) return &msg->timestamp; } -#define INVOKE_VIRTUAL(fn, ...) \ - ({ \ - if (msg == NULL) { \ - return NULL; \ - } \ - ast_assert(msg->type != NULL); \ +#define INVOKE_VIRTUAL(fn, ...) \ + ({ \ + if (!msg) { \ + return NULL; \ + } \ + ast_assert(msg->type != NULL); \ ast_assert(msg->type->vtable != NULL); \ - if (msg->type->vtable->fn == NULL) { \ - return NULL; \ - } \ - msg->type->vtable->fn(__VA_ARGS__); \ + if (!msg->type->vtable->fn) { \ + return NULL; \ + } \ + msg->type->vtable->fn(__VA_ARGS__); \ }) struct ast_manager_event_blob *stasis_message_to_ami(struct stasis_message *msg) @@ -199,3 +199,18 @@ struct ast_event *stasis_message_to_event(struct stasis_message *msg) { return INVOKE_VIRTUAL(to_event, msg); } + +#define HAS_VIRTUAL(fn, msg) \ + ({ \ + if (!msg) { \ + return 0; \ + } \ + ast_assert(msg->type != NULL); \ + ast_assert(msg->type->vtable != NULL); \ + !!msg->type->vtable->fn; \ + }) + +int stasis_message_can_be_ami(struct stasis_message *msg) +{ + return HAS_VIRTUAL(to_ami, msg); +} |