diff options
author | Richard Mudgett <rmudgett@digium.com> | 2016-04-12 15:29:52 -0500 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2016-04-22 15:45:47 -0500 |
commit | 06632a0d11ff328a43a8fa6864d5e3a1523859d1 (patch) | |
tree | 83b400dca7b34120d310373a73714932eda47406 /main/stasis_message.c | |
parent | 6ddd856b866ca248a8e7aeaaf17c59469a6e1848 (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 0e6ff9204..37b9a2b6f 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); +} |