[asterisk-commits] mjordan: branch mjordan/ami-refactoring r387791 - in /team/mjordan/ami-refact...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon May 6 17:13:55 CDT 2013


Author: mjordan
Date: Mon May  6 17:13:53 2013
New Revision: 387791

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387791
Log:
Migrate hangup handlers over to Stasis-Core

Some other general cleanup included as well; finished the loader
work

Modified:
    team/mjordan/ami-refactoring/CHANGES
    team/mjordan/ami-refactoring/main/asterisk.c
    team/mjordan/ami-refactoring/main/cdr.c
    team/mjordan/ami-refactoring/main/dnsmgr.c
    team/mjordan/ami-refactoring/main/enum.c
    team/mjordan/ami-refactoring/main/loader.c
    team/mjordan/ami-refactoring/main/manager.c
    team/mjordan/ami-refactoring/main/manager_channels.c
    team/mjordan/ami-refactoring/main/manager_mwi.c
    team/mjordan/ami-refactoring/main/manager_system.c
    team/mjordan/ami-refactoring/main/pbx.c

Modified: team/mjordan/ami-refactoring/CHANGES
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/CHANGES?view=diff&rev=387791&r1=387790&r2=387791
==============================================================================
--- team/mjordan/ami-refactoring/CHANGES (original)
+++ team/mjordan/ami-refactoring/CHANGES Mon May  6 17:13:53 2013
@@ -58,6 +58,16 @@
    ChanVariable: bar=baz. When multiple channels are present in a single AMI
    event, the various ChanVariable fields will contain a suffix that specifies
    which channel they correspond to.
+
+ * All "Reload" events have been consolidated into a single event type. This
+   event will always contain a Module field specifying the name of the module
+   and a Status field denoting the result of the reload. All modules now issue
+   this event when being reloaded.
+
+ * The "ModuleLoadReport" event has been removed. Most AMI connections would
+   fail to receive this event due to being connected after modules have loaded.
+   AMI connections that want to know when Asterisk is ready should listen for
+   the "FullyBooted" event.
 
 Channel Drivers
 ------------------

Modified: team/mjordan/ami-refactoring/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/main/asterisk.c?view=diff&rev=387791&r1=387790&r2=387791
==============================================================================
--- team/mjordan/ami-refactoring/main/asterisk.c (original)
+++ team/mjordan/ami-refactoring/main/asterisk.c Mon May  6 17:13:53 2013
@@ -638,7 +638,7 @@
 {
 	RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
 
-	json_object = ast_json_pack("%s: %s",
+	json_object = ast_json_pack("s: s",
 			"type", "fullybooted");
 	publish_system_message(json_object);
 }

Modified: team/mjordan/ami-refactoring/main/cdr.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/main/cdr.c?view=diff&rev=387791&r1=387790&r2=387791
==============================================================================
--- team/mjordan/ami-refactoring/main/cdr.c (original)
+++ team/mjordan/ami-refactoring/main/cdr.c Mon May  6 17:13:53 2013
@@ -1674,7 +1674,6 @@
 
 	ast_mutex_unlock(&cdr_batch_lock);
 	ast_config_destroy(config);
-	manager_event(EVENT_FLAG_SYSTEM, "Reload", "Module: CDR\r\nMessage: CDR subsystem reload requested\r\n");
 }
 
 static void cdr_engine_shutdown(void)

Modified: team/mjordan/ami-refactoring/main/dnsmgr.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/main/dnsmgr.c?view=diff&rev=387791&r1=387790&r2=387791
==============================================================================
--- team/mjordan/ami-refactoring/main/dnsmgr.c (original)
+++ team/mjordan/ami-refactoring/main/dnsmgr.c Mon May  6 17:13:53 2013
@@ -514,7 +514,6 @@
 	}
 
 	ast_mutex_unlock(&refresh_lock);
-	manager_event(EVENT_FLAG_SYSTEM, "Reload", "Module: DNSmgr\r\nStatus: %s\r/nMessage: DNSmgr reload Requested\r\n", enabled ? "Enabled" : "Disabled");
 
 	return 0;
 }

Modified: team/mjordan/ami-refactoring/main/enum.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/main/enum.c?view=diff&rev=387791&r1=387790&r2=387791
==============================================================================
--- team/mjordan/ami-refactoring/main/enum.c (original)
+++ team/mjordan/ami-refactoring/main/enum.c Mon May  6 17:13:53 2013
@@ -1009,7 +1009,6 @@
 		ast_config_destroy(cfg);
 	}
 	ast_mutex_unlock(&enumlock);
-	manager_event(EVENT_FLAG_SYSTEM, "Reload", "Module: Enum\r\nStatus: Enabled\r\nMessage: ENUM reload Requested\r\n");
 	return 0;
 }
 

