[asterisk-commits] dlee: branch dlee/ari-event-remodel2 r392282 - in /team/dlee/ari-event-remode...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jun 19 18:07:42 CDT 2013


Author: dlee
Date: Wed Jun 19 18:07:40 2013
New Revision: 392282

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392282
Log:
You know that scene in Doc Hollywood, where the mechanic has all the car parts laid out on the floor?

Removed:
    team/dlee/ari-event-remodel2/res/res_stasis_json_asterisk.c
    team/dlee/ari-event-remodel2/res/res_stasis_json_asterisk.exports.in
    team/dlee/ari-event-remodel2/res/res_stasis_json_bridges.c
    team/dlee/ari-event-remodel2/res/res_stasis_json_bridges.exports.in
    team/dlee/ari-event-remodel2/res/res_stasis_json_channels.c
    team/dlee/ari-event-remodel2/res/res_stasis_json_channels.exports.in
    team/dlee/ari-event-remodel2/res/res_stasis_json_endpoints.c
    team/dlee/ari-event-remodel2/res/res_stasis_json_endpoints.exports.in
    team/dlee/ari-event-remodel2/res/res_stasis_json_events.c
    team/dlee/ari-event-remodel2/res/res_stasis_json_events.exports.in
    team/dlee/ari-event-remodel2/res/res_stasis_json_playback.c
    team/dlee/ari-event-remodel2/res/res_stasis_json_playback.exports.in
    team/dlee/ari-event-remodel2/res/res_stasis_json_recordings.c
    team/dlee/ari-event-remodel2/res/res_stasis_json_recordings.exports.in
    team/dlee/ari-event-remodel2/res/res_stasis_json_sounds.c
    team/dlee/ari-event-remodel2/res/res_stasis_json_sounds.exports.in
    team/dlee/ari-event-remodel2/res/stasis_json/
    team/dlee/ari-event-remodel2/rest-api-templates/res_stasis_json_resource.c.mustache
    team/dlee/ari-event-remodel2/rest-api-templates/res_stasis_json_resource.exports.mustache
    team/dlee/ari-event-remodel2/rest-api-templates/stasis_json_resource.h.mustache
Modified:
    team/dlee/ari-event-remodel2/main/stasis_channels.c
    team/dlee/ari-event-remodel2/res/res_stasis.c
    team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c
    team/dlee/ari-event-remodel2/res/stasis_http/ari_model.h
    team/dlee/ari-event-remodel2/rest-api/api-docs/events.json

Modified: team/dlee/ari-event-remodel2/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/main/stasis_channels.c?view=diff&rev=392282&r1=392281&r2=392282
==============================================================================
--- team/dlee/ari-event-remodel2/main/stasis_channels.c (original)
+++ team/dlee/ari-event-remodel2/main/stasis_channels.c Wed Jun 19 18:07:40 2013
@@ -678,7 +678,9 @@
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_user_event_type);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_hangup_request_type);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_dtmf_begin_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_dtmf_end_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_dtmf_end_type,
+	.to_json = dtmf_end_to_json,
+);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_hold_type);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_unhold_type);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_start_type);

Modified: team/dlee/ari-event-remodel2/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/res_stasis.c?view=diff&rev=392282&r1=392281&r2=392282
==============================================================================
--- team/dlee/ari-event-remodel2/res/res_stasis.c (original)
+++ team/dlee/ari-event-remodel2/res/res_stasis.c Wed Jun 19 18:07:40 2013
@@ -48,7 +48,6 @@
  */
 
 /*** MODULEINFO
-	<depend>res_stasis_json_events</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -66,7 +65,6 @@
 #include "asterisk/strings.h"
 #include "stasis/app.h"
 #include "stasis/control.h"
-#include "stasis_json/resource_events.h"
 
 /*! Time to wait for a frame in the application */
 #define MAX_WAIT_MS 200
