[svn-commits] dlee: branch dlee/stasis-http r380843 - in /team/dlee/stasis-http: apps/ incl...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Feb 4 22:13:44 CST 2013


Author: dlee
Date: Mon Feb  4 22:13:42 2013
New Revision: 380843

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380843
Log:
start/end events

Modified:
    team/dlee/stasis-http/apps/app_stasis.c
    team/dlee/stasis-http/include/asterisk/channel.h
    team/dlee/stasis-http/main/channel.c

Modified: team/dlee/stasis-http/apps/app_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/apps/app_stasis.c?view=diff&rev=380843&r1=380842&r2=380843
==============================================================================
--- team/dlee/stasis-http/apps/app_stasis.c (original)
+++ team/dlee/stasis-http/apps/app_stasis.c Mon Feb  4 22:13:42 2013
@@ -58,10 +58,73 @@
 
 static const char *stasis = "Stasis";
 
+static struct ast_json *json_name_number(const char *name, const char *number)
+{
+	return ast_json_pack("{s: s, s: s}",
+			     "name", name,
+			     "number", number);
+}
+
+static struct ast_json *json_timeval(struct timeval *tv)
+{
+	return ast_json_pack("{s: i, s: i}",
+			     "sec", tv->tv_sec,
+			     "usec", tv->tv_usec);
+}
+
+static struct ast_json *json_dialplan_cep(const char *context, const char *exten, int priority)
+{
+	return ast_json_pack("{s: s, s: s, s: i}",
+			     "context", context,
+			     "exten", exten,
+			     "priority", priority);
+}
+
+static struct ast_json *ast_channel_snapshot_to_json(struct ast_channel_snapshot *snapshot)
+{
+	RAII_VAR(struct ast_json *, json_chan, ast_json_object_create(), ast_json_unref);
+	int r = 0;
+
+	if (!json_chan) { ast_log(LOG_ERROR, "Error creating channel json object\n"); return NULL; }
+	r = ast_json_object_set(json_chan, "name", ast_json_string_create(snapshot->name));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+	r = ast_json_object_set(json_chan, "state", ast_json_string_create(ast_state2str(snapshot->state)));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+	r = ast_json_object_set(json_chan, "accountcode", ast_json_string_create(snapshot->accountcode));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+	r = ast_json_object_set(json_chan, "peeraccount", ast_json_string_create(snapshot->peeraccount));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+	r = ast_json_object_set(json_chan, "userfield", ast_json_string_create(snapshot->userfield));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+	r = ast_json_object_set(json_chan, "uniqueid", ast_json_string_create(snapshot->uniqueid));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+	r = ast_json_object_set(json_chan, "linkedid", ast_json_string_create(snapshot->linkedid));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+	r = ast_json_object_set(json_chan, "parkinglot", ast_json_string_create(snapshot->parkinglot));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+	r = ast_json_object_set(json_chan, "hangupsource", ast_json_string_create(snapshot->hangupsource));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+	r = ast_json_object_set(json_chan, "appl", ast_json_string_create(snapshot->appl));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+	r = ast_json_object_set(json_chan, "data", ast_json_string_create(snapshot->data));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+	r = ast_json_object_set(json_chan, "dialplan", json_dialplan_cep(snapshot->context, snapshot->exten, snapshot->priority));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+	r = ast_json_object_set(json_chan, "caller", json_name_number(snapshot->caller_name, snapshot->caller_number));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+	r = ast_json_object_set(json_chan, "connected", json_name_number(snapshot->connected_name, snapshot->connected_number));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+	r = ast_json_object_set(json_chan, "creationtime", json_timeval(&snapshot->creationtime));
+	if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
+
+	return ast_json_ref(json_chan);
+}
+
 static int send_start_msg(
 	const char *app_name, struct ast_channel *chan, int argc, char *argv[])
 {
 	RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
+	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ast_channel_snapshot_dtor);
 	struct ast_json *json_args;
 	int i;
 