Modified: team/mjordan/ami-refactoring/main/loader.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/main/loader.c?view=diff&rev=387791&r1=387790&r2=387791
==============================================================================
--- team/mjordan/ami-refactoring/main/loader.c (original)
+++ team/mjordan/ami-refactoring/main/loader.c Mon May  6 17:13:53 2013
@@ -718,7 +718,7 @@
 	RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
 
-	json_object = ast_json_pack("{s: s, s: s, s: i}"
+	json_object = ast_json_pack("{s: s, s: s, s: i}",
 			"type", "module_reload",
 			"name", S_OR(name, "All"),
 			"result", (int)result);
@@ -735,6 +735,7 @@
 	if (!message) {
 		return;
 	}
+
 	stasis_publish(ast_system_topic(), message);
 }
 
@@ -743,7 +744,7 @@
 	struct ast_module *cur;
 	enum ast_module_reload_result res = AST_MODULE_RELOAD_NOT_FOUND;
 	int i;
-	ast_log(AST_LOG_NOTICE, "foo\n");
+
 	/* If we aren't fully booted, we just pretend we reloaded but we queue this
 	   up to run once we are booted up. */
 	if (!ast_fully_booted) {
@@ -790,7 +791,7 @@
 			ast_unlock_path(ast_config_AST_CONFIG_DIR);
 		}
 		ast_mutex_unlock(&reloadlock);
-		return res;
+		goto module_reload_exit;
 	}
 
 	AST_LIST_LOCK(&module_list);
@@ -823,6 +824,9 @@
 		if (info->reload() == AST_MODULE_LOAD_SUCCESS) {
 			res = AST_MODULE_RELOAD_SUCCESS;
 		}
+		if (name) {
+			break;
+		}
 	}
 	AST_LIST_UNLOCK(&module_list);
 
@@ -832,7 +836,6 @@
 	ast_mutex_unlock(&reloadlock);
 
 module_reload_exit:
-ast_log(AST_LOG_NOTICE, "foobar\n");
 	publish_reload_message(name, res);
 	return res;
 }
@@ -1245,25 +1248,6 @@
 	}
 
 	AST_LIST_UNLOCK(&module_list);
-
-	/* Tell manager clients that are aggressive at logging in that we're done
-	   loading modules. If there's a DNS problem in chan_sip, we might not
-	   even reach this */
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when all dynamic modules have finished their initial loading.</synopsis>
-			<syntax>
-				<parameter name="ModuleSelection">
-					<enumlist>
-						<enum name="Preload"/>
-						<enum name="All"/>
-					</enumlist>
-				</parameter>
-			</syntax>
-		</managerEventInstance>
-	***/
-	manager_event(EVENT_FLAG_SYSTEM, "ModuleLoadReport", "ModuleLoadStatus: Done\r\nModuleSelection: %s\r\nModuleCount: %d\r\n", preload_only ? "Preload" : "All", modulecount);
-
 	return res;
 }
 

Modified: team/mjordan/ami-refactoring/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/main/manager.c?view=diff&rev=387791&r1=387790&r2=387791
==============================================================================
--- team/mjordan/ami-refactoring/main/manager.c (original)
+++ team/mjordan/ami-refactoring/main/manager.c Mon May  6 17:13:53 2013
@@ -7551,17 +7551,19 @@
 
 	manager_enabled = 0;
 
