[asterisk-commits] dlee: branch dlee/ASTERISK-22451-ari-subscribe r399235 - in /team/dlee/ASTERI...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 17 10:44:30 CDT 2013


Author: dlee
Date: Tue Sep 17 10:44:28 2013
New Revision: 399235

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=399235
Log:
EndpointStateChange events

Modified:
    team/dlee/ASTERISK-22451-ari-subscribe/main/endpoints.c
    team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.c
    team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.h
    team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c
    team/dlee/ASTERISK-22451-ari-subscribe/rest-api/api-docs/applications.json

Modified: team/dlee/ASTERISK-22451-ari-subscribe/main/endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/main/endpoints.c?view=diff&rev=399235&r1=399234&r2=399235
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/main/endpoints.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/main/endpoints.c Tue Sep 17 10:44:28 2013
@@ -93,10 +93,9 @@
 {
 	const struct ast_endpoint *left = obj;
 	const struct ast_endpoint *right = arg;
-
-	ast_assert(!(flags & OBJ_KEY));
-
-	if (strcmp(left->id, right->id) == 0) {
+	const char *right_id = (flags & OBJ_KEY) ? arg : right->id;
+
+	if (strcmp(left->id, right_id) == 0) {
 		return CMP_MATCH;
 	}
 
@@ -290,12 +289,6 @@
 	return endpoint;
 }
 
-const char *ast_endpoint_get_tech(const struct ast_endpoint *endpoint)
-{
-	ast_assert(endpoint != NULL);
-	return endpoint->tech;
-}
-
 static struct stasis_message *create_endpoint_snapshot_message(struct ast_endpoint *endpoint)
 {
 	RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
@@ -331,9 +324,28 @@
 	stasis_message_router_unsubscribe(endpoint->router);
 }
 
+const char *ast_endpoint_get_tech(const struct ast_endpoint *endpoint)
+{
+	if (!endpoint) {
+		return NULL;
+	}
+	return endpoint->tech;
+}
+
 const char *ast_endpoint_get_resource(const struct ast_endpoint *endpoint)
 {
+	if (!endpoint) {
+		return NULL;
+	}
 	return endpoint->resource;
+}
+
+const char *ast_endpoint_get_id(const struct ast_endpoint *endpoint)
+{
+	if (!endpoint) {
+		return NULL;
+	}
+	return endpoint->id;
 }
 
 void ast_endpoint_set_state(struct ast_endpoint *endpoint,

Modified: team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.c?view=diff&rev=399235&r1=399234&r2=399235
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.c Tue Sep 17 10:44:28 2013
@@ -3469,7 +3469,7 @@
 	struct ast_json_iter *iter;
 	int has_bridge_ids = 0;
 	int has_channel_ids = 0;
-	int has_endpoint_names = 0;
+	int has_endpoint_ids = 0;
 	int has_name = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
@@ -3495,14 +3495,14 @@
 				res = 0;
 			}
 		} else
-		if (strcmp("endpoint_names", ast_json_object_iter_key(iter)) == 0) {
-			int prop_is_valid;
-			has_endpoint_names = 1;
+		if (strcmp("endpoint_ids", ast_json_object_iter_key(iter)) == 0) {
+			int prop_is_valid;
+			has_endpoint_ids = 1;
 			prop_is_valid = ast_ari_validate_list(
 				ast_json_object_iter_value(iter),
 				ast_ari_validate_string);
 			if (!prop_is_valid) {
-				ast_log(LOG_ERROR, "ARI Application field endpoint_names failed validation\n");
+				ast_log(LOG_ERROR, "ARI Application field endpoint_ids failed validation\n");
 				res = 0;
 			}
 		} else
@@ -3534,8 +3534,8 @@
 		res = 0;
 	}
 