@@ -69,7 +132,7 @@
 
 	msg = ast_json_pack("{s: s, s: s, s: []}",
 			    "command", "start",
-			    "channel", ast_channel_uniqueid(chan),
+			    "channel-id", ast_channel_uniqueid(chan),
 			    "args");
 	if (!msg) {
 		ast_log(LOG_ERROR, "Couldn't create message for %s\n", app_name);
@@ -80,27 +143,41 @@
 	json_args = ast_json_object_get(msg, "args");
 	ast_assert(json_args != NULL);
 	for (i = 0; i < argc; ++i) {
-		if (!ast_json_array_append(json_args, ast_json_string_create(argv[i]))) {
-			ast_log(LOG_ERROR, "Error appending arg to start message");
+		if (ast_json_array_append(json_args, ast_json_string_create(argv[i])) != 0) {
+			ast_log(LOG_ERROR, "Error appending arg to start message\n");
 			return -1;
 		}
 	}
 
+	/* Set channel info */
+	snapshot = ast_channel_snapshot_create(chan);
+	if (ast_json_object_set(msg, "channel-info", ast_channel_snapshot_to_json(snapshot)) != 0) {
+		ast_log(LOG_ERROR, "Couldn't attach channel-info info to message\n");
+		return -1;
+	}
+
 	return stasis_app_send(app_name, msg);
 }
 
 static int send_end_msg(const char *app_name, struct ast_channel *chan)
 {
 	RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
+	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ast_channel_snapshot_dtor);
 
 	ast_assert(chan != NULL);
 
 	msg = ast_json_pack("{s: s, s: s}",
 			    "command", "end",
-			    "channel", ast_channel_uniqueid(chan),
-			    "args");
+			    "channel-id", ast_channel_uniqueid(chan));
 	if (!msg) {
 		ast_log(LOG_ERROR, "Couldn't create message for %s\n", app_name);
+		return -1;
+	}
+
+	/* Set channel info */
+	snapshot = ast_channel_snapshot_create(chan);
+	if (ast_json_object_set(msg, "channel-info", ast_channel_snapshot_to_json(snapshot)) != 0) {
+		ast_log(LOG_ERROR, "Couldn't attach channel-info info to message\n");
 		return -1;
 	}
 
@@ -150,6 +227,10 @@
 				ast_debug(3, "%s: Received hangup\n", ast_channel_uniqueid(chan));
 				hungup = 1;
 			}
+			break;
+		default:
+			/* Not handled; discard */
+			break;
 		}
 	}
 

Modified: team/dlee/stasis-http/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/include/asterisk/channel.h?view=diff&rev=380843&r1=380842&r2=380843
==============================================================================
--- team/dlee/stasis-http/include/asterisk/channel.h (original)
+++ team/dlee/stasis-http/include/asterisk/channel.h Mon Feb  4 22:13:42 2013
@@ -4182,4 +4182,12 @@
  * \param orig_len The length of the snapshot to destroy
  */
 void ast_channel_snapshot_destroy(void *orig, size_t orig_len);
+
+/*!
+ * \since 12
+ * \brief \ref RAII_VAR friendly version of \ref ast_channel_snapshot_destroy.
+ *
+ * \param snapshot The snapshot to destroy
+ */
+void ast_channel_snapshot_dtor(struct ast_channel_snapshot *snapshot);
 #endif /* _ASTERISK_CHANNEL_H */

Modified: team/dlee/stasis-http/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/main/channel.c?view=diff&rev=380843&r1=380842&r2=380843
==============================================================================
--- team/dlee/stasis-http/main/channel.c (original)
+++ team/dlee/stasis-http/main/channel.c Mon Feb  4 22:13:42 2013
@@ -11288,3 +11288,9 @@
 	struct ast_channel_snapshot *orig = orig_in;
 	ast_string_field_free_memory(orig);
 }
+
+void ast_channel_snapshot_dtor(struct ast_channel_snapshot *snapshot)
+{
+	ast_channel_snapshot_destroy(snapshot, sizeof(*snapshot));
+	ast_free(snapshot);
+}




More information about the svn-commits mailing list