diff options
author | Kinsey Moore <kmoore@digium.com> | 2013-04-16 15:48:16 +0000 |
---|---|---|
committer | Kinsey Moore <kmoore@digium.com> | 2013-04-16 15:48:16 +0000 |
commit | 71a01725b850505a26d800288dc00e376e885dc1 (patch) | |
tree | 3a5d625f8fe0aeac4429834f74faaa7616e90d8e /funcs | |
parent | 191cf99ae1f821dec98199931fc775fc0716d27c (diff) |
Move presence state distribution to Stasis-core
Convert presence state events to Stasis-core messages and remove
redundant serializers where possible.
Review: https://reviewboard.asterisk.org/r/2410/
(closes issue ASTERISK-21102)
Patch-by: Kinsey Moore <kmoore@digium.com>
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@385862 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'funcs')
-rw-r--r-- | funcs/func_presencestate.c | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/funcs/func_presencestate.c b/funcs/func_presencestate.c index 66a3f2ef5..01e6d09c2 100644 --- a/funcs/func_presencestate.c +++ b/funcs/func_presencestate.c @@ -645,21 +645,20 @@ AST_TEST_DEFINE(test_invalid_parse_data) } struct test_cb_data { - enum ast_presence_state presence; - const char *provider; - const char *subtype; - const char *message; + struct ast_presence_state_message *presence_state; /* That's right. I'm using a semaphore */ sem_t sem; }; -static void test_cb(const struct ast_event *event, void *userdata) +static void test_cb(void *userdata, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg) { struct test_cb_data *cb_data = userdata; - cb_data->presence = ast_event_get_ie_uint(event, AST_EVENT_IE_PRESENCE_STATE); - cb_data->provider = ast_strdup(ast_event_get_ie_str(event, AST_EVENT_IE_PRESENCE_PROVIDER)); - cb_data->subtype = ast_strdup(ast_event_get_ie_str(event, AST_EVENT_IE_PRESENCE_SUBTYPE)); - cb_data->message = ast_strdup(ast_event_get_ie_str(event, AST_EVENT_IE_PRESENCE_MESSAGE)); + if (stasis_message_type(msg) != ast_presence_state_message_type()) { + return; + } + cb_data->presence_state = stasis_message_data(msg); + ao2_ref(cb_data->presence_state, +1); + sem_post(&cb_data->sem); } @@ -670,7 +669,7 @@ static void test_cb(const struct ast_event *event, void *userdata) */ AST_TEST_DEFINE(test_presence_state_change) { - struct ast_event_sub *test_sub; + struct stasis_subscription *test_sub; struct test_cb_data *cb_data; switch (cmd) { @@ -690,8 +689,7 @@ AST_TEST_DEFINE(test_presence_state_change) return AST_TEST_FAIL; } - if (!(test_sub = ast_event_subscribe(AST_EVENT_PRESENCE_STATE, - test_cb, "Test presence state callbacks", cb_data, AST_EVENT_IE_END))) { + if (!(test_sub = stasis_subscribe(ast_presence_state_topic_all(), test_cb, cb_data))) { return AST_TEST_FAIL; } @@ -701,16 +699,16 @@ AST_TEST_DEFINE(test_presence_state_change) presence_write(NULL, "PRESENCESTATE", "CustomPresence:TestPresenceStateChange", "away,down the hall,Quarterly financial meeting"); sem_wait(&cb_data->sem); - if (cb_data->presence != AST_PRESENCE_AWAY || - strcmp(cb_data->provider, "CustomPresence:TestPresenceStateChange") || - strcmp(cb_data->subtype, "down the hall") || - strcmp(cb_data->message, "Quarterly financial meeting")) { + if (cb_data->presence_state->state != AST_PRESENCE_AWAY || + strcmp(cb_data->presence_state->provider, "CustomPresence:TestPresenceStateChange") || + strcmp(cb_data->presence_state->subtype, "down the hall") || + strcmp(cb_data->presence_state->message, "Quarterly financial meeting")) { return AST_TEST_FAIL; } - ast_free((char *)cb_data->provider); - ast_free((char *)cb_data->subtype); - ast_free((char *)cb_data->message); + test_sub = stasis_unsubscribe(test_sub); + + ao2_cleanup(cb_data->presence_state); ast_free((char *)cb_data); ast_db_del("CustomPresence", "TestPresenceStateChange"); |