[asterisk-commits] dlee: branch dlee/stasis-dtmf r385258 - /team/dlee/stasis-dtmf/apps/app_stasis.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Apr 10 13:15:28 CDT 2013
Author: dlee
Date: Wed Apr 10 13:15:25 2013
New Revision: 385258
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385258
Log:
Adding DTMF to app_stasis events
Modified:
team/dlee/stasis-dtmf/apps/app_stasis.c
Modified: team/dlee/stasis-dtmf/apps/app_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-dtmf/apps/app_stasis.c?view=diff&rev=385258&r1=385257&r2=385258
==============================================================================
--- team/dlee/stasis-dtmf/apps/app_stasis.c (original)
+++ team/dlee/stasis-dtmf/apps/app_stasis.c Wed Apr 10 13:15:25 2013
@@ -358,6 +358,47 @@
return 0;
}
+static void dtmf_handler(struct app *app, struct ast_channel_blob *obj)
+{
+ RAII_VAR(struct ast_json *, extra, NULL, ast_json_unref);
+ RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
+ const char *direction;
+
+ /* To simplify events, we'll only generate on DTMF end */
+ if (ast_json_is_false(ast_json_object_get(obj->blob, "end"))) {
+ return;
+ }
+
+ /* And only on receive */
+ direction = ast_json_string_get(
+ ast_json_object_get(obj->blob, "direction"));
+
+ if (strcmp("Received", direction) != 0) {
+ return;
+ }
+
+ extra = ast_json_pack(
+ "{s: o}",
+ "digit", ast_json_ref(ast_json_object_get(obj->blob, "digit")));
+ if (!extra) {
+ return;
+ }
+
+ msg = app_event_create("dtmf-received", obj->snapshot, extra);
+ if (!msg) {
+ return;
+ }
+
+ app_send(app, msg);
+}
+
+static void blob_handler(struct app *app, struct ast_channel_blob *blob)
+{
+ if (strcmp(ast_channel_blob_json_type(blob), "dtmf") == 0) {
+ dtmf_handler(app, blob);
+ }
+}
+
static void sub_handler(void *data, struct stasis_subscription *sub,
struct stasis_topic *topic,
struct stasis_message *message)
@@ -373,6 +414,9 @@
return;
}
app_send(app, msg);
+ } else if (ast_channel_blob_type() == stasis_message_type(message)) {
+ struct ast_channel_blob *blob = stasis_message_data(message);
+ blob_handler(app, blob);
}
if (stasis_subscription_final_message(sub, message)) {
ao2_cleanup(data);
More information about the asterisk-commits
mailing list