-	if (manager_subscriptions_init()) {
-		return -1;
-	}
-	if (manager_channels_init()) {
-		return -1;
-	}
-	if (manager_mwi_init()) {
-		return -1;
-	}
-	if (manager_system_init()) {
-		return -1;
+	if (!reload) {
+		if (manager_subscriptions_init()) {
+			return -1;
+		}
+		if (manager_channels_init()) {
+			return -1;
+		}
+		if (manager_mwi_init()) {
+			return -1;
+		}
+		if (manager_system_init()) {
+			return -1;
+		}
 	}
 
 	if (!registered) {
@@ -8007,8 +8009,6 @@
 		httptimeout = newhttptimeout;
 	}
 
-	manager_event(EVENT_FLAG_SYSTEM, "Reload", "Module: Manager\r\nStatus: %s\r\nMessage: Manager reload Requested\r\n", manager_enabled ? "Enabled" : "Disabled");
-
 	ast_tcptls_server_start(&ami_desc);
 	if (tls_was_enabled && !ami_tls_cfg.enabled) {
 		ast_tcptls_server_stop(&amis_desc);

Modified: team/mjordan/ami-refactoring/main/manager_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/main/manager_channels.c?view=diff&rev=387791&r1=387790&r2=387791
==============================================================================
--- team/mjordan/ami-refactoring/main/manager_channels.c (original)
+++ team/mjordan/ami-refactoring/main/manager_channels.c Mon May  6 17:13:53 2013
@@ -324,6 +324,47 @@
 			</syntax>
 			<see-also>
 				<ref type="application">ChanSpyStart</ref>
+			</see-also>
+		</managerEventInstance>
+	</managerEvent>
+	<managerEvent language="en_US" name="HangupHandlerRun">
+		<managerEventInstance class="EVENT_FLAG_DIALPLAN">
+			<synopsis>Raised when a hangup handler is about to be called.</synopsis>
+			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+				<parameter name="Handler">
+					<para>Hangup handler parameter string passed to the Gosub application.</para>
+				</parameter>
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
+	<managerEvent language="en_US" name="HangupHandlerPop">
+		<managerEventInstance class="EVENT_FLAG_DIALPLAN">
+			<synopsis>
+				Raised when a hangup handler is removed from the handler stack
+				by the CHANNEL() function.
+			</synopsis>
+			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='HangupHandlerRun']/managerEventInstance/syntax/parameter)" />
+			</syntax>
+			<see-also>
+				<ref type="managerEvent">HangupHandlerPush</ref>
+				<ref type="function">CHANNEL</ref>
+			</see-also>
+		</managerEventInstance>
+	</managerEvent>
+	<managerEvent language="en_US" name="HangupHandlerPush">
+		<managerEventInstance class="EVENT_FLAG_DIALPLAN">
+			<synopsis>
+				Raised when a hangup handler is added to the handler stack by
+				the CHANNEL() function.
+			</synopsis>
+			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='HangupHandlerRun']/managerEventInstance/syntax/parameter)" />
+			</syntax>
+			<see-also>
+				<ref type="managerEvent">HangupHandlerPop</ref>
+				<ref type="function">CHANNEL</ref>
 			</see-also>
 		</managerEventInstance>
 	</managerEvent>
@@ -892,6 +933,35 @@
 		digit, duration_ms, direction);
 }
 
+static void channel_hangup_handler(struct ast_channel_blob *obj)
+{
+	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
+	const char *action = ast_json_string_get(ast_json_object_get(obj->blob, "action"));
+	const char *handler = ast_json_string_get(ast_json_object_get(obj->blob, "handler"));
+	const char *event;
+
+	channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
+
+	if (!channel_event_string) {
+		return;
+	}
+
+	if (!strcmp(action, "run")) {
+		event = "HangupHandlerRun";
+	} else if (!strcmp(action, "pop")) {
+		event = "HangupHandlerPop";
+	} else if (!strcmp(action, "push")) {
+		event = "HangupHandlerPush";
+	} else {
+		return;
+	}
+	manager_event(EVENT_FLAG_DIALPLAN, event,
+		"%s"
+		"Handler: %s\r\n",
+		ast_str_buffer(channel_event_string),
+		handler);
+}
+
 /*!
  * \brief Callback processing messages on the channel topic.
  */
@@ -911,6 +981,8 @@
 		channel_dtmf_begin(obj);
 	} else if (strcmp("dtmf_end", ast_channel_blob_json_type(obj)) == 0) {
 		channel_dtmf_end(obj);
+	} else if (strcmp("hangup_handler", ast_channel_blob_json_type(obj)) == 0) {
+		channel_hangup_handler(obj);
 	}
 }
 

Modified: team/mjordan/ami-refactoring/main/manager_mwi.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/main/manager_mwi.c?view=diff&rev=387791&r1=387790&r2=387791
==============================================================================
--- team/mjordan/ami-refactoring/main/manager_mwi.c (original)
+++ team/mjordan/ami-refactoring/main/manager_mwi.c Mon May  6 17:13:53 2013
@@ -123,7 +123,7 @@
 			"Waiting: %d\r\n"
 			"New: %d\r\n"
 			"Old: %d\r\n",
-			ast_str_buffer(channel_event_string),
+			AS_OR(channel_event_string, ""),
 			mwi_state->uniqueid,
 			ast_app_has_voicemail(mwi_state->uniqueid, NULL),
 			mwi_state->new_msgs,

Modified: team/mjordan/ami-refactoring/main/manager_system.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/main/manager_system.c?view=diff&rev=387791&r1=387790&r2=387791
==============================================================================
--- team/mjordan/ami-refactoring/main/manager_system.c (original)
+++ team/mjordan/ami-refactoring/main/manager_system.c Mon May  6 17:13:53 2013
@@ -45,7 +45,7 @@
 
 	result = ast_json_integer_get(ast_json_object_get(obj, "result"));
 	name = ast_json_string_get(ast_json_object_get(obj, "name"));
