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

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


Author: mjordan
Date: Mon May  6 13:52:49 2013
New Revision: 387771

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387771
Log:
Branch this so Qwell can use it (if he wants to)

Added:
    team/mjordan/ami-refactoring/
      - copied from r387611, trunk/
    team/mjordan/ami-refactoring/funcs/func_global.c
      - copied unchanged from r387630, trunk/funcs/func_global.c
    team/mjordan/ami-refactoring/include/asterisk.h
      - copied, changed from r387633, trunk/include/asterisk.h
    team/mjordan/ami-refactoring/main/asterisk.c
      - copied, changed from r387633, trunk/main/asterisk.c
    team/mjordan/ami-refactoring/main/manager_mwi.c   (with props)
    team/mjordan/ami-refactoring/main/manager_system.c   (with props)
Modified:
    team/mjordan/ami-refactoring/apps/app_chanspy.c
    team/mjordan/ami-refactoring/apps/app_minivm.c
    team/mjordan/ami-refactoring/apps/app_voicemail.c
    team/mjordan/ami-refactoring/channels/chan_dahdi.c
    team/mjordan/ami-refactoring/channels/chan_iax2.c
    team/mjordan/ami-refactoring/channels/chan_mgcp.c
    team/mjordan/ami-refactoring/channels/chan_sip.c
    team/mjordan/ami-refactoring/channels/chan_skinny.c
    team/mjordan/ami-refactoring/channels/chan_unistim.c
    team/mjordan/ami-refactoring/channels/sig_pri.c
    team/mjordan/ami-refactoring/include/asterisk/_private.h
    team/mjordan/ami-refactoring/include/asterisk/app.h
    team/mjordan/ami-refactoring/include/asterisk/manager.h
    team/mjordan/ami-refactoring/include/asterisk/stasis_channels.h
    team/mjordan/ami-refactoring/main/app.c
    team/mjordan/ami-refactoring/main/cli.c
    team/mjordan/ami-refactoring/main/json.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/stasis_channels.c
    team/mjordan/ami-refactoring/res/res_jabber.c
    team/mjordan/ami-refactoring/res/res_sip_mwi.c
    team/mjordan/ami-refactoring/res/res_xmpp.c

Modified: team/mjordan/ami-refactoring/apps/app_chanspy.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/apps/app_chanspy.c?view=diff&rev=387771&r1=387611&r2=387771
==============================================================================
--- team/mjordan/ami-refactoring/apps/app_chanspy.c (original)
+++ team/mjordan/ami-refactoring/apps/app_chanspy.c Mon May  6 13:52:49 2013
@@ -55,6 +55,8 @@
 #include "asterisk/lock.h"
 #include "asterisk/options.h"
 #include "asterisk/autochan.h"
+#include "asterisk/stasis_channels.h"
+#include "asterisk/json.h"
 
 #define AST_NAME_STRLEN 256
 #define NUM_SPYGROUPS 128
@@ -188,6 +190,8 @@
 		</description>
 		<see-also>
 			<ref type="application">ExtenSpy</ref>
+			<ref type="managerEvent">ChanSpyStart</ref>
+			<ref type="managerEvent">ChanSpyStop</ref>
 		</see-also>
 	</application>
 	<application name="ExtenSpy" language="en_US">
@@ -322,9 +326,10 @@
 		</description>
 		<see-also>
 			<ref type="application">ChanSpy</ref>
+			<ref type="managerEvent">ChanSpyStart</ref>
+			<ref type="managerEvent">ChanSpyStop</ref>
 		</see-also>
 	</application>
-	
 	<application name="DAHDIScan" language="en_US">
 		<synopsis>
 			Scan DAHDI channels to monitor calls.
@@ -338,6 +343,10 @@
 			<para>Allows a call center manager to monitor DAHDI channels in a
 			convenient way.  Use <literal>#</literal> to select the next channel and use <literal>*</literal> to exit.</para>
 		</description>
+		<see-also>
+			<ref type="managerEvent">ChanSpyStart</ref>
+			<ref type="managerEvent">ChanSpyStop</ref>
+		</see-also>
 	</application>
  ***/
 
@@ -509,6 +518,75 @@
 	}
 }
 