-	if (!has_endpoint_names) {
-		ast_log(LOG_ERROR, "ARI Application missing required field endpoint_names\n");
+	if (!has_endpoint_ids) {
+		ast_log(LOG_ERROR, "ARI Application missing required field endpoint_ids\n");
 		res = 0;
 	}
 

Modified: team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.h?view=diff&rev=399235&r1=399234&r2=399235
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.h (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.h Tue Sep 17 10:44:28 2013
@@ -1126,7 +1126,7 @@
  * Application
  * - bridge_ids: List[string] (required)
  * - channel_ids: List[string] (required)
- * - endpoint_names: List[string] (required)
+ * - endpoint_ids: List[string] (required)
  * - name: string (required)
  */
 

Modified: team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c?view=diff&rev=399235&r1=399234&r2=399235
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c Tue Sep 17 10:44:28 2013
@@ -128,6 +128,7 @@
 		return NULL;
 	}
 
+	forwards->forward_type = FORWARD_CHANNEL;
 	forwards->topic_forward = stasis_forward_all(ast_channel_topic(chan),
 		app->topic);
 	if (!forwards->topic_forward) {
@@ -162,6 +163,7 @@
 		return NULL;
 	}
 
+	forwards->forward_type = FORWARD_BRIDGE;
 	forwards->topic_forward = stasis_forward_all(ast_bridge_topic(bridge),
 		app->topic);
 	if (!forwards->topic_forward) {
@@ -196,6 +198,7 @@
 		return NULL;
 	}
 
+	forwards->forward_type = FORWARD_ENDPOINT;
 	forwards->topic_forward = stasis_forward_all(ast_endpoint_topic(endpoint),
 		app->topic);
 	if (!forwards->topic_forward) {
@@ -441,6 +444,48 @@
         }
 }
 
+static struct ast_json *simple_endpoint_event(
+        const char *type,
+        struct ast_endpoint_snapshot *snapshot,
+        const struct timeval *tv)
+{
+        return ast_json_pack("{s: s, s: o, s: o}",
+                "type", type,
+                "timestamp", ast_json_timeval(*tv, NULL),
+                "endpoint", ast_endpoint_snapshot_to_json(snapshot));
+}
+
+static void sub_endpoint_update_handler(void *data,
+                struct stasis_subscription *sub,
+                struct stasis_topic *topic,
+                struct stasis_message *message)
+{
+        RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+	struct app *app = data;
+        struct stasis_cache_update *update;
+        struct ast_endpoint_snapshot *new_snapshot;
+        const struct timeval *tv;
+
+	ast_assert(stasis_message_type(message) == stasis_cache_update_type());
+
+	update = stasis_message_data(message);
+
+	ast_assert(update->type == ast_endpoint_snapshot_type());
+
+	new_snapshot = stasis_message_data(update->new_snapshot);
+	tv = update->new_snapshot ?
+		stasis_message_timestamp(update->new_snapshot) :
+		stasis_message_timestamp(message);
+
+	json = simple_endpoint_event("EndpointStateChange", new_snapshot, tv);
+
+        if (!json) {
+                return;
+        }
+
+        app_send(app, json);
+}
+
 static struct ast_json *simple_bridge_event(
         const char *type,
         struct ast_bridge_snapshot *snapshot,
@@ -570,6 +615,9 @@
 
         res |= stasis_message_router_add_cache_update(app->router,
 		ast_channel_snapshot_type(), sub_channel_update_handler, app);
+
+        res |= stasis_message_router_add_cache_update(app->router,
+		ast_endpoint_snapshot_type(), sub_endpoint_update_handler, app);
 
 	res |= stasis_message_router_set_default(app->router,
 		sub_default_handler, app);
@@ -696,10 +744,10 @@
 
 	json = ast_json_pack("{s: s, s: [], s: [], s: []}",
 		"name", app->name,
-		"channel_ids", "bridge_ids", "endpoint_names");
+		"channel_ids", "bridge_ids", "endpoint_ids");
 	channels = ast_json_object_get(json, "channel_ids");
 	bridges = ast_json_object_get(json, "bridge_ids");
-	endpoints = ast_json_object_get(json, "endpoint_names");
+	endpoints = ast_json_object_get(json, "endpoint_ids");
 
 	i = ao2_iterator_init(app->forwards, 0);
 	while ((obj = ao2_iterator_next(&i))) {

Modified: team/dlee/ASTERISK-22451-ari-subscribe/rest-api/api-docs/applications.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/rest-api/api-docs/applications.json?view=diff&rev=399235&r1=399234&r2=399235
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/rest-api/api-docs/applications.json (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/rest-api/api-docs/applications.json Tue Sep 17 10:44:28 2013
@@ -156,7 +156,7 @@
 					"description": "Id's for bridges subscribed to.",
 					"required": true
 				},
-				"endpoint_names": {
+				"endpoint_ids": {
 					"type": "List[string]",
 					"description": "{tech}/{resource} for endpoints subscribed to.",
 					"required": true




More information about the asterisk-commits mailing list