@@ -233,36 +231,76 @@
 /*! \brief Typedef for callbacks that get called on channel snapshot updates */
 typedef struct ast_json *(*channel_snapshot_monitor)(
 	struct ast_channel_snapshot *old_snapshot,
-	struct ast_channel_snapshot *new_snapshot);
+	struct ast_channel_snapshot *new_snapshot,
+	struct timeval tv);
+
+static struct ast_json *simple_channel_event(
+	const char *type,
+	struct ast_channel_snapshot *snapshot,
+	struct timeval tv)
+{
+	return ast_json_pack("{s: s, s: o, s: o}",
+		"type", type,
+		"timestamp", ast_json_timeval(tv, NULL),
+		"channel", ast_channel_snapshot_to_json(snapshot));
+}
+
+static struct ast_json *channel_created_event(
+	struct ast_channel_snapshot *snapshot,
+	struct timeval tv)
+{
+	return simple_channel_event("ChannelCreated", snapshot, tv);
+}
+
+static struct ast_json *channel_destroyed_event(
+	struct ast_channel_snapshot *snapshot,
+	struct timeval tv)
+{
+	return ast_json_pack("{s: s, s: o, s: i, s: s, s: o}",
+		"type", "ChannelDestroyed",
+		"timestamp", ast_json_timeval(tv, NULL),
+		"cause", snapshot->hangupcause,
+		"cause_txt", ast_cause2str(snapshot->hangupcause),
+		"channel", ast_channel_snapshot_to_json(snapshot));
+}
+
+static struct ast_json *channel_state_change_event(
+	struct ast_channel_snapshot *snapshot,
+	struct timeval tv)
+{
+	return simple_channel_event("ChannelStateChange", snapshot, tv);
+}
 
 /*! \brief Handle channel state changes */
 static struct ast_json *channel_state(
 	struct ast_channel_snapshot *old_snapshot,
-	struct ast_channel_snapshot *new_snapshot)
-{
-	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+	struct ast_channel_snapshot *new_snapshot,
+	struct timeval tv)
+{
 	struct ast_channel_snapshot *snapshot = new_snapshot ? new_snapshot : old_snapshot;
 
 	if (!old_snapshot) {
-		return stasis_json_event_channel_created_create(snapshot);
+		return channel_created_event(snapshot, tv);
 	} else if (!new_snapshot) {
-		json = ast_json_pack("{s: i, s: s}",
-			"cause", snapshot->hangupcause,
-			"cause_txt", ast_cause2str(snapshot->hangupcause));
-		if (!json) {
-			return NULL;
-		}
-		return stasis_json_event_channel_destroyed_create(snapshot, json);
+		return channel_destroyed_event(snapshot, tv);
 	} else if (old_snapshot->state != new_snapshot->state) {
-		return stasis_json_event_channel_state_change_create(snapshot);
+		return channel_state_change_event(snapshot, tv);
 	}
 
 	return NULL;
+}
+
+static struct ast_json *channel_dialplan_event(
+	struct ast_channel_snapshot *snapshot,
+	struct timeval tv)
+{
+	return simple_channel_event("ChannelDialplan", snapshot, tv);
 }
 
 static struct ast_json *channel_dialplan(
 	struct ast_channel_snapshot *old_snapshot,
-	struct ast_channel_snapshot *new_snapshot)
+	struct ast_channel_snapshot *new_snapshot,
+	struct timeval tv)
 {
 	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
 
@@ -280,19 +318,20 @@
 		return NULL;
 	}
 
-	json = ast_json_pack("{s: s, s: s}",
-		"application", new_snapshot->appl,
-		"application_data", new_snapshot->data);
-	if (!json) {
-		return NULL;
-	}
-
-	return stasis_json_event_channel_dialplan_create(new_snapshot, json);
+	return channel_dialplan_event(new_snapshot, tv);
+}
+
+static struct ast_json *channel_callerid_event(
+	struct ast_channel_snapshot *snapshot,
+	struct timeval tv)
+{
+	return simple_channel_event("ChannelCallerId", snapshot, tv);
 }
 
 static struct ast_json *channel_callerid(
 	struct ast_channel_snapshot *old_snapshot,
-	struct ast_channel_snapshot *new_snapshot)
+	struct ast_channel_snapshot *new_snapshot,
+	struct timeval tv)
 {
 	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
 
@@ -305,29 +344,10 @@
 		return NULL;
 	}
 