+static int pack_channel_into_message(struct ast_channel *chan, const char *role, struct ast_multi_channel_blob *payload)
+{
+	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
+	struct ast_channel_snapshot *snapshot;
+
+	message = stasis_cache_get(ast_channel_topic_all_cached(),
+			ast_channel_snapshot_type(),
+			ast_channel_uniqueid(chan));
+	if (!message) {
+		return -1;
+	}
+	snapshot = stasis_message_data(message);
+	ao2_ref(snapshot, +1);
+	ast_multi_channel_blob_add_channel(payload, role, snapshot);
+	return 0;
+}
+
+/*! \internal
+ * \brief Publish the chanspy message over Stasis-Core
+ * \param spyer The channel doing the spying
+ * \param spyee Who is being spied upon
+ * \start start If non-zero, the spying is starting. Otherwise, the spyer is
+ * finishing
+ */
+static void publish_chanspy_message(struct ast_channel *spyer, struct ast_channel *spyee, int start)
+{
+	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+	RAII_VAR(struct ast_multi_channel_blob *, payload, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
+
+	if (!spyer) {
+		ast_log(AST_LOG_WARNING, "Attempt to publish ChanSpy message for NULL spyer channel\n");
+		return;
+	}
+	blob = ast_json_pack("{s: s}",
+			     "type", start ? "chanspy_start" : "chanspy_stop");
+	if (!blob) {
+		ast_log(AST_LOG_ERROR, "Error creating blob for ChanSpy message\n");
+		return;
+	}
+
+	payload = ast_multi_channel_blob_create(blob);
+	if (!payload) {
+		ast_log(AST_LOG_ERROR, "Error creating payload for ChanSpy message\n");
+		return;
+	}
+
+	if (pack_channel_into_message(spyer, "spyer_channel", payload)) {
+		ast_log(AST_LOG_WARNING, "Unable to publish ChanSpy message: %s not in Stasis cache\n",
+				ast_channel_name(spyer));
+		return;
+	}
+
+	if (spyee) {
+		if (pack_channel_into_message(spyee, "spyee_channel", payload)) {
+			ast_log(AST_LOG_WARNING, "Unable to publish ChanSpy message: %s not in Stasis cache\n",
+					ast_channel_name(spyee));
+			return;
+		}
+	}
+
+	message = stasis_message_create(ast_multi_channel_blob_type(), payload);
+	if (!message) {
+		ast_log(AST_LOG_ERROR, "Error creating message object for ChanSpy message\n");
+		return;
+	}
+	stasis_publish(ast_channel_topic(spyer), message);
+}
+
 static int channel_spy(struct ast_channel *chan, struct ast_autochan *spyee_autochan,
 	int *volfactor, int fd, struct spy_dtmf_options *user_options, struct ast_flags *flags,
 	char *exitcontext)
@@ -521,38 +599,22 @@
 	struct ast_silence_generator *silgen = NULL;
 	struct ast_autochan *spyee_bridge_autochan = NULL;
 	const char *spyer_name;
-	struct ast_channel *chans[] = { chan, spyee_autochan->chan };
+
+	if (ast_check_hangup(chan) || ast_check_hangup(spyee_autochan->chan) ||
+			ast_test_flag(ast_channel_flags(spyee_autochan->chan), AST_FLAG_ZOMBIE)) {
+		return 0;
+	}
 
 	ast_channel_lock(chan);
 	spyer_name = ast_strdupa(ast_channel_name(chan));
 	ast_channel_unlock(chan);
 
-	/* We now hold the channel lock on spyee */
-
-	if (ast_check_hangup(chan) || ast_check_hangup(spyee_autochan->chan) ||
-			ast_test_flag(ast_channel_flags(spyee_autochan->chan), AST_FLAG_ZOMBIE)) {
-		return 0;
-	}
-
 	ast_channel_lock(spyee_autochan->chan);
 	name = ast_strdupa(ast_channel_name(spyee_autochan->chan));
 	ast_channel_unlock(spyee_autochan->chan);
 
 	ast_verb(2, "Spying on channel %s\n", name);
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when a channel has started spying on another channel.</synopsis>
-			<see-also>
-				<ref type="application">ChanSpy</ref>
-				<ref type="application">ExtenSpy</ref>
-				<ref type="managerEvent">ChanSpyStop</ref>
-			</see-also>
-		</managerEventInstance>
-	***/
-	ast_manager_event_multichan(EVENT_FLAG_CALL, "ChanSpyStart", 2, chans,
-			"SpyerChannel: %s\r\n"
-			"SpyeeChannel: %s\r\n",
-			spyer_name, name);
+	publish_chanspy_message(chan, spyee_autochan->chan, 1);
 
 	memset(&csth, 0, sizeof(csth));
 	ast_copy_flags(&csth.flags, flags, AST_FLAGS_ALL);
@@ -737,15 +799,7 @@
 	}
 
 	ast_verb(2, "Done Spying on channel %s\n", name);
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when a channel has stopped spying on another channel.</synopsis>
-			<see-also>
-				<ref type="managerEvent">ChanSpyStart</ref>
-			</see-also>
-		</managerEventInstance>
-	***/
-	ast_manager_event(chan, EVENT_FLAG_CALL, "ChanSpyStop", "SpyeeChannel: %s\r\n", name);
+	publish_chanspy_message(chan, NULL, 0);
 
 	return running;
 }

Modified: team/mjordan/ami-refactoring/apps/app_minivm.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/apps/app_minivm.c?view=diff&rev=387771&r1=387611&r2=387771
==============================================================================
--- team/mjordan/ami-refactoring/apps/app_minivm.c (original)
+++ team/mjordan/ami-refactoring/apps/app_minivm.c Mon May  6 13:52:49 2013
@@ -174,6 +174,8 @@
 #include "asterisk/linkedlists.h"
 #include "asterisk/callerid.h"
 #include "asterisk/event.h"
+#include "asterisk/stasis.h"
+#include "asterisk/stasis_channels.h"
 
 /*** DOCUMENTATION
 <application name="MinivmRecord" language="en_US">
@@ -495,7 +497,23 @@
 		<ref type="function">MINIVMCOUNTER</ref>
 	</see-also>
 </function>
-
+	<managerEvent language="en_US" name="MiniVoiceMail">
+		<managerEventInstance class="EVENT_FLAG_CALL">
+			<synopsis>Raised when a notification is sent out by a MiniVoiceMail application</synopsis>
+			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+				<parameter name="Action">
+					<para>What action was taken. Currently, this will always be <literal>SentNotification</literal></para>
+				</parameter>
+				<parameter name="Mailbox">
+					<para>The mailbox that the notification was about, specified as <literal>mailbox</literal>@<literal>context</literal></para>
+				</parameter>
+				<parameter name="Counter">
+					<para>A message counter derived from the <literal>MVM_COUNTER</literal> channel variable.</para>
+				</parameter>
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
 ***/
 
 #ifndef TRUE
@@ -1767,6 +1785,15 @@
 	int res = 0;
 	char oldlocale[100];
 	const char *counter;
