[asterisk-commits] dlee: branch dlee/stasis-app r381804 - /team/dlee/stasis-app/apps/app_stasis.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Feb 19 16:24:10 CST 2013


Author: dlee
Date: Tue Feb 19 16:24:07 2013
New Revision: 381804

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=381804
Log:
Event handling

Modified:
    team/dlee/stasis-app/apps/app_stasis.c

Modified: team/dlee/stasis-app/apps/app_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/apps/app_stasis.c?view=diff&rev=381804&r1=381803&r2=381804
==============================================================================
--- team/dlee/stasis-app/apps/app_stasis.c (original)
+++ team/dlee/stasis-app/apps/app_stasis.c Tue Feb 19 16:24:07 2013
@@ -173,12 +173,10 @@
 }
 
 struct ast_json *stasis_app_event_create(const char *event_name, const struct ast_channel_snapshot *channel_info, const struct ast_json *extra_info) {
-	RAII_VAR(struct ast_json *, message, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_json *, message, NULL, ast_json_unref);
 	int r;
 
-	if (event_name == NULL) {
-		return NULL;
-	}
+	ast_assert(event_name != NULL);
 
 	if (extra_info) {
 		message = ast_json_deep_copy(extra_info);
@@ -190,9 +188,9 @@
 		return NULL;
 	}
 
-	r = ast_json_object_set(message, "event_name", ast_json_string_create(event_name));
+	r = ast_json_object_set(message, "event", ast_json_string_create(event_name));
 	if (r != 0) {
-		ast_log(LOG_ERROR, "Allocation failed\n");
+		ast_log(LOG_ERROR, "Failed to add event_name to message\n");
 		return NULL;
 	}
 
@@ -234,6 +232,11 @@
 	}
 
 	/* Set channel info */
+	snapshot = ast_channel_snapshot_create(chan);
+	if (!snapshot) {
+		ast_log(LOG_ERROR, "Allocation failed\n");
+		return -1;
+	}
 	msg = stasis_app_event_create("stasis-start", snapshot, msg_info);
 	if (!msg) {
 		return -1;
@@ -263,9 +266,14 @@
 
 static void sub_handler(void *data, struct stasis_topic *topic, struct stasis_message *message)
 {
-	/* TODO */
-	//struct stasis_app *app = data;
-	ast_assert(0);
+	struct stasis_app *app = data;
+	if (ast_channel_snapshot() == stasis_message_type(message)) {
+		RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
+		struct ast_channel_snapshot *snapshot = stasis_message_data(message);
+
+		msg = stasis_app_event_create("channel-state-change", snapshot, NULL);
+		app_send(app, msg);
+	}
 }
 
 




More information about the asterisk-commits mailing list