-	json = ast_json_pack("{s: i, s: s}",
-		"caller_presentation", new_snapshot->caller_pres,
-		"caller_presentation_txt", ast_describe_caller_presentation(new_snapshot->caller_pres));
-	if (!json) {
-		return NULL;
-	}
-
-	return stasis_json_event_channel_caller_id_create(new_snapshot, json);
-}
-
-static struct ast_json *channel_snapshot(
-	struct ast_channel_snapshot *old_snapshot,
-	struct ast_channel_snapshot *new_snapshot)
-{
-	if (!new_snapshot) {
-		return NULL;
-	}
-
-	return stasis_json_event_channel_snapshot_create(new_snapshot);
+	return channel_callerid_event(new_snapshot, tv);
 }
 
 channel_snapshot_monitor channel_monitors[] = {
-	channel_snapshot,
 	channel_state,
 	channel_dialplan,
 	channel_callerid
@@ -351,6 +371,9 @@
 	struct stasis_cache_update *update = stasis_message_data(message);
 	struct ast_channel_snapshot *new_snapshot = stasis_message_data(update->new_snapshot);
 	struct ast_channel_snapshot *old_snapshot = stasis_message_data(update->old_snapshot);
+	/* Pull timestamp from the new snapshot, or from the update message
+	 * when there isn't one. */
+	const struct timeval *tv = update->new_snapshot ? stasis_message_timestamp(update->new_snapshot) : stasis_message_timestamp(message);
 	int i;
 
 	watching_apps = get_apps_watching_channel(new_snapshot ? new_snapshot->uniqueid : old_snapshot->uniqueid);
@@ -361,7 +384,7 @@
 	for (i = 0; i < ARRAY_LEN(channel_monitors); ++i) {
 		RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
 
-		msg = channel_monitors[i](old_snapshot, new_snapshot);
+		msg = channel_monitors[i](old_snapshot, new_snapshot, *tv);
 		if (msg) {
 			ao2_callback(watching_apps, OBJ_NODATA, app_send_cb, msg);
 		}
@@ -446,7 +469,6 @@
 	int argc, char *argv[])
 {
 	RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
-	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
 	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
 
 	struct ast_json *json_args;
@@ -460,13 +482,16 @@
 		return -1;
 	}
 
-	blob = ast_json_pack("{s: []}", "args");
-	if (!blob) {
+	msg = ast_json_pack("{s: s, s: [], s: o}",
+		"type", "StasisStart",
+		"args",
+		"channel", ast_channel_snapshot_to_json(snapshot));
+	if (!msg) {
 		return -1;
 	}
 
 	/* Append arguments to args array */
-	json_args = ast_json_object_get(blob, "args");
+	json_args = ast_json_object_get(msg, "args");
 	ast_assert(json_args != NULL);
 	for (i = 0; i < argc; ++i) {
 		int r = ast_json_array_append(json_args,
@@ -477,11 +502,6 @@
 		}
 	}
 
-	msg = stasis_json_event_stasis_start_create(snapshot, blob);
-	if (!msg) {
-		return -1;
-	}
-
 	app_send(app, msg);
 	return 0;
 }
@@ -499,7 +519,9 @@
 		return -1;
 	}
 
-	msg = stasis_json_event_stasis_end_create(snapshot);
+	msg = ast_json_pack("{s: s, s: o, s: o}",
+		"type", "StasisEnd",
+		"channel", ast_channel_snapshot_to_json(snapshot));
 	if (!msg) {
 		return -1;
 	}