+	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_mwi_state *, mwi_state, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_message *, chan_message,
+		stasis_cache_get(ast_channel_topic_all_cached(),
+				ast_channel_snapshot_type(),
+				ast_channel_uniqueid(chan)),
+		ao2_cleanup);
+	struct stasis_topic *mailbox_specific_topic;
 
 	if (!ast_strlen_zero(vmu->attachfmt)) {
 		if (strstr(format, vmu->attachfmt)) {
@@ -1826,10 +1853,41 @@
 		res = sendmail(etemplate, vmu, cidnum, cidname, filename, messageformat, duration, etemplate->attachment, MVM_MESSAGE_PAGE, counter);
 	}
 
-	ast_manager_event(chan, EVENT_FLAG_CALL, "MiniVoiceMail", "Action: SentNotification\rn\nMailbox: %s@%s\r\nCounter: %s\r\n", vmu->username, vmu->domain, counter);
+	blob = ast_json_pack("{s: s, s: s, s: s}",
+			     "type", "minivm",
+			     "action", "SentNotification",
+			     "counter", counter);
+	if (!blob) {
+		res = 1;
+		goto notify_cleanup;
+	}
+
+	mwi_state = ast_mwi_create(vmu->username, vmu->domain);
+	if (!mwi_state) {
+		res = 1;
+		goto notify_cleanup;
+	}
+
+	if (chan_message) {
+		mwi_state->snapshot = stasis_message_data(chan_message);
+		ao2_ref(mwi_state->snapshot, +1);
+	}
+
+	msg = ast_mwi_blob_create(mwi_state, blob);
+	if (!msg) {
+		res = 1;
+		goto notify_cleanup;
+	}
+	mailbox_specific_topic = ast_mwi_topic(mwi_state->uniqueid);
+	if (!mailbox_specific_topic) {
+		res = 1;
+		goto notify_cleanup;
+	}
+	stasis_publish(mailbox_specific_topic, msg);
 
 	run_externnotify(chan, vmu);		/* Run external notification */
 
+notify_cleanup:
 	if (etemplate->locale) {
 		setlocale(LC_TIME, oldlocale); /* Rest to old locale */
 	}
@@ -2011,7 +2069,7 @@
 
 /*!\internal
  * \brief Queue a message waiting event */
-static void queue_mwi_event(const char *mbx, const char *ctx, int urgent, int new, int old)
+static void queue_mwi_event(const char *channel_id, const char *mbx, const char *ctx, int urgent, int new, int old)
 {
 	char *mailbox, *context;
 
@@ -2021,7 +2079,7 @@
 		context = "default";
 	}
 
-	stasis_publish_mwi_state(mailbox, context, new + urgent, old);
+	stasis_publish_mwi_state_channel(mailbox, context, new + urgent, old, channel_id);
 }
 
 /*!\internal
@@ -2056,7 +2114,7 @@
 		ast_log(LOG_ERROR, "Need mailbox at context as argument. Sorry. Argument 0 %s\n", argv[0]);
 		return -1;
 	}
-	queue_mwi_event(mailbox, domain, atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
+	queue_mwi_event(ast_channel_uniqueid(chan), mailbox, domain, atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
 
 	return res;
 }

Modified: team/mjordan/ami-refactoring/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/apps/app_voicemail.c?view=diff&rev=387771&r1=387611&r2=387771
==============================================================================
--- team/mjordan/ami-refactoring/apps/app_voicemail.c (original)
+++ team/mjordan/ami-refactoring/apps/app_voicemail.c Mon May  6 13:52:49 2013
@@ -7741,7 +7741,7 @@
 	return cmd;
 }
 
-static void queue_mwi_event(const char *box, int urgent, int new, int old)
+static void queue_mwi_event(const char *channel_id, const char *box, int urgent, int new, int old)
 {
 	char *mailbox, *context;
 
@@ -7752,7 +7752,7 @@
 		context = "default";
 	}
 
-	stasis_publish_mwi_state(mailbox, context, new + urgent, old);
+	stasis_publish_mwi_state_channel(mailbox, context, new + urgent, old, channel_id);
 }
 
 /*!
@@ -7842,32 +7842,7 @@
 	if (ast_app_has_voicemail(ext_context, NULL)) 
 		ast_app_inboxcount2(ext_context, &urgentmsgs, &newmsgs, &oldmsgs);
 
-	queue_mwi_event(ext_context, urgentmsgs, newmsgs, oldmsgs);
-
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when a new message has been left in a voicemail mailbox.</synopsis>
-			<syntax>
-				<parameter name="Mailbox">
-					<para>The mailbox with the new message, specified as <emphasis>mailbox</emphasis>@<emphasis>context</emphasis></para>
-				</parameter>
-				<parameter name="Waiting">
-					<para>Whether or not the mailbox has access to a voicemail application.</para>
-				</parameter>
-				<parameter name="New">
-					<para>The number of new messages.</para>
-				</parameter>
-				<parameter name="Old">
-					<para>The number of old messages.</para>
-				</parameter>
-			</syntax>
-		</managerEventInstance>
-	***/
-	ast_manager_event(chan, EVENT_FLAG_CALL, "MessageWaiting",
-			"Mailbox: %s@%s\r\n"
-			"Waiting: %d\r\n"
-			"New: %d\r\n"
-			"Old: %d\r\n", vmu->mailbox, vmu->context, ast_app_has_voicemail(ext_context, NULL), newmsgs, oldmsgs);
+	queue_mwi_event(ast_channel_uniqueid(chan), ext_context, urgentmsgs, newmsgs, oldmsgs);
 	run_externnotify(vmu->context, vmu->mailbox, flag);
 
 #ifdef IMAP_STORAGE