-	ast_log(AST_LOG_NOTICE, "foobar\n");
+
 	/*** DOCUMENTATION
 		<managerEventInstance>
 			<synopsis>Raised when a module has been reloaded in Asterisk.</synopsis>
@@ -132,7 +132,6 @@
 	struct ast_json *obj = payload->json;
 	const char *type = ast_json_string_get(ast_json_object_get(obj, "type"));
 
-	ast_log(AST_LOG_NOTICE, "%s\n", type);
 	if (!strcmp("fullybooted", type)) {
 		system_fully_booted_cb(obj);
 	} else if (!strcmp("shutdown", type)) {

Modified: team/mjordan/ami-refactoring/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/main/pbx.c?view=diff&rev=387791&r1=387790&r2=387791
==============================================================================
--- team/mjordan/ami-refactoring/main/pbx.c (original)
+++ team/mjordan/ami-refactoring/main/pbx.c Mon May  6 17:13:53 2013
@@ -5768,6 +5768,31 @@
 	ast_channel_unlock(chan);
 }
 
+/*!
+ * \internal
+ * \brief Publish a hangup handler related message to \ref stasis
+ */
+static void publish_hangup_handler_message(const char *action, struct ast_channel *chan, const char *handler)
+{
+	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
+
+	blob = ast_json_pack("{s: s, s: s}",
+			"type", "hangup_handler",
+			"action", action,
+			"handler", S_OR(handler, ""));
+	if (!blob) {
+		return;
+	}
+
+	message = ast_channel_blob_create(chan, blob);
+	if (!message) {
+		return;
+	}
+
+	stasis_publish(ast_channel_topic(chan), message);
+}
+
 int ast_pbx_hangup_handler_run(struct ast_channel *chan)
 {
 	struct ast_hangup_handler_list *handlers;
@@ -5797,23 +5822,7 @@
 			break;
 		}
 
-		/*** DOCUMENTATION
-			<managerEventInstance>
-				<synopsis>Raised when a hangup handler is about to be called.</synopsis>
-				<syntax>
-					<parameter name="Handler">
-						<para>Hangup handler parameter string passed to the Gosub application.</para>
-					</parameter>
-				</syntax>
-			</managerEventInstance>
-		***/
-		manager_event(EVENT_FLAG_DIALPLAN, "HangupHandlerRun",
-			"Channel: %s\r\n"
-			"Uniqueid: %s\r\n"
-			"Handler: %s\r\n",
-			ast_channel_name(chan),
-			ast_channel_uniqueid(chan),
-			h_handler->args);
+		publish_hangup_handler_message("run", chan, h_handler->args);
 		ast_channel_unlock(chan);
 
 		ast_app_exec_sub(NULL, chan, h_handler->args, 1);
@@ -5858,30 +5867,7 @@
 	handlers = ast_channel_hangup_handlers(chan);
 	h_handler = AST_LIST_REMOVE_HEAD(handlers, node);
 	if (h_handler) {
-		/*** DOCUMENTATION
-			<managerEventInstance>
-				<synopsis>
-					Raised when a hangup handler is removed from the handler
-					stack by the CHANNEL() function.
-				</synopsis>
-				<syntax>
-					<parameter name="Handler">
-						<para>Hangup handler parameter string passed to the Gosub application.</para>
-					</parameter>
-				</syntax>
-				<see-also>
-					<ref type="managerEvent">HangupHandlerPush</ref>
-					<ref type="function">CHANNEL</ref>
-				</see-also>
-			</managerEventInstance>
-		***/
-		manager_event(EVENT_FLAG_DIALPLAN, "HangupHandlerPop",
-			"Channel: %s\r\n"
-			"Uniqueid: %s\r\n"
-			"Handler: %s\r\n",
-			ast_channel_name(chan),
-			ast_channel_uniqueid(chan),
-			h_handler->args);
+		publish_hangup_handler_message("pop", chan, h_handler->args);
 	}
 	ast_channel_unlock(chan);
 	if (h_handler) {
@@ -5917,32 +5903,7 @@
 
 	handlers = ast_channel_hangup_handlers(chan);
 	AST_LIST_INSERT_HEAD(handlers, h_handler, node);
-
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>
-				Raised when a hangup handler is added to the handler
-				stack by the CHANNEL() function.
-			</synopsis>
-			<syntax>
-				<parameter name="Handler">
-					<para>Hangup handler parameter string passed to the Gosub application.</para>
-				</parameter>
-			</syntax>
-			<see-also>
-				<ref type="managerEvent">HangupHandlerPop</ref>
-				<ref type="function">CHANNEL</ref>
-			</see-also>
-		</managerEventInstance>
-	***/
-	manager_event(EVENT_FLAG_DIALPLAN, "HangupHandlerPush",
-		"Channel: %s\r\n"
-		"Uniqueid: %s\r\n"
-		"Handler: %s\r\n",
-		ast_channel_name(chan),
-		ast_channel_uniqueid(chan),
-		h_handler->args);
-
+	publish_hangup_handler_message("push", chan, h_handler->args);
 	ast_channel_unlock(chan);
 }
 




More information about the asterisk-commits mailing list