@@ -633,15 +655,11 @@
 	app = ao2_find(apps_registry, app_name, OBJ_KEY | OBJ_NOLOCK);
 
 	if (app) {
-		RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
 		RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
 
-		blob = ast_json_pack("{s: s}", "application", app_name);
-		if (blob) {
-			msg = stasis_json_event_application_replaced_create(blob);
-			if (msg) {
-				app_send(app, msg);
-			}
+		msg = ast_json_pack("{s: s}", "type", "ApplicationReplaced");
+		if (msg) {
+			app_send(app, msg);
 		}
 
 		app_update(app, handler, data);
@@ -667,7 +685,6 @@
 
 static struct ast_json *handle_blob_dtmf(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;
 
@@ -679,24 +696,10 @@
 		return NULL;
 	}
 
-	extra = ast_json_pack(
-		"{s: o}",
+	msg = ast_json_pack(
+		"{s: s, s: o}",
 		"digit", ast_json_ref(ast_json_object_get(obj->blob, "digit")));
-	if (!extra) {
-		return NULL;
-	}
-
-	return stasis_json_event_channel_dtmf_received_create(obj->snapshot, extra);
-}
-
-/* To simplify events, we'll only generate on DTMF end (dtmf_end type) */
-static void sub_dtmf_handler(void *data,
-		struct stasis_subscription *sub,
-		struct stasis_topic *topic,
-		struct stasis_message *message)
-{
-	struct ast_channel_blob *obj = stasis_message_data(message);
-	generic_blob_handler(obj, handle_blob_dtmf);
+	return channel_dtmf_received_event(obj->snapshot, );
 }
 
 static struct ast_json *handle_blob_userevent(struct ast_channel_blob *obj)
@@ -974,7 +977,7 @@
 	r |= stasis_message_router_add(channel_router, stasis_cache_update_type(), sub_channel_snapshot_handler, NULL);
 	r |= stasis_message_router_add(channel_router, ast_channel_user_event_type(), sub_userevent_handler, NULL);
 	r |= stasis_message_router_add(channel_router, ast_channel_varset_type(), sub_varset_handler, NULL);
-	r |= stasis_message_router_add(channel_router, ast_channel_dtmf_begin_type(), sub_dtmf_handler, NULL);
+	r |= stasis_message_router_add(channel_router, ast_channel_dtmf_end_type(), sub_dtmf_handler, NULL);
 	r |= stasis_message_router_add(channel_router, ast_channel_hangup_request_type(), sub_hangup_request_handler, NULL);
 	if (r) {
 		return AST_MODULE_LOAD_FAILURE;

Modified: team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c?view=diff&rev=392282&r1=392281&r2=392282
==============================================================================
--- team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c (original)
+++ team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c Wed Jun 19 18:07:40 2013
@@ -1068,31 +1068,9 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
-	int has_application = 0;
-	int has_application_data = 0;
 	int has_channel = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
-		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
-			int prop_res;
-			has_application = 1;
-			prop_res = ari_validate_string(
-				ast_json_object_iter_value(iter));
-			if (!prop_res) {
-				ast_log(LOG_ERROR, "ARI ChannelDialplan field application failed validation\n");
-				res = 0;
-			}
-		} else
-		if (strcmp("application_data", ast_json_object_iter_key(iter)) == 0) {
-			int prop_res;
-			has_application_data = 1;
-			prop_res = ari_validate_string(
-				ast_json_object_iter_value(iter));
-			if (!prop_res) {
-				ast_log(LOG_ERROR, "ARI ChannelDialplan field application_data failed validation\n");
-				res = 0;
-			}
-		} else
 		if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_channel = 1;
@@ -1111,14 +1089,6 @@
 		}
 	}
 
-	if (!has_application) {
-		ast_log(LOG_ERROR, "ARI ChannelDialplan missing required field application\n");
-		res = 0;
-	}
-	if (!has_application_data) {
-		ast_log(LOG_ERROR, "ARI ChannelDialplan missing required field application_data\n");
-		res = 0;
-	}
 	if (!has_channel) {
 		ast_log(LOG_ERROR, "ARI ChannelDialplan missing required field channel\n");
 		res = 0;
@@ -1133,6 +1103,7 @@
 	struct ast_json_iter *iter;
 	int has_channel = 0;
 	int has_digit = 0;
+	int has_duration_ms = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
 		if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
@@ -1155,6 +1126,16 @@
 				res = 0;
 			}
 		} else