@@ -11538,16 +11513,10 @@
 	if (valid) {
 		int new = 0, old = 0, urgent = 0;
 		snprintf(ext_context, sizeof(ext_context), "%s@%s", vms.username, vmu->context);
-		/*** DOCUMENTATION
-			<managerEventInstance>
-				<synopsis>Raised when a user has finished listening to their messages.</synopsis>
-			</managerEventInstance>
-		***/
-		ast_manager_event(chan, EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s\r\nWaiting: %d\r\n", ext_context, has_voicemail(ext_context, NULL));
 		/* Urgent flag not passwd to externnotify here */
 		run_externnotify(vmu->context, vmu->mailbox, NULL);
 		ast_app_inboxcount2(ext_context, &urgent, &new, &old);
-		queue_mwi_event(ext_context, urgent, new, old);
+		queue_mwi_event(ast_channel_uniqueid(chan), ext_context, urgent, new, old);
 	}
 #ifdef IMAP_STORAGE
 	/* expunge message - use UID Expunge if supported on IMAP server*/
@@ -11766,7 +11735,7 @@
 	strcat(mailbox_full, context);
 
 	inboxcount2(mailbox_full, &urgent, &new, &old);
-	queue_mwi_event(mailbox_full, urgent, new, old);
+	queue_mwi_event(NULL, mailbox_full, urgent, new, old);
 
 	return 0;
 }
@@ -12502,7 +12471,7 @@
 		mwi_sub->old_urgent = urgent;
 		mwi_sub->old_new = new;
 		mwi_sub->old_old = old;
-		queue_mwi_event(mwi_sub->mailbox, urgent, new, old);
+		queue_mwi_event(NULL, mwi_sub->mailbox, urgent, new, old);
 		run_externnotify(NULL, mwi_sub->mailbox, NULL);
 	}
 }
@@ -12647,7 +12616,7 @@
 	}
 
 	change = stasis_message_data(msg);
-	if (change->topic == stasis_mwi_topic_all()) {
+	if (change->topic == ast_mwi_topic_all()) {
 		return;
 	}
 
@@ -12668,10 +12637,10 @@
 static void start_poll_thread(void)
 {
 	int errcode;
-	mwi_sub_sub = stasis_subscribe(stasis_mwi_topic_all(), mwi_event_cb, NULL);
+	mwi_sub_sub = stasis_subscribe(ast_mwi_topic_all(), mwi_event_cb, NULL);
 
 	if (mwi_sub_sub) {
-		struct ao2_container *cached = stasis_cache_dump(stasis_mwi_topic_cached(), stasis_subscription_change_type());
+		struct ao2_container *cached = stasis_cache_dump(ast_mwi_topic_cached(), stasis_subscription_change_type());
 		if (cached) {
 			ao2_callback(cached, OBJ_MULTIPLE | OBJ_NODATA, dump_cache, NULL);
 		}
@@ -15269,7 +15238,7 @@
 	snprintf(ext_context, sizeof(ext_context), "%s@%s", vmu->mailbox, vmu->context);
 	run_externnotify(vmu->context, vmu->mailbox, NULL);
 	ast_app_inboxcount2(ext_context, &urgent, &new, &old);
-	queue_mwi_event(ext_context, urgent, new, old);
+	queue_mwi_event(NULL, ext_context, urgent, new, old);
 }
 
 static int vm_msg_forward(const char *from_mailbox,

Modified: team/mjordan/ami-refactoring/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/channels/chan_dahdi.c?view=diff&rev=387771&r1=387611&r2=387771
==============================================================================
--- team/mjordan/ami-refactoring/channels/chan_dahdi.c (original)
+++ team/mjordan/ami-refactoring/channels/chan_dahdi.c Mon May  6 13:52:49 2013
@@ -5426,10 +5426,10 @@
 	}
 
 	ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
-	mwi_message = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_type(), ast_str_buffer(uniqueid));
+	mwi_message = stasis_cache_get(ast_mwi_topic_cached(), ast_mwi_state_type(), ast_str_buffer(uniqueid));
 
 	if (mwi_message) {
-		struct stasis_mwi_state *mwi_state = stasis_message_data(mwi_message);
+		struct ast_mwi_state *mwi_state = stasis_message_data(mwi_message);
 		new_msgs = mwi_state->new_msgs;
 	} else {
 		new_msgs = ast_app_has_voicemail(p->mailbox, NULL);
@@ -13234,7 +13234,7 @@
 
 			ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
 
-			mailbox_specific_topic = stasis_mwi_topic(ast_str_buffer(uniqueid));
+			mailbox_specific_topic = ast_mwi_topic(ast_str_buffer(uniqueid));
 			if (mailbox_specific_topic) {
 				tmp->mwi_event_sub = stasis_subscribe(mailbox_specific_topic, mwi_event_cb, NULL);
 			}

Modified: team/mjordan/ami-refactoring/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/channels/chan_iax2.c?view=diff&rev=387771&r1=387611&r2=387771
==============================================================================
--- team/mjordan/ami-refactoring/channels/chan_iax2.c (original)
+++ team/mjordan/ami-refactoring/channels/chan_iax2.c Mon May  6 13:52:49 2013
@@ -8765,10 +8765,10 @@
 			}
 
 			ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
-			msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_type(), ast_str_buffer(uniqueid));
+			msg = stasis_cache_get(ast_mwi_topic_cached(), ast_mwi_state_type(), ast_str_buffer(uniqueid));
 
 			if (msg) {
-				struct stasis_mwi_state *mwi_state = stasis_message_data(msg);
+				struct ast_mwi_state *mwi_state = stasis_message_data(msg);
 				new = mwi_state->new_msgs;
 				old = mwi_state->old_msgs;
 			} else { /* Fall back on checking the mailbox directly */
@@ -12702,7 +12702,7 @@
 
 		ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
 
-		mailbox_specific_topic = stasis_mwi_topic(ast_str_buffer(uniqueid));
+		mailbox_specific_topic = ast_mwi_topic(ast_str_buffer(uniqueid));
 		if (mailbox_specific_topic) {
 			peer->mwi_event_sub = stasis_subscribe(mailbox_specific_topic, mwi_event_cb, NULL);
 		}

Modified: team/mjordan/ami-refactoring/channels/chan_mgcp.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/channels/chan_mgcp.c?view=diff&rev=387771&r1=387611&r2=387771
==============================================================================
--- team/mjordan/ami-refactoring/channels/chan_mgcp.c (original)
+++ team/mjordan/ami-refactoring/channels/chan_mgcp.c Mon May  6 13:52:49 2013
@@ -507,10 +507,10 @@
 
 	ast_str_set(&uniqueid, 0, "%s@%s", mbox, cntx);
 
-	msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_type(), ast_str_buffer(uniqueid));
+	msg = stasis_cache_get(ast_mwi_topic_cached(), ast_mwi_state_type(), ast_str_buffer(uniqueid));
 
 	if (msg) {
-		struct stasis_mwi_state *mwi_state = stasis_message_data(msg);
+		struct ast_mwi_state *mwi_state = stasis_message_data(msg);
 		new_msgs = mwi_state->new_msgs;
 	} else {
 		new_msgs = ast_app_has_voicemail(p->mailbox, NULL);
@@ -4175,7 +4175,7 @@
 					ast_str_reset(uniqueid);
 					ast_str_set(&uniqueid, 0, "%s@%s", mbox, cntx);
 
-					mailbox_specific_topic = stasis_mwi_topic(ast_str_buffer(uniqueid));
+					mailbox_specific_topic = ast_mwi_topic(ast_str_buffer(uniqueid));
 					if (mailbox_specific_topic) {
 						e->mwi_event_sub = stasis_subscribe(mailbox_specific_topic, mwi_event_cb, NULL);
 					}

Modified: team/mjordan/ami-refactoring/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/channels/chan_sip.c?view=diff&rev=387771&r1=387611&r2=387771
==============================================================================
--- team/mjordan/ami-refactoring/channels/chan_sip.c (original)
+++ team/mjordan/ami-refactoring/channels/chan_sip.c Mon May  6 13:52:49 2013
@@ -16702,7 +16702,7 @@
 		ao2_cleanup(peer);
 		return;
 	}
