[svn-commits] kmoore: branch kmoore/cel_cleanup r392238 - in /team/kmoore/cel_cleanup: apps...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jun 18 22:35:18 CDT 2013


Author: kmoore
Date: Tue Jun 18 22:35:15 2013
New Revision: 392238

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392238
Log:
Refactor CEL user defined events

Modified:
    team/kmoore/cel_cleanup/apps/app_celgenuserevent.c
    team/kmoore/cel_cleanup/include/asterisk/cel.h
    team/kmoore/cel_cleanup/main/cel.c

Modified: team/kmoore/cel_cleanup/apps/app_celgenuserevent.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/cel_cleanup/apps/app_celgenuserevent.c?view=diff&rev=392238&r1=392237&r2=392238
==============================================================================
--- team/kmoore/cel_cleanup/apps/app_celgenuserevent.c (original)
+++ team/kmoore/cel_cleanup/apps/app_celgenuserevent.c Tue Jun 18 22:35:15 2013
@@ -62,6 +62,7 @@
 {
 	int res = 0;
 	char *parse;
+	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(event);
 		AST_APP_ARG(extra);
@@ -74,7 +75,13 @@
 	parse = ast_strdupa(data);
 	AST_STANDARD_APP_ARGS(args, parse);
 
-	ast_cel_report_event(chan, AST_CEL_USER_DEFINED, args.event, args.extra, NULL);
+	blob = ast_json_pack("{s: s, s: s}",
+		"event", args.event,
+		"extra", args.extra);
+	if (!blob) {
+		return res;
+	}
+	ast_cel_publish_event(chan, AST_CEL_USER_DEFINED, blob);
 	return res;
 }
 

Modified: team/kmoore/cel_cleanup/include/asterisk/cel.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/cel_cleanup/include/asterisk/cel.h?view=diff&rev=392238&r1=392237&r2=392238
==============================================================================
--- team/kmoore/cel_cleanup/include/asterisk/cel.h (original)
+++ team/kmoore/cel_cleanup/include/asterisk/cel.h Tue Jun 18 22:35:15 2013
@@ -268,6 +268,18 @@
  */
 int ast_cel_fill_record(const struct ast_event *event, struct ast_cel_event_record *r);
 
+/*!
+ * \brief Publish a CEL event
+ * \since 12
+ *
+ * \param chan This is the primary channel associated with this channel event.
+ * \param event_type This is the type of call event being reported.
+ * \param blob This contains any additional parameters that need to be conveyed for this event.
+ */
+void ast_cel_publish_event(struct ast_channel *chan,
+	enum ast_cel_event_type event_type,
+	struct ast_json *blob);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/kmoore/cel_cleanup/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/cel_cleanup/main/cel.c?view=diff&rev=392238&r1=392237&r2=392238
==============================================================================
--- team/kmoore/cel_cleanup/main/cel.c (original)
+++ team/kmoore/cel_cleanup/main/cel.c Tue Jun 18 22:35:15 2013
@@ -140,6 +140,9 @@
 /*! Container for primary channel/bridge ID listing for 2 party bridges */
 static struct ao2_container *bridge_primaries;
 
+struct stasis_message_type *cel_generic_type(void);
+STASIS_MESSAGE_TYPE_DEFN(cel_generic_type);
+
 /*! The number of buckets into which primary channel uniqueids will be hashed */
 #define BRIDGE_PRIMARY_BUCKETS 251
 
@@ -1416,6 +1419,26 @@
 	save_dialstatus(blob);
 }
 
+static void cel_generic_cb(
+	void *data, struct stasis_subscription *sub,
+	struct stasis_topic *topic,
+	struct stasis_message *message)
+{
+	struct ast_channel_blob *obj = stasis_message_data(message);
+	int event_type = ast_json_integer_get(ast_json_object_get(obj->blob, "event_type"));
+	struct ast_json *event_details = ast_json_object_get(obj->blob, "event_details");
+
+	switch (event_type) {
+	case AST_CEL_USER_DEFINED:
+	{
+		const char *event = ast_json_string_get(ast_json_object_get(event_details, "event"));
+		const char *extra = ast_json_string_get(ast_json_object_get(event_details, "extra"));
+		report_event_snapshot(obj->snapshot, event_type, event, extra, NULL);
+		break;
+	}
+	}
+}
+
 static void ast_cel_engine_term(void)
 {
 	stasis_message_router_unsubscribe_and_join(cel_state_router);
@@ -1430,6 +1453,7 @@
 	ast_cli_unregister(&cli_status);
 	ao2_cleanup(bridge_primaries);
 	bridge_primaries = NULL;
+	STASIS_MESSAGE_TYPE_CLEANUP(cel_generic_type);
 }
 
 int ast_cel_engine_init(void)
@@ -1440,6 +1464,10 @@
 	}
 
 	if (!(cel_dialstatus_store = ao2_container_alloc(NUM_DIALSTATUS_BUCKETS, dialstatus_hash, dialstatus_cmp))) {
+		return -1;
+	}
+
+	if (STASIS_MESSAGE_TYPE_INIT(cel_generic_type)) {
 		return -1;
 	}
 
@@ -1506,6 +1534,11 @@
 	ret |= stasis_message_router_add(cel_state_router,
 		ast_parked_call_type(),
 		cel_parking_cb,
+		NULL);
+
+	ret |= stasis_message_router_add(cel_state_router,
+		cel_generic_type(),
+		cel_generic_cb,
 		NULL);
 
 	/* If somehow we failed to add any routes, just shut down the whole
@@ -1537,3 +1570,14 @@
 	return do_reload();
 }
 
+void ast_cel_publish_event(struct ast_channel *chan,
+	enum ast_cel_event_type event_type,
+	struct ast_json *blob)
+{
+	RAII_VAR(struct ast_channel_blob *, obj, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_json *, cel_blob, NULL, ast_json_unref);
+	cel_blob = ast_json_pack("{s: i, s: O}",
+		"event_type", event_type,
+		"event_details", blob);
+	ast_channel_publish_blob(chan, cel_generic_type(), cel_blob);
+}




More information about the svn-commits mailing list