+		if (strcmp("duration_ms", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_duration_ms = 1;
+			prop_res = ari_validate_int(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelDtmfReceived field duration_ms failed validation\n");
+				res = 0;
+			}
+		} else
 		{
 			ast_log(LOG_ERROR,
 				"ARI ChannelDtmfReceived has undocumented field %s\n",
@@ -1171,6 +1152,10 @@
 		ast_log(LOG_ERROR, "ARI ChannelDtmfReceived missing required field digit\n");
 		res = 0;
 	}
+	if (!has_duration_ms) {
+		ast_log(LOG_ERROR, "ARI ChannelDtmfReceived missing required field duration_ms\n");
+		res = 0;
+	}
 
 	return res;
 }
@@ -1310,39 +1295,6 @@
 	}
 	if (!has_channel) {
 		ast_log(LOG_ERROR, "ARI ChannelLeftBridge missing required field channel\n");
-		res = 0;
-	}
-
-	return res;
-}
-
-int ari_validate_channel_snapshot(struct ast_json *json)
-{
-	int res = 1;
-	struct ast_json_iter *iter;
-	int has_channel = 0;
-
-	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
-		if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
-			int prop_res;
-			has_channel = 1;
-			prop_res = ari_validate_channel(
-				ast_json_object_iter_value(iter));
-			if (!prop_res) {
-				ast_log(LOG_ERROR, "ARI ChannelSnapshot field channel failed validation\n");
-				res = 0;
-			}
-		} else
-		{
-			ast_log(LOG_ERROR,
-				"ARI ChannelSnapshot has undocumented field %s\n",
-				ast_json_object_iter_key(iter));
-			res = 0;
-		}
-	}
-
-	if (!has_channel) {
-		ast_log(LOG_ERROR, "ARI ChannelSnapshot missing required field channel\n");
 		res = 0;
 	}
 

Modified: team/dlee/ari-event-remodel2/res/stasis_http/ari_model.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/stasis_http/ari_model.h?view=diff&rev=392282&r1=392281&r2=392282
==============================================================================
--- team/dlee/ari-event-remodel2/res/stasis_http/ari_model.h (original)
+++ team/dlee/ari-event-remodel2/res/stasis_http/ari_model.h Wed Jun 19 18:07:40 2013
@@ -387,17 +387,6 @@
  * \returns False (zero) if invalid.
  */
 int ari_validate_channel_left_bridge(struct ast_json *json);
-
-/*!
- * \brief Validator for ChannelSnapshot.
- *
- * Some part of channel state changed.
- *
- * \param json JSON object to validate.
- * \returns True (non-zero) if valid.
- * \returns False (zero) if invalid.
- */
-int ari_validate_channel_snapshot(struct ast_json *json);
 
 /*!
  * \brief Validator for ChannelStateChange.
@@ -559,12 +548,11 @@
  * - cause_txt: string (required)
  * - channel: Channel (required)
  * ChannelDialplan
- * - application: string (required)
- * - application_data: string (required)
  * - channel: Channel (required)
  * ChannelDtmfReceived
  * - channel: Channel (required)
  * - digit: string (required)
+ * - duration_ms: int (required)
  * ChannelEnteredBridge
  * - bridge: Bridge (required)
  * - channel: Channel
@@ -574,8 +562,6 @@
  * - soft: boolean
  * ChannelLeftBridge
  * - bridge: Bridge (required)
- * - channel: Channel (required)
- * ChannelSnapshot
  * - channel: Channel (required)
  * ChannelStateChange
  * - channel: Channel (required)

Modified: team/dlee/ari-event-remodel2/rest-api/api-docs/events.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api/api-docs/events.json?view=diff&rev=392282&r1=392281&r2=392282
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api/api-docs/events.json (original)
+++ team/dlee/ari-event-remodel2/rest-api/api-docs/events.json Wed Jun 19 18:07:40 2013
@@ -136,17 +136,6 @@
 				}
 			}
 		},
-		"ChannelSnapshot": {
-			"id": "ChannelSnapshot",
-			"extends": "Event",
-			"description": "Some part of channel state changed.",
-			"properties": {
-				"channel": {
-					"required": true,
-					"type": "Channel"
-				}
-			}
-		},
 		"ChannelDestroyed": {
 			"id": "ChannelDestroyed",
 			"extends": "Event",
@@ -218,6 +207,11 @@
 					"type": "string",
 					"description": "DTMF digit received (0-9, A-E, # or *)"
 				},
+				"duration_ms": {
+					"required": true,
+					"type": "int",
+					"description": "Number of milliseconds DTMF was received"
+				},
 				"channel": {
 					"required": true,
 					"type": "Channel",
@@ -230,16 +224,6 @@
 			"extends": "Event",
 			"description": "Channel changed location in the dialplan.",
 			"properties": {
-				"application": {
-					"required": true,
-					"type": "string",
-					"description": "The application that the channel is currently in."
-				},
-				"application_data": {
-					"required": true,
-					"type": "string",
-					"description": "The data that was passed to the application when it was invoked."
-				},
 				"channel": {
 					"required": true,
 					"type": "Channel",




More information about the asterisk-commits mailing list