-	if (stasis_mwi_state_type() == stasis_message_type(msg)) {
+	if (ast_mwi_state_type() == stasis_message_type(msg)) {
 		sip_send_mwi_to_peer(peer, 0);
 	}
 }
@@ -27716,7 +27716,7 @@
 		ast_str_reset(uniqueid);
 		ast_str_set(&uniqueid, 0, "%s@%s", mailbox->mailbox, S_OR(mailbox->context, "default"));
 
-		mailbox_specific_topic = stasis_mwi_topic(ast_str_buffer(uniqueid));
+		mailbox_specific_topic = ast_mwi_topic(ast_str_buffer(uniqueid));
 		if (mailbox_specific_topic) {
 			ao2_ref(peer, +1);
 			mailbox->event_sub = stasis_subscribe(mailbox_specific_topic, mwi_event_cb, peer);
@@ -28926,12 +28926,12 @@
 	in_cache = 0;
 	AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) {
 		RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
-		struct stasis_mwi_state *mwi_state;
+		struct ast_mwi_state *mwi_state;
 
 		ast_str_reset(uniqueid);
 		ast_str_set(&uniqueid, 0, "%s@%s", mailbox->mailbox, S_OR(mailbox->context, "default"));
 
-		msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_type(), ast_str_buffer(uniqueid));
+		msg = stasis_cache_get(ast_mwi_topic_cached(), ast_mwi_state_type(), ast_str_buffer(uniqueid));
 		if (!msg) {
 			continue;
 		}

Modified: team/mjordan/ami-refactoring/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/channels/chan_skinny.c?view=diff&rev=387771&r1=387611&r2=387771
==============================================================================
--- team/mjordan/ami-refactoring/channels/chan_skinny.c (original)
+++ team/mjordan/ami-refactoring/channels/chan_skinny.c Mon May  6 13:52:49 2013
@@ -3518,8 +3518,8 @@
 		return;
 	}
 
