diff options
Diffstat (limited to 'decoders/appid/appid.c')
| -rw-r--r-- | decoders/appid/appid.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/decoders/appid/appid.c b/decoders/appid/appid.c new file mode 100644 index 0000000..642e8e6 --- /dev/null +++ b/decoders/appid/appid.c @@ -0,0 +1,49 @@ +#include "appid_internal.h" + +#include "stellar/utils.h" +#include "stellar/mq.h" + + + +static void appid_message_free(void *msg, void *msg_free_arg __unused) +{ + if(msg==NULL)return; + FREE(msg); +} + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-function-type" + +static void stellar_appid_on_msg_dispatch(int topic_id __unused, + void *msg, + on_msg_cb_func* on_msg_cb, + void *on_msg_cb_arg, + void *dispatch_arg __unused) +{ + on_appid_callback *appid_cb = (on_appid_callback *)on_msg_cb; + struct appid_message *appid_msg=(struct appid_message *)msg; + appid_cb(appid_msg->sess, appid_msg->origin, appid_msg->appid, appid_msg->appid_num, on_msg_cb_arg); +} + +int stellar_appid_subscribe(struct stellar_module_manager *mod_mgr, on_appid_callback *cb, void *args) +{ + if(mod_mgr==NULL)return -1; + int appid_topic_id=mq_schema_get_topic_id(stellar_module_manager_get_mq_schema(mod_mgr), APPID_MESSAGE_TOPIC); + if(appid_topic_id<0) + { + appid_topic_id=mq_schema_create_topic(stellar_module_manager_get_mq_schema(mod_mgr), APPID_MESSAGE_TOPIC, stellar_appid_on_msg_dispatch, mod_mgr, appid_message_free, NULL); + } + return mq_schema_subscribe(stellar_module_manager_get_mq_schema(mod_mgr), appid_topic_id, (on_msg_cb_func *)cb, args); +} + +#pragma GCC diagnostic pop + +int stellar_appid_create_topic(struct stellar_module_manager *mod_mgr) +{ + int app_topic_id=mq_schema_get_topic_id(stellar_module_manager_get_mq_schema(mod_mgr), APPID_MESSAGE_TOPIC); + if(app_topic_id < 0) + { + app_topic_id=mq_schema_create_topic(stellar_module_manager_get_mq_schema(mod_mgr), APPID_MESSAGE_TOPIC, stellar_appid_on_msg_dispatch, NULL,appid_message_free, NULL); + } + return app_topic_id; +}
\ No newline at end of file |