-	if (msg && stasis_mwi_state_type() == stasis_message_type(msg)) {
-		struct stasis_mwi_state *mwi_state = stasis_message_data(msg);
+	if (msg && ast_mwi_state_type() == stasis_message_type(msg)) {
+		struct ast_mwi_state *mwi_state = stasis_message_data(msg);
 		l->newmsgs = mwi_state->new_msgs;
 	}
 
@@ -8256,7 +8256,7 @@
 
 		ast_str_set(&uniqueid, 0, "%s@%s", cfg_mailbox, cfg_context);
 
-		mailbox_specific_topic = stasis_mwi_topic(ast_str_buffer(uniqueid));
+		mailbox_specific_topic = ast_mwi_topic(ast_str_buffer(uniqueid));
 		if (mailbox_specific_topic) {
 			l->mwi_event_sub = stasis_subscribe(mailbox_specific_topic, mwi_event_cb, l);
 		}

Modified: team/mjordan/ami-refactoring/channels/chan_unistim.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/channels/chan_unistim.c?view=diff&rev=387771&r1=387611&r2=387771
==============================================================================
--- team/mjordan/ami-refactoring/channels/chan_unistim.c (original)
+++ team/mjordan/ami-refactoring/channels/chan_unistim.c Mon May  6 13:52:49 2013
@@ -5502,10 +5502,10 @@
 
 	ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
 
-	msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_type(), ast_str_buffer(uniqueid));
+	msg = stasis_cache_get(ast_mwi_topic_cached(), ast_mwi_state_type(), ast_str_buffer(uniqueid));
 
 	if (msg) {
-		struct stasis_mwi_state *mwi_state = stasis_message_data(msg);
+		struct ast_mwi_state *mwi_state = stasis_message_data(msg);
 		new = mwi_state->new_msgs;
 	} else { /* Fall back on checking the mailbox directly */
 		new = ast_app_has_voicemail(peer->mailbox, "INBOX");

Modified: team/mjordan/ami-refactoring/channels/sig_pri.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/channels/sig_pri.c?view=diff&rev=387771&r1=387611&r2=387771
==============================================================================
--- team/mjordan/ami-refactoring/channels/sig_pri.c (original)
+++ team/mjordan/ami-refactoring/channels/sig_pri.c Mon May  6 13:52:49 2013
@@ -8768,9 +8768,9 @@
 	const char *mbox_number;
 	int num_messages;
 	int idx;
-	struct stasis_mwi_state *mwi_state;
-
-	if (stasis_mwi_state_type() != stasis_message_type(msg)) {
+	struct ast_mwi_state *mwi_state;
+
+	if (ast_mwi_state_type() != stasis_message_type(msg)) {
 		return;
 	}
 
@@ -8816,7 +8816,7 @@
 {
 	int idx;
 	struct ast_str *uniqueid = ast_str_alloca(AST_MAX_MAILBOX_UNIQUEID);
-	struct stasis_mwi_state *mwi_state;
+	struct ast_mwi_state *mwi_state;
 
 	for (idx = 0; idx < ARRAY_LEN(pri->mbox); ++idx) {
 		RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
@@ -8828,7 +8828,7 @@
 		ast_str_reset(uniqueid);
 		ast_str_set(&uniqueid, 0, "%s@%s", pri->mbox[idx].number, pri->mbox[idx].context);
 
-		msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_type(), ast_str_buffer(uniqueid));
+		msg = stasis_cache_get(ast_mwi_topic_cached(), ast_mwi_state_type(), ast_str_buffer(uniqueid));
 		if (!msg) {
 			/* No cached event for this mailbox. */
 			continue;
@@ -9002,7 +9002,7 @@
 		ast_str_set(&mwi_description, -1, "%s span %d[%d] MWI mailbox %s@%s",
 			sig_pri_cc_type_name, pri->span, i, mbox_number, mbox_context);
 
-		mailbox_specific_topic = stasis_mwi_topic(ast_str_buffer(uniqueid));
+		mailbox_specific_topic = ast_mwi_topic(ast_str_buffer(uniqueid));
 		if (mailbox_specific_topic) {
 			pri->mbox[i].sub = stasis_subscribe(mailbox_specific_topic, sig_pri_mwi_event_cb, pri);
 		}

Copied: team/mjordan/ami-refactoring/include/asterisk.h (from r387633, trunk/include/asterisk.h)
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/include/asterisk.h?view=diff&rev=387771&p1=trunk/include/asterisk.h&r1=387633&p2=team/mjordan/ami-refactoring/include/asterisk.h&r2=387771
==============================================================================
--- trunk/include/asterisk.h (original)
+++ team/mjordan/ami-refactoring/include/asterisk.h Mon May  6 13:52:49 2013
@@ -3,7 +3,7 @@
  *
  * General Definitions for Asterisk top level program
  *
- * Copyright (C) 1999-2006, Digium, Inc.
+ * Copyright (C) 1999-2013, Digium, Inc.
  *
  * Mark Spencer <markster at digium.com>
  *
@@ -12,7 +12,8 @@
  */
 
 /*! \file
- * \brief Asterisk main include file. File version handling, generic pbx functions.
+ * \brief Asterisk main include file. File version handling, system \ref stasis
+ * topics and messages
  */
 
 #ifndef _ASTERISK_H
@@ -148,6 +149,15 @@
 struct stasis_message_type *ast_network_change_type(void);
 
 /*!
+ * \since 12
+ * \brief A \ref stasis_message_type for system status changes
+ *
+ * \retval NULL on error
+ * \retval \ref stasis_message_type for system status changes
+ */
+struct stasis_message_type *ast_system_status_type(void);
+
+/*!
  * \brief Register/unregister a source code file with the core.
  * \param file the source file name
  * \param version the version string (typically a SVN revision keyword string)

Modified: team/mjordan/ami-refactoring/include/asterisk/_private.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/include/asterisk/_private.h?view=diff&rev=387771&r1=387611&r2=387771
==============================================================================
--- team/mjordan/ami-refactoring/include/asterisk/_private.h (original)
+++ team/mjordan/ami-refactoring/include/asterisk/_private.h Mon May  6 13:52:49 2013
@@ -52,6 +52,20 @@
 int aco_init(void);             /*!< Provided by config_options.c */
 
 /*!
+ * \since 12
+ * \brief Possible return types for \ref ast_module_reload
+ */
+enum ast_module_reload_result {
+	AST_MODULE_RELOAD_SUCCESS = 0,		/*!< The module was reloaded succesfully */
+	AST_MODULE_RELOAD_QUEUED,			/*!< The module reload request was queued */
+	AST_MODULE_RELOAD_NOT_FOUND,		/*!< The requested module was not found */
+	AST_MODULE_RELOAD_ERROR,			/*!< An error occurred while reloading the module */
+	AST_MODULE_RELOAD_IN_PROGRESS,		/*!< A module reload request is already in progress */
+	AST_MODULE_RELOAD_UNINITIALIZED,	/*!< The module has not been initialized */
+	AST_MODULE_RELOAD_NOT_IMPLEMENTED,	/*!< This module doesn't support reloading */
+};
+
+/*!
  * \brief Reload asterisk modules.
  * \param name the name of the module to reload
  *
@@ -61,12 +75,9 @@
  * \note Modules are reloaded using their reload() functions, not unloading
  * them and loading them again.
  * 
- * \return 0 if the specified module was not found.
- * \retval 1 if the module was found but cannot be reloaded.
- * \retval -1 if a reload operation is already in progress.
- * \retval 2 if the specfied module was found and reloaded.
+ * \retval The \ref ast_module_reload_result status of the module load request
  */
-int ast_module_reload(const char *name);
+enum ast_module_reload_result ast_module_reload(const char *name);
 
 /*!
  * \brief Process reload requests received during startup.

Modified: team/mjordan/ami-refactoring/include/asterisk/app.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/include/asterisk/app.h?view=diff&rev=387771&r1=387611&r2=387771
==============================================================================
--- team/mjordan/ami-refactoring/include/asterisk/app.h (original)
+++ team/mjordan/ami-refactoring/include/asterisk/app.h Mon May  6 13:52:49 2013
@@ -1088,8 +1088,8 @@
 int ast_app_parse_timelen(const char *timestr, int *result, enum ast_timelen defunit);
 
 /*!
+ * \since 12
  * \brief Publish a MWI state update via stasis
- * \param[in] uniqueid A unique identifier for this mailbox (usually mailbox at context)
  * \param[in] mailbox The number identifying this mailbox
  * \param[in] context The context this mailbox resides in
  * \param[in] new_msgs The number of new messages in this mailbox
@@ -1099,15 +1099,32 @@
  * \since 12
  */
 #define stasis_publish_mwi_state(mailbox, context, new_msgs, old_msgs) \
-	stasis_publish_mwi_state_full(mailbox, context, new_msgs, old_msgs, NULL)
-
-/*!
- * \brief Publish a MWI state update via stasis with EID
- * \param[in] uniqueid A unique identifier for this mailbox (usually mailbox at context)
+	stasis_publish_mwi_state_full(mailbox, context, new_msgs, old_msgs, NULL, NULL)
+
+/*!
+ * \since 12
+ * \brief Publish a MWI state update associated with some channel
  * \param[in] mailbox The number identifying this mailbox
  * \param[in] context The context this mailbox resides in
  * \param[in] new_msgs The number of new messages in this mailbox
  * \param[in] old_msgs The number of old messages in this mailbox
+ * \param[in] channel_id A unique identifier for a channel associated with this
+ * change in mailbox state
+ * \retval 0 Success
+ * \retval -1 Failure
+ * \since 12
+ */
+#define stasis_publish_mwi_state_channel(mailbox, context, new_msgs, old_msgs, channel_id) \
+	stasis_publish_mwi_state_full(mailbox, context, new_msgs, old_msgs, channel_id, NULL)
+
+/*!
+ * \since 12
+ * \brief Publish a MWI state update via stasis with all parameters
+ * \param[in] mailbox The number identifying this mailbox
+ * \param[in] context The context this mailbox resides in
+ * \param[in] new_msgs The number of new messages in this mailbox
+ * \param[in] old_msgs The number of old messages in this mailbox
+ * \param[in] channel_id A unique identifier for a channel associated with this
  * \param[in] eid The EID of the server that originally published the message
  * \retval 0 Success
  * \retval -1 Failure
@@ -1118,6 +1135,7 @@
 			const char *context,
 			int new_msgs,
 			int old_msgs,
+			const char *channel_id,
 			struct ast_eid *eid);
 
 /*! \addtogroup StasisTopicsAndMessages
@@ -1128,7 +1146,7 @@
  * \brief The structure that contains MWI state
  * \since 12
  */
-struct stasis_mwi_state {
+struct ast_mwi_state {
 	AST_DECLARE_STRING_FIELDS(
 		AST_STRING_FIELD(uniqueid);	/*!< Unique identifier for this mailbox/context */
 		AST_STRING_FIELD(mailbox);	/*!< Mailbox for this event */
@@ -1136,8 +1154,54 @@
 	);
 	int new_msgs;				/*!< The current number of new messages for this mailbox */
 	int old_msgs;				/*!< The current number of old messages for this mailbox */
+	/*! If applicable, a snapshot of the channel that caused this MWI change */
+	struct ast_channel_snapshot *snapshot;
 	struct ast_eid eid;			/*!< The EID of the server where this message originated */
 };
+
+/*!
+ * \brief Object that represents an MWI update with some additional application
+ * defined data
+ */
+struct ast_mwi_blob {
+	struct ast_mwi_state *mwi_state;	/*!< MWI state */
+	struct ast_json *blob;				/*!< JSON blob of data */
+};
+
+/*!
+ * \since 12
+ * \brief Create a \ref ast_mwi_state object
+ *
+ * \retval \ref ast_mwi_state object on success
+ * \retval NULL on error
+ */
+struct ast_mwi_state *ast_mwi_create(const char *mailbox, const char *context);
+
+/*!
+ * \since 12
+ * \brief Creates a \ref ast_mwi_blob message.
+ *
+ * The \a blob JSON object requires a \c "type" field describing the blob. It
+ * should also be treated as immutable and not modified after it is put into the
+ * message.
+ *
+ * \param mwi_state MWI state associated with the update
+ * \param blob JSON object representing the data.
+ * \return \ref ast_mwi_blob message.
+ * \return \c NULL on error
+ */
+struct stasis_message *ast_mwi_blob_create(struct ast_mwi_state *mwi_state,
+					       struct ast_json *blob);
+
+/*!
+ * \since 12
+ * \brief Extracts the type field from a \ref ast_mwi_blob.
+ * Returned \c char* is still owned by \a obj
+ * \param obj MWI blob object.
+ * \return Type field value from the blob.
+ * \return \c NULL on error.
+ */
+const char *ast_mwi_blob_json_type(struct ast_mwi_blob *obj);
 
 /*!
  * \brief Get the Stasis topic for MWI messages
@@ -1145,7 +1209,7 @@
  * \retval NULL if it has not been allocated
  * \since 12
  */
-struct stasis_topic *stasis_mwi_topic_all(void);
+struct stasis_topic *ast_mwi_topic_all(void);
 
 /*!
  * \brief Get the Stasis topic for MWI messages on a unique ID
@@ -1154,7 +1218,7 @@
  * \retval NULL if it failed to be found or allocated
  * \since 12
  */
-struct stasis_topic *stasis_mwi_topic(const char *uniqueid);
+struct stasis_topic *ast_mwi_topic(const char *uniqueid);
 
 /*!
  * \brief Get the Stasis caching topic for MWI messages
@@ -1162,7 +1226,7 @@
  * \retval NULL if it has not been allocated
  * \since 12
  */
-struct stasis_caching_topic *stasis_mwi_topic_cached(void);
+struct stasis_caching_topic *ast_mwi_topic_cached(void);
 
 /*!
  * \brief Get the Stasis message type for MWI messages
@@ -1170,7 +1234,15 @@
  * \retval NULL if it has not been allocated
  * \since 12
  */
-struct stasis_message_type *stasis_mwi_state_type(void);
+struct stasis_message_type *ast_mwi_state_type(void);
+
+/*!
+ * \brief Get the Stasis message type for MWI messages accompanied by other data
+ * \retval The mesage type structure for MWI messages with a JSON blob
+ * \retval NULL if it has not been allocated
+ * \since 12
+ */
+struct stasis_message_type *ast_mwi_blob_type(void);
 
 /*! @} */
 

Modified: team/mjordan/ami-refactoring/include/asterisk/manager.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/include/asterisk/manager.h?view=diff&rev=387771&r1=387611&r2=387771
==============================================================================
--- team/mjordan/ami-refactoring/include/asterisk/manager.h (original)
+++ team/mjordan/ami-refactoring/include/asterisk/manager.h Mon May  6 13:52:49 2013
@@ -330,7 +330,7 @@
  * \retval NULL on error
  * \retval ast_str* on success (must be ast_freed by caller)
  */
-struct ast_str *ast_manager_build_channel_state_string_suffix(
+struct ast_str *ast_manager_build_channel_state_string_prefix(
 		const struct ast_channel_snapshot *snapshot,
 		const char *suffix);
 
@@ -349,10 +349,44 @@
 
 /*!
  * \brief Initialize support for AMI channel events.
- * \return 0 on success.
- * \return non-zero on error.
+ * \retval 0 on success.
+ * \retval non-zero on error.
  * \since 12
  */
 int manager_channels_init(void);
 
+/*!
+ * \since 12
+ * \brief Initialize support for AMI MWI events.
+ * \retval 0 on success
+ * \retval non-zero on error
+ */
+int manager_mwi_init(void);
+
+/*!
+ * \since 12
+ * \brief Initialize support for AMI system events.
+ * \retval 0 on success
+ * \retval non-zero on error
+ */
+int manager_system_init(void);
+
+/*!
+ * \since 12
+ * \brief Get the \ref stasis topic for AMI
+ *
+ * \retval The \ref stasis topic for AMI
+ * \retval NULL on error
+ */
+struct stasis_topic *ast_manager_get_topic(void);
+
+/*!
+ * \since 12
+ * \brief Get the \ref stasis_message_router for AMI
+ *
+ * \retval The \ref stasis_message_router for AMI
+ * \retval NULL on error
+ */
+struct stasis_message_router *ast_manager_get_message_router(void);
+
 #endif /* _ASTERISK_MANAGER_H */

Modified: team/mjordan/ami-refactoring/include/asterisk/stasis_channels.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/include/asterisk/stasis_channels.h?view=diff&rev=387771&r1=387611&r2=387771
==============================================================================
--- team/mjordan/ami-refactoring/include/asterisk/stasis_channels.h (original)
+++ team/mjordan/ami-refactoring/include/asterisk/stasis_channels.h Mon May  6 13:52:49 2013
@@ -120,6 +120,14 @@
 
 /*!
  * \since 12
+ * \brief Message type for \ref ast_multi_channel_blob messages.
+ *
+ * \retval Message type for \ref ast_multi_channel_blob messages.
+ */
+struct stasis_message_type *ast_multi_channel_blob_type(void);
+
+/*!
+ * \since 12
  * \brief Generate a snapshot of the channel state. This is an ao2 object, so
  * ao2_cleanup() to deallocate.
  *

Modified: team/mjordan/ami-refactoring/main/app.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/main/app.c?view=diff&rev=387771&r1=387611&r2=387771
==============================================================================
--- team/mjordan/ami-refactoring/main/app.c (original)
+++ team/mjordan/ami-refactoring/main/app.c Mon May  6 13:52:49 2013
@@ -68,6 +68,8 @@
 #include "asterisk/module.h"
 #include "asterisk/astobj2.h"
 #include "asterisk/stasis.h"
+#include "asterisk/stasis_channels.h"
+#include "asterisk/json.h"
 
 #define MWI_TOPIC_BUCKETS 57
 
@@ -85,6 +87,7 @@
 static struct stasis_topic *mwi_topic_all;
 static struct stasis_caching_topic *mwi_topic_cached;
 static struct stasis_message_type *mwi_state_type;
+static struct stasis_message_type *mwi_blob_type;
 static struct stasis_topic_pool *mwi_topic_pool;
 

[... 1700 lines stripped ...]



More information about the asterisk-commits mailing list