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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 8 17:08:41 CDT 2013


Author: mjordan
Date: Wed May  8 17:08:40 2013
New Revision: 388076

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=388076
Log:
Update channel snapshot to not rely on JSON type field

This handle dlee's changes. System and MWI topics still have
to be throught through.

Modified:
    team/mjordan/ami-refactoring/   (props changed)
    team/mjordan/ami-refactoring/apps/app_directory.c
    team/mjordan/ami-refactoring/apps/app_userevent.c
    team/mjordan/ami-refactoring/include/asterisk/stasis.h
    team/mjordan/ami-refactoring/include/asterisk/stasis_channels.h
    team/mjordan/ami-refactoring/main/channel.c
    team/mjordan/ami-refactoring/main/manager_channels.c
    team/mjordan/ami-refactoring/main/pbx.c
    team/mjordan/ami-refactoring/main/stasis_channels.c
    team/mjordan/ami-refactoring/res/res_fax.c
    team/mjordan/ami-refactoring/res/res_stasis.c
    team/mjordan/ami-refactoring/tests/test_stasis_channels.c
    team/mjordan/ami-refactoring/tests/test_stasis_endpoints.c

Propchange: team/mjordan/ami-refactoring/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Wed May  8 17:08:40 2013
@@ -1,1 +1,1 @@
-/trunk:1-387983
+/trunk:1-388030

Modified: team/mjordan/ami-refactoring/apps/app_directory.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/apps/app_directory.c?view=diff&rev=388076&r1=388075&r2=388076
==============================================================================
--- team/mjordan/ami-refactoring/apps/app_directory.c (original)
+++ team/mjordan/ami-refactoring/apps/app_directory.c Wed May  8 17:08:40 2013
@@ -440,7 +440,7 @@
 static struct ast_config *realtime_directory(char *context)
 {
 	struct ast_config *cfg;
-	struct ast_config *rtdata;
+	struct ast_config *rtdata = NULL;
 	struct ast_category *cat;
 	struct ast_variable *var;
 	char *mailbox;
@@ -475,7 +475,7 @@
 			rtdata = ast_load_realtime_multientry("voicemail", "mailbox LIKE", "%", "context", "default", SENTINEL);
 			context = "default";
 		}
-	} else {
+	} else if (!ast_strlen_zero(context)) {
 		rtdata = ast_load_realtime_multientry("voicemail", "mailbox LIKE", "%", "context", context, SENTINEL);
 	}
 

Modified: team/mjordan/ami-refactoring/apps/app_userevent.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/apps/app_userevent.c?view=diff&rev=388076&r1=388075&r2=388076
==============================================================================
--- team/mjordan/ami-refactoring/apps/app_userevent.c (original)
+++ team/mjordan/ami-refactoring/apps/app_userevent.c Wed May  8 17:08:40 2013
@@ -93,7 +93,6 @@
 	}
 
 	blob = ast_json_pack("{s: s, s: s, s: s}",
-			     "type", "userevent",
 			     "eventname", args.eventname,
 			     "body", ast_str_buffer(body));
 	if (!blob) {
@@ -101,7 +100,8 @@
 		return -1;
 	}
 
-	msg = ast_channel_blob_create(chan, blob);
+	msg = ast_channel_blob_create(
+		chan, ast_channel_user_event_type(), blob);
 	if (!msg) {
 		return -1;
 	}

Modified: team/mjordan/ami-refactoring/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/include/asterisk/stasis.h?view=diff&rev=388076&r1=388075&r2=388076
==============================================================================
--- team/mjordan/ami-refactoring/include/asterisk/stasis.h (original)
+++ team/mjordan/ami-refactoring/include/asterisk/stasis.h Wed May  8 17:08:40 2013
@@ -543,6 +543,43 @@
 /*! @{ */
 
 /*!
+ * \brief Boiler-plate removing macro for defining message types.
+ *
+ * \param name Name of message type.
+ * \since 12
+ */
+#define STASIS_MESSAGE_TYPE_DEFN(name)				\
+	static struct stasis_message_type *__ ## name;	\
+	struct stasis_message_type *name(void) {	\
+		ast_assert(__ ## name != NULL);		\
+		return __ ## name;			\
+	}
+
+/*!
+ * \brief Boiler-plate removing macro for initializing message types.
+ *
+ * \param name Name of message type.
+ * \return 0 if initialization is successful.
+ * \return Non-zero on failure.
+ * \since 12
+ */
+#define STASIS_MESSAGE_TYPE_INIT(name)				\
+	({						\
+	__ ## name = stasis_message_type_create(#name);	\
+	__ ## name ? 0 : -1;				\
+	})
+
+#define STASIS_MESSAGE_TYPE_CLEANUP(name)		\
+	({					\
+		ao2_cleanup(__ ## name);	\
+		__ ## name = NULL;		\
+	})
+
+/*! @} */
+
+/*! @{ */
+
+/*!
  * \brief Initialize the Stasis subsystem
  * \return 0 on success.
  * \return Non-zero on error.

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=388076&r1=388075&r2=388076
==============================================================================
--- team/mjordan/ami-refactoring/include/asterisk/stasis_channels.h (original)
+++ team/mjordan/ami-refactoring/include/asterisk/stasis_channels.h Wed May  8 17:08:40 2013
@@ -70,8 +70,7 @@
  * \since 12
  * \brief Blob of data associated with a channel.
  *
- * The \c blob is actually a JSON object of structured data. It has a "type" field
- * which contains the type string describing this blob.
+ * This blob is actually shared amongst several \ref stasis_message_type's.
  */
 struct ast_channel_blob {
 	/*! Channel blob is associated with (or NULL for global/all channels) */
@@ -112,14 +111,6 @@
 
 /*!
  * \since 12
- * \brief Message type for \ref ast_channel_blob messages.
- *
- * \retval Message type for \ref ast_channel_blob messages.
- */
-struct stasis_message_type *ast_channel_blob_type(void);
-
-/*!
- * \since 12
  * \brief Message type for \ref ast_multi_channel_blob messages.
  *
  * \retval Message type for \ref ast_multi_channel_blob messages.
@@ -136,7 +127,8 @@
  * \retval pointer on success (must be ast_freed)
  * \retval NULL on error
  */
-struct ast_channel_snapshot *ast_channel_snapshot_create(struct ast_channel *chan);
+struct ast_channel_snapshot *ast_channel_snapshot_create(
+	struct ast_channel *chan);
 
 /*!
  * \since 12
@@ -154,26 +146,32 @@
  * \since 12
  * \brief Creates a \ref ast_channel_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 chan Channel blob is associated with, or NULL for global/all channels.
- * \param blob JSON object representing the data.
+ * The given \a blob should be treated as immutable and not modified after it is
+ * put into the message.
+ *
+ * \param chan Channel blob is associated with, or \c NULL for global/all channels.
+ * \param type Message type for this blob.
+ * \param blob JSON object representing the data, or \c NULL for no data. If
+ *             \c NULL, ast_json_null() is put into the object.
+ *
  * \return \ref ast_channel_blob message.
  * \return \c NULL on error
  */
 struct stasis_message *ast_channel_blob_create(struct ast_channel *chan,
-					       struct ast_json *blob);
+	struct stasis_message_type *type, struct ast_json *blob);
 
 /*!
  * \since 12
  * \brief Creates a \ref ast_channel_blob message using the current cached
  * \ref ast_channel_snapshot for the passed in \ref ast_channel
  *
- * 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.
+ * The given \a blob should be treated as immutable and not modified after it is
+ * put into the message.
+ *
+ * \param chan Channel blob is associated with, or \c NULL for global/all channels.
+ * \param type Message type for this blob.
+ * \param blob JSON object representing the data, or \c NULL for no data. If
+ *             \c NULL, ast_json_null() is put into the object.
  *
  * \param chan Channel blob is associated with
  * \param blob JSON object representing the data.
@@ -181,28 +179,16 @@
  * \return \c NULL on error
  */
 struct stasis_message *ast_channel_cached_blob_create(struct ast_channel *chan,
-					       struct ast_json *blob);
-
-/*!
- * \since 12
- * \brief Extracts the type field from a \ref ast_channel_blob.
- * Returned \c char* is still owned by \a obj
- * \param obj Channel blob object.
- * \return Type field value from the blob.
- * \return \c NULL on error.
- */
-const char *ast_channel_blob_json_type(struct ast_channel_blob *obj);
-
-/*!
- * \since 12
- * \brief Create a \ref ast_multi_channel_blob suitable for a \ref stasis_message
- *
- * \note Similar to a \ref ast_channel_blob, the \ref ast_multi_channel_blob requires
- * a \a blob JSON object containing 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 blob The JSON blob that defines the type of this \ref ast_multi_channel_blob
+	struct stasis_message_type *type, struct ast_json *blob);
+
+/*!
+ * \since 12
+ * \brief Create a \ref ast_multi_channel_blob suitable for a \ref stasis_message.
+ *
+ * The given \a blob should be treated as immutable and not modified after it is
+ * put into the message.
+ *
+ * \param blob The JSON blob that defines the data of this \ref ast_multi_channel_blob
  *
  * \return \ref ast_multi_channel_blob object
  * \return \c NULL on error
@@ -226,8 +212,7 @@
  * \retval NULL on error or not found for the role specified
  */
 struct ast_channel_snapshot *ast_multi_channel_blob_get_channel(
-					       struct ast_multi_channel_blob *obj,
-					       const char *role);
+	struct ast_multi_channel_blob *obj, const char *role);
 
 /*!
  * \since 12
@@ -249,8 +234,7 @@
  * \retval NULL on error or not found for the role specified
  */
 struct ao2_container *ast_multi_channel_blob_get_channels(
-					       struct ast_multi_channel_blob *obj,
-					       const char *role);
+	struct ast_multi_channel_blob *obj, const char *role);
 
 /*!
  * \since 12
@@ -262,17 +246,6 @@
  * \return \c NULL on error.
  */
 struct ast_json *ast_multi_channel_blob_get_json(struct ast_multi_channel_blob *obj);
-
-/*!
- * \since 12
- * \brief Extracts the type field from a \ref ast_multi_channel_blob.
- * Returned \c char* is still owned by \a obj
- *
- * \param obj Channel blob object.
- * \return Type field value from the blob.
- * \return \c NULL on error.
- */
-const char *ast_multi_channel_blob_get_type(struct ast_multi_channel_blob *obj);
 
 /*!
  * \since 12
@@ -287,8 +260,7 @@
  * \ref ast_multi_channel_blob object
  */
 void ast_multi_channel_blob_add_channel(struct ast_multi_channel_blob *obj,
-					       const char *role,
-					       struct ast_channel_snapshot *snapshot);
+	const char *role, struct ast_channel_snapshot *snapshot);
 
 /*!
  * \since 12
@@ -308,6 +280,78 @@
  * \retval A stasis message type
  */
 struct stasis_message_type *ast_channel_dial_type(void);
+
+/*!
+ * \since 12
+ * \brief Message type for when a variable is set on a channel.
+ *
+ * \retval A stasis message type
+ */
+struct stasis_message_type *ast_channel_varset_type(void);
+
+/*!
+ * \since 12
+ * \brief Message type for when a custom user event is sent on a channel.
+ *
+ * \retval A stasis message type
+ */
+struct stasis_message_type *ast_channel_user_event_type(void);
+
+/*!
+ * \since 12
+ * \brief Message type for when a hangup is requested on a channel.
+ *
+ * \retval A stasis message type
+ */
+struct stasis_message_type *ast_channel_hangup_request_type(void);
+
+/*!
+ * \since 12
+ * \brief Message type for when DTMF begins on a channel.
+ *
+ * \retval A stasis message type
+ */
+struct stasis_message_type *ast_channel_dtmf_begin_type(void);
+
+/*!
+ * \since 12
+ * \brief Message type for when DTMF ends on a channel.
+ *
+ * \retval A stasis message type
+ */
+struct stasis_message_type *ast_channel_dtmf_end_type(void);
+
+/*!
+ * \since 12
+ * \brief Message type for when a channel starts spying on another channel
+ *
+ * \retval A stasis message type
+ */
+struct stasis_message_type *ast_channel_chanspy_start_type(void);
+
+/*!
+ * \since 12
+ * \brief Message type for when a channel stops spying on another channel
+ *
+ * \retval A stasis message type
+ */
+struct stasis_message_type *ast_channel_chanspy_stop_type(void);
+
+/*!
+ * \since 12
+ * \brief Message type for a fax operation
+ *
+ * \retval A stasis message type
+ */
+struct stasis_message_type *ast_channel_fax_type(void);
+
+/*!
+ * \since 12
+ * \brief Message type for hangup handler related actions
+ *
+ * \retval A stasis message type
+ */
+struct stasis_message_type *ast_channel_hangup_handler_type(void);
 
 /*!
  * \since 12

Modified: team/mjordan/ami-refactoring/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/main/channel.c?view=diff&rev=388076&r1=388075&r2=388076
==============================================================================
--- team/mjordan/ami-refactoring/main/channel.c (original)
+++ team/mjordan/ami-refactoring/main/channel.c Wed May  8 17:08:40 2013
@@ -1368,11 +1368,12 @@
 }
 
 /*! \internal \brief Publish a channel blob message */
-static void publish_channel_blob(struct ast_channel *chan, struct ast_json *blob)
+static void publish_channel_blob(struct ast_channel *chan,
+	struct stasis_message_type *type, struct ast_json *blob)
 {
 	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
 	if (blob) {
-		message = ast_channel_blob_create(chan, blob);
+		message = ast_channel_blob_create(chan, type, blob);
 	}
 	if (message) {
 		stasis_publish(ast_channel_topic(chan), message);
@@ -1382,7 +1383,6 @@
 /*! \brief Queue a hangup frame for channel */
 int ast_queue_hangup(struct ast_channel *chan)
 {
-	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
 	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
 	struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
 	int res;
@@ -1390,8 +1390,7 @@
 	/* Yeah, let's not change a lock-critical value without locking */
 	ast_channel_lock(chan);
 	ast_channel_softhangup_internal_flag_add(chan, AST_SOFTHANGUP_DEV);
-	blob = ast_json_pack("{s: s}", "type", "hangup_request");
-	publish_channel_blob(chan, blob);
+	publish_channel_blob(chan, ast_channel_hangup_request_type(), NULL);
 
 	res = ast_queue_frame(chan, &f);
 	ast_channel_unlock(chan);
@@ -1416,10 +1415,9 @@
 	if (cause < 0) {
 		f.data.uint32 = ast_channel_hangupcause(chan);
 	}
-	blob = ast_json_pack("{s: s, s: i}",
-			     "type", "hangup_request",
+	blob = ast_json_pack("{s: i}",
 			     "cause", cause);
-	publish_channel_blob(chan, blob);
+	publish_channel_blob(chan, ast_channel_hangup_request_type(), blob);
 
 	res = ast_queue_frame(chan, &f);
 	ast_channel_unlock(chan);
@@ -2727,11 +2725,10 @@
 
 	ast_channel_lock(chan);
 	res = ast_softhangup_nolock(chan, cause);
-	blob = ast_json_pack("{s: s, s: i, s: b}",
-			     "type", "hangup_request",
+	blob = ast_json_pack("{s: i, s: b}",
 			     "cause", cause,
 			     "soft", 1);
-	publish_channel_blob(chan, blob);
+	publish_channel_blob(chan, ast_channel_hangup_request_type(), blob);
 	ast_channel_unlock(chan);
 
 	return res;
@@ -3737,15 +3734,14 @@
 	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
 	char digit_str[] = { digit, '\0' };
 
-	blob = ast_json_pack("{ s: s, s: s, s: s }",
-		"type", "dtmf_begin",
+	blob = ast_json_pack("{ s: s, s: s }",
 		"digit", digit_str,
 		"direction", dtmf_direction_to_string(direction));
 	if (!blob) {
 		return;
 	}
 
-	publish_channel_blob(chan, blob);
+	publish_channel_blob(chan, ast_channel_dtmf_begin_type(), blob);
 }
 
 static void send_dtmf_end_event(struct ast_channel *chan,
@@ -3754,8 +3750,7 @@
 	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
 	char digit_str[] = { digit, '\0' };
 
-	blob = ast_json_pack("{ s: s, s: s, s: s, s: i }",
-		"type", "dtmf_end",
+	blob = ast_json_pack("{ s: s, s: s, s: i }",
 		"digit", digit_str,
 		"direction", dtmf_direction_to_string(direction),
 		"duration_ms", duration_ms);
@@ -3763,7 +3758,7 @@
 		return;
 	}
 
-	publish_channel_blob(chan, blob);
+	publish_channel_blob(chan, ast_channel_dtmf_end_type(), blob);
 }
 
 static void ast_read_generator_actions(struct ast_channel *chan, struct ast_frame *f)

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=388076&r1=388075&r2=388076
==============================================================================
--- team/mjordan/ami-refactoring/main/manager_channels.c (original)
+++ team/mjordan/ami-refactoring/main/manager_channels.c Wed May  8 17:08:40 2013
@@ -399,16 +399,16 @@
 				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
 				<parameter name="LocalStationID">
 					<para>The value of the <variable>LOCALSTATIONID</variable> channel variable</para>
-				<parameter>
+				</parameter>
 				<parameter name="RemoteStationID">
 					<para>The value of the <variable>REMOTESTATIONID</variable> channel variable</para>
-				<parameter>
+				</parameter>
 				<parameter name="PagesTransferred">
 					<para>The number of pages that have been transferred</para>
 				</parameter>
 				<parameter name="Resolution">
 					<para>The negotiated resolution</para>
-				<parameter>
+				</parameter>
 				<parameter name="TransferRate">
 					<para>The negotiated transfer rate</para>
 				</parameter>
@@ -742,8 +742,10 @@
 	}
 }
 
-static void channel_varset(struct ast_channel_blob *obj)
-{
+static void channel_varset_cb(void *data, struct stasis_subscription *sub,
+	struct stasis_topic *topic, struct stasis_message *message)
+{
+	struct ast_channel_blob *obj = stasis_message_data(message);
 	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
 	const char *variable = ast_json_string_get(ast_json_object_get(obj->blob, "variable"));
 	const char *value = ast_json_string_get(ast_json_object_get(obj->blob, "value"));
@@ -783,8 +785,10 @@
 		      variable, value);
 }
 
-static void channel_userevent(struct ast_channel_blob *obj)
-{
+static void channel_user_event_cb(void *data, struct stasis_subscription *sub,
+	struct stasis_topic *topic, struct stasis_message *message)
+{
+	struct ast_channel_blob *obj = stasis_message_data(message);
 	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
 	const char *eventname;
 	const char *body;
@@ -818,8 +822,11 @@
 		      ast_str_buffer(channel_event_string), eventname, body);
 }
 
-static void channel_hangup_request(struct ast_channel_blob *obj)
-{
+static void channel_hangup_request_cb(void *data,
+	struct stasis_subscription *sub, struct stasis_topic *topic,
+	struct stasis_message *message)
+{
+	struct ast_channel_blob *obj = stasis_message_data(message);
 	RAII_VAR(struct ast_str *, extra, NULL, ast_free);
 	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
 	struct ast_json *cause;
@@ -855,10 +862,12 @@
 		      ast_str_buffer(extra));
 }
 
-static void channel_chanspy_stop_event(struct ast_multi_channel_blob *payload)
+static void channel_chanspy_stop_cb(void *data, struct stasis_subscription *sub,
+		struct stasis_topic *topic, struct stasis_message *message)
 {
 	RAII_VAR(struct ast_str *, spyer_channel_string, NULL, ast_free);
 	RAII_VAR(struct ast_channel_snapshot *, spyer, NULL, ao2_cleanup);
+	struct ast_multi_channel_blob *payload = stasis_message_data(message);
 
 	spyer = ast_multi_channel_blob_get_channel(payload, "spyer_channel");
 	if (!spyer) {
@@ -876,12 +885,14 @@
 		      ast_str_buffer(spyer_channel_string));
 }
 
-static void channel_chanspy_start_event(struct ast_multi_channel_blob *payload)
+static void channel_chanspy_start_cb(void *data, struct stasis_subscription *sub,
+		struct stasis_topic *topic, struct stasis_message *message)
 {
 	RAII_VAR(struct ast_str *, spyer_channel_string, NULL, ast_free);
 	RAII_VAR(struct ast_str *, spyee_channel_string, NULL, ast_free);
 	RAII_VAR(struct ast_channel_snapshot *, spyer, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_channel_snapshot *, spyee, NULL, ao2_cleanup);
+	struct ast_multi_channel_blob *payload = stasis_message_data(message);
 
 	spyer = ast_multi_channel_blob_get_channel(payload, "spyer_channel");
 	if (!spyer) {
@@ -909,8 +920,10 @@
 		      ast_str_buffer(spyee_channel_string));
 }
 
-static void channel_dtmf_begin(struct ast_channel_blob *obj)
-{
+static void channel_dtmf_begin_cb(void *data, struct stasis_subscription *sub,
+	struct stasis_topic *topic, struct stasis_message *message)
+{
+	struct ast_channel_blob *obj = stasis_message_data(message);
 	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
 	const char *digit =
 		ast_json_string_get(ast_json_object_get(obj->blob, "digit"));
@@ -948,8 +961,10 @@
 		digit, direction);
 }
 
-static void channel_dtmf_end(struct ast_channel_blob *obj)
-{
+static void channel_dtmf_end_cb(void *data, struct stasis_subscription *sub,
+	struct stasis_topic *topic, struct stasis_message *message)
+{
+	struct ast_channel_blob *obj = stasis_message_data(message);
 	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
 	const char *digit =
 		ast_json_string_get(ast_json_object_get(obj->blob, "digit"));
@@ -993,24 +1008,26 @@
 		digit, duration_ms, direction);
 }
 
-static void channel_hangup_handler(struct ast_channel_blob *obj)
+static void channel_hangup_handler_cb(void *data, struct stasis_subscription *sub,
+		struct stasis_topic *topic, struct stasis_message *message)
 {
 	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"));
+	struct ast_channel_blob *payload = stasis_message_data(message);
+	const char *action = ast_json_string_get(ast_json_object_get(payload->blob, "type"));
+	const char *handler = ast_json_string_get(ast_json_object_get(payload->blob, "handler"));
 	const char *event;
 
-	channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
+	channel_event_string = ast_manager_build_channel_state_string(payload->snapshot);
 
 	if (!channel_event_string) {
 		return;
 	}
 
-	if (!strcmp(action, "run")) {
+	if (!strcmp(action, "type")) {
 		event = "HangupHandlerRun";
-	} else if (!strcmp(action, "pop")) {
+	} else if (!strcmp(action, "type")) {
 		event = "HangupHandlerPop";
-	} else if (!strcmp(action, "push")) {
+	} else if (!strcmp(action, "type")) {
 		event = "HangupHandlerPush";
 	} else {
 		return;
@@ -1022,19 +1039,21 @@
 		handler);
 }
 
-static void channel_fax_handler(struct ast_channel_blob *obj)
+static void channel_fax_cb(void *data, struct stasis_subscription *sub,
+		struct stasis_topic *topic, struct stasis_message *message)
 {
 	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
 	RAII_VAR(struct ast_str *, event_buffer, ast_str_create(256), ast_free);
-	const char *subtype = ast_json_string_get(ast_json_object_get(obj->blob, "subtype"));
-	struct ast_json *operation = ast_json_object_get(obj->blob, "operation");
-	struct ast_json *status = ast_json_object_get(obj->blob, "status");
-	struct ast_json *local_station_id = ast_json_object_get(obj->blob, "local_station_id");
-	struct ast_json *remote_station_id = ast_json_object_get(obj->blob, "remote_station_id");
-	struct ast_json *fax_pages = ast_json_object_get(obj->blob, "fax_pages");
-	struct ast_json *fax_resolution = ast_json_object_get(obj->blob, "fax_resolution");
-	struct ast_json *fax_bitrate = ast_json_object_get(obj->blob, "fax_bitrate");
-	struct ast_json *filenames = ast_json_object_get(obj->blob, "filenames");
+	struct ast_channel_blob *payload = stasis_message_data(message);
+	const char *type = ast_json_string_get(ast_json_object_get(payload->blob, "type"));
+	struct ast_json *operation = ast_json_object_get(payload->blob, "operation");
+	struct ast_json *status = ast_json_object_get(payload->blob, "status");
+	struct ast_json *local_station_id = ast_json_object_get(payload->blob, "local_station_id");
+	struct ast_json *remote_station_id = ast_json_object_get(payload->blob, "remote_station_id");
+	struct ast_json *fax_pages = ast_json_object_get(payload->blob, "fax_pages");
+	struct ast_json *fax_resolution = ast_json_object_get(payload->blob, "fax_resolution");
+	struct ast_json *fax_bitrate = ast_json_object_get(payload->blob, "fax_bitrate");
+	struct ast_json *filenames = ast_json_object_get(payload->blob, "filenames");
 	const char *event;
 	size_t array_len;
 	size_t i;
@@ -1043,16 +1062,16 @@
 		return;
 	}
 
-	channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
+	channel_event_string = ast_manager_build_channel_state_string(payload->snapshot);
 	if (!channel_event_string) {
 		return;
 	}
 
-	if (!strcmp(subtype, "status")) {
+	if (!strcmp(type, "status")) {
 		event = "FAXStatus";
-	} else if (!strcmp(subtype, "receive")) {
+	} else if (!strcmp(type, "receive")) {
 		event = "ReceiveFAX";
-	} else if (!strcmp(subtype, "send")) {
+	} else if (!strcmp(type, "send")) {
 		event = "SendFAX";
 	} else {
 		return;
@@ -1093,55 +1112,12 @@
 		ast_str_buffer(event_buffer));
 }
 
-/*!
- * \brief Callback processing messages on the channel topic.
- */
-static void channel_blob_cb(void *data, struct stasis_subscription *sub,
-			    struct stasis_topic *topic,
-			    struct stasis_message *message)
-{
-	struct ast_channel_blob *obj = stasis_message_data(message);
-
-	if (strcmp("varset", ast_channel_blob_json_type(obj)) == 0) {
-		channel_varset(obj);
-	} else if (strcmp("userevent", ast_channel_blob_json_type(obj)) == 0) {
-		channel_userevent(obj);
-	} else if (strcmp("hangup_request", ast_channel_blob_json_type(obj)) == 0) {
-		channel_hangup_request(obj);
-	} else if (strcmp("dtmf_begin", ast_channel_blob_json_type(obj)) == 0) {
-		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);
-	} else if (strcmp("fax", ast_channel_blob_json_type(obj)) == 0) {
-		channel_fax_handler(obj);
-	}
-}
-
-/*!
- * \brief Callback processing messages involving multiple channels
- */
-static void multi_channel_blob_cb(void *data, struct stasis_subscription *sub,
-			    struct stasis_topic *topic,
-			    struct stasis_message *message)
-{
-	struct ast_multi_channel_blob *payload = stasis_message_data(message);
-	const char *type = ast_multi_channel_blob_get_type(payload);
-
-	if (!strcmp("chanspy_start", type)) {
-		channel_chanspy_start_event(payload);
-	} else if (!strcmp("chanspy_stop", type)) {
-		channel_chanspy_stop_event(payload);
-	}
-}
 
 /*!
  * \brief Callback processing messages for channel dialing
  */
 static void channel_dial_cb(void *data, struct stasis_subscription *sub,
-				struct stasis_topic *topic,
-				struct stasis_message *message)
+	struct stasis_topic *topic, struct stasis_message *message)
 {
 	struct ast_multi_channel_blob *obj = stasis_message_data(message);
 	const char *dialstatus;
@@ -1150,11 +1126,6 @@
 	struct ast_channel_snapshot *peer;
 	RAII_VAR(struct ast_str *, caller_event_string, NULL, ast_free);
 	RAII_VAR(struct ast_str *, peer_event_string, NULL, ast_free);
-
-	if (strcmp("dial", ast_multi_channel_blob_get_type(obj))) {
-		ast_assert(0);
-		return;
-	}
 
 	caller = ast_multi_channel_blob_get_channel(obj, "caller");
 	peer = ast_multi_channel_blob_get_channel(obj, "peer");
@@ -1223,18 +1194,78 @@
 					 NULL);
 
 	ret |= stasis_message_router_add(message_router,
-					 ast_channel_blob_type(),
-					 channel_blob_cb,
-					 NULL);
-
-	ret |= stasis_message_router_add(message_router,
-					 ast_multi_channel_blob_type(),
-					 multi_channel_blob_cb,
+					 ast_channel_varset_type(),
+					 channel_varset_cb,
+					 NULL);
+
+	ret |= stasis_message_router_add(message_router,
+					 ast_channel_user_event_type(),
+					 channel_user_event_cb,
+					 NULL);
+
+	ret |= stasis_message_router_add(message_router,
+					 ast_channel_dtmf_begin_type(),
+					 channel_dtmf_begin_cb,
+					 NULL);
+
+	ret |= stasis_message_router_add(message_router,
+					 ast_channel_dtmf_end_type(),
+					 channel_dtmf_end_cb,
+					 NULL);
+
+	ret |= stasis_message_router_add(message_router,
+					 ast_channel_varset_type(),
+					 channel_varset_cb,
+					 NULL);
+
+	ret |= stasis_message_router_add(message_router,
+					 ast_channel_user_event_type(),
+					 channel_user_event_cb,
+					 NULL);
+
+	ret |= stasis_message_router_add(message_router,
+					 ast_channel_dtmf_begin_type(),
+					 channel_dtmf_begin_cb,
+					 NULL);
+
+	ret |= stasis_message_router_add(message_router,
+					 ast_channel_dtmf_end_type(),
+					 channel_dtmf_end_cb,
+					 NULL);
+
+	ret |= stasis_message_router_add(message_router,
+					 ast_channel_hangup_request_type(),
+					 channel_hangup_request_cb,
+					 NULL);
+
+	ret |= stasis_message_router_add(message_router,
+					 ast_channel_hangup_request_type(),
+					 channel_hangup_request_cb,
 					 NULL);
 
 	ret |= stasis_message_router_add(message_router,
 					 ast_channel_dial_type(),
 					 channel_dial_cb,
+					 NULL);
+
+	ret |= stasis_message_router_add(message_router,
+					 ast_channel_fax_type(),
+					 channel_fax_cb,
+					 NULL);
+
+	ret |= stasis_message_router_add(message_router,
+					 ast_channel_chanspy_start_type(),
+					 channel_chanspy_start_cb,
+					 NULL);
+
+	ret |= stasis_message_router_add(message_router,
+					 ast_channel_chanspy_stop_type(),
+					 channel_chanspy_stop_cb,
+					 NULL);
+
+	ret |= stasis_message_router_add(message_router,
+					 ast_channel_hangup_handler_type(),
+					 channel_hangup_handler_cb,
 					 NULL);
 
 	/* If somehow we failed to add any routes, just shut down the whole

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=388076&r1=388075&r2=388076
==============================================================================
--- team/mjordan/ami-refactoring/main/pbx.c (original)
+++ team/mjordan/ami-refactoring/main/pbx.c Wed May  8 17:08:40 2013
@@ -5778,14 +5778,13 @@
 	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
 
 	blob = ast_json_pack("{s: s, s: s}",
-			"type", "hangup_handler",
-			"action", action,
+			"type", action,
 			"handler", S_OR(handler, ""));
 	if (!blob) {
 		return;
 	}
 
-	message = ast_channel_blob_create(chan, blob);
+	message = ast_channel_blob_create(chan, ast_channel_hangup_handler_type(), blob);
 	if (!message) {
 		return;
 	}

Modified: team/mjordan/ami-refactoring/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/main/stasis_channels.c?view=diff&rev=388076&r1=388075&r2=388076
==============================================================================
--- team/mjordan/ami-refactoring/main/stasis_channels.c (original)
+++ team/mjordan/ami-refactoring/main/stasis_channels.c Wed May  8 17:08:40 2013
@@ -38,43 +38,27 @@
 
 #define NUM_MULTI_CHANNEL_BLOB_BUCKETS 7
 
-/*! \brief Message type for channel snapshot messages */
-static struct stasis_message_type *channel_snapshot_type;
-
-/*! \brief Message type for channel blob messages */
-static struct stasis_message_type *channel_blob_type;
-
-/*! \brief Message type for channel dial messages */
-static struct stasis_message_type *channel_dial_type;
-
-/*! \brief Message type for multi channel blob messages */
-static struct stasis_message_type *multi_channel_blob_type;
+/*!
+ * @{ \brief Define channel message types.
+ */
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_snapshot_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_dial_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_varset_type);
+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_chanspy_start_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_stop_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_fax_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_hangup_handler_type);
+/*! @} */
 
 /*! \brief Topic for all channels */
 struct stasis_topic *channel_topic_all;
 
 /*! \brief Caching topic for all channels */
 struct stasis_caching_topic *channel_topic_all_cached;
-
-struct stasis_message_type *ast_channel_dial_type(void)
-{
-	return channel_dial_type;
-}
-
-struct stasis_message_type *ast_channel_blob_type(void)
-{
-	return channel_blob_type;
-}
-
-struct stasis_message_type *ast_multi_channel_blob_type(void)
-{
-	return multi_channel_blob_type;
-}
-
-struct stasis_message_type *ast_channel_snapshot_type(void)
-{
-	return channel_snapshot_type;
-}
 
 struct stasis_topic *ast_channel_topic_all(void)
 {
@@ -229,18 +213,15 @@
 }
 
 static struct stasis_message *create_channel_blob_message(struct ast_channel_snapshot *snapshot,
+		struct stasis_message_type *type,
 		struct ast_json *blob)
+
 {
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_channel_blob *, obj, NULL, ao2_cleanup);
-	struct ast_json *type;
-
-	ast_assert(blob != NULL);
-
-	type = ast_json_object_get(blob, "type");
-	if (type == NULL) {
-		ast_log(LOG_ERROR, "Invalid ast_channel_blob; missing type field\n");
-		return NULL;
+
+	if (blob == NULL) {
+		blob = ast_json_null();
 	}
 
 	obj = ao2_alloc(sizeof(*obj), channel_blob_dtor);
@@ -254,7 +235,7 @@
 	}
 	obj->blob = ast_json_ref(blob);
 
-	msg = stasis_message_create(ast_channel_blob_type(), obj);
+	msg = stasis_message_create(type, obj);
 	if (!msg) {
 		return NULL;
 	}
@@ -264,17 +245,18 @@
 }
 
 struct stasis_message *ast_channel_cached_blob_create(struct ast_channel *chan,
+					       struct stasis_message_type *type,
 					       struct ast_json *blob)
 {
 	RAII_VAR(struct ast_channel_snapshot *, snapshot,
 			ast_channel_get_cached_snapshot(ast_channel_uniqueid(chan)),
 			ao2_cleanup);
 
-	return create_channel_blob_message(snapshot, blob);
+	return create_channel_blob_message(snapshot, type, blob);
 }
 
 struct stasis_message *ast_channel_blob_create(struct ast_channel *chan,
-					       struct ast_json *blob)
+	struct stasis_message_type *type, struct ast_json *blob)
 {
 	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
 
@@ -282,16 +264,7 @@
 		snapshot = ast_channel_snapshot_create(chan);
 	}
 
-	return create_channel_blob_message(snapshot, blob);
-}
-
-const char *ast_channel_blob_json_type(struct ast_channel_blob *obj)
-{
-	if (obj == NULL) {
-		return NULL;
-	}
-
-	return ast_json_string_get(ast_json_object_get(obj->blob, "type"));
+	return create_channel_blob_message(snapshot, type, blob);
 }
 
 /*! \brief A channel snapshot wrapper object used in \ref ast_multi_channel_blob objects */
@@ -346,17 +319,10 @@
 	RAII_VAR(struct ast_multi_channel_blob *, obj,
 			ao2_alloc(sizeof(*obj), multi_channel_blob_dtor),
 			ao2_cleanup);
-	struct ast_json *type;
 
 	ast_assert(blob != NULL);
 
 	if (!obj) {
-		return NULL;
-	}
-
-	type = ast_json_object_get(blob, "type");
-	if (type == NULL) {
-		ast_log(LOG_ERROR, "Invalid ast_multi_channel_blob; missing type field\n");
 		return NULL;
 	}
 
@@ -469,15 +435,6 @@
 	return obj->blob;
 }
 
-const char *ast_multi_channel_blob_get_type(struct ast_multi_channel_blob *obj)
-{
-	if (!obj) {
-		return NULL;
-	}
-
-	return ast_json_string_get(ast_json_object_get(obj->blob, "type"));
-}
-
 void ast_channel_publish_varset(struct ast_channel *chan, const char *name, const char *value)
 {
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
@@ -495,7 +452,8 @@
 		return;
 	}
 
-	msg = ast_channel_blob_create(chan, ast_json_ref(blob));
+	msg = ast_channel_blob_create(chan, ast_channel_varset_type(),
+		ast_json_ref(blob));
 
 	if (!msg) {
 		return;
@@ -537,14 +495,17 @@
 
 void ast_stasis_channels_shutdown(void)
 {
-	ao2_cleanup(channel_snapshot_type);
-	channel_snapshot_type = NULL;
-	ao2_cleanup(channel_blob_type);
-	channel_blob_type = NULL;
-	ao2_cleanup(multi_channel_blob_type);
-	multi_channel_blob_type = NULL;
-	ao2_cleanup(channel_dial_type);
-	channel_dial_type = NULL;
+	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_snapshot_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dial_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_varset_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_user_event_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_hangup_request_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_begin_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_end_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_chanspy_start_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_chanspy_stop_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_fax_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_hangup_handler_type);
 	ao2_cleanup(channel_topic_all);
 	channel_topic_all = NULL;
 	channel_topic_all_cached = stasis_caching_unsubscribe(channel_topic_all_cached);
@@ -552,10 +513,17 @@
 
 void ast_stasis_channels_init(void)
 {
-	channel_snapshot_type = stasis_message_type_create("ast_channel_snapshot");
-	channel_blob_type = stasis_message_type_create("ast_channel_blob");
-	multi_channel_blob_type = stasis_message_type_create("ast_multi_channel_blob");
-	channel_dial_type = stasis_message_type_create("ast_channel_dial");
+	STASIS_MESSAGE_TYPE_INIT(ast_channel_snapshot_type);
+	STASIS_MESSAGE_TYPE_INIT(ast_channel_dial_type);
+	STASIS_MESSAGE_TYPE_INIT(ast_channel_varset_type);
+	STASIS_MESSAGE_TYPE_INIT(ast_channel_user_event_type);
+	STASIS_MESSAGE_TYPE_INIT(ast_channel_hangup_request_type);
+	STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_begin_type);
+	STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_end_type);
+	STASIS_MESSAGE_TYPE_INIT(ast_channel_chanspy_start_type);
+	STASIS_MESSAGE_TYPE_INIT(ast_channel_chanspy_stop_type);
+	STASIS_MESSAGE_TYPE_INIT(ast_channel_fax_type);
+	STASIS_MESSAGE_TYPE_INIT(ast_channel_hangup_handler_type);
 	channel_topic_all = stasis_topic_create("ast_channel_topic_all");
 	channel_topic_all_cached = stasis_caching_topic_create(channel_topic_all, channel_snapshot_get_id);
 }

Modified: team/mjordan/ami-refactoring/res/res_fax.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/ami-refactoring/res/res_fax.c?view=diff&rev=388076&r1=388075&r2=388076
==============================================================================
--- team/mjordan/ami-refactoring/res/res_fax.c (original)
+++ team/mjordan/ami-refactoring/res/res_fax.c Wed May  8 17:08:40 2013
@@ -1198,7 +1198,7 @@
 	{
 		SCOPED_CHANNELLOCK(lock, chan);
 
-		message = ast_channel_cached_blob_create(chan, json_object);
+		message = ast_channel_cached_blob_create(chan, ast_channel_fax_type(), json_object);
 		if (!message) {
 			return -1;
 		}
@@ -1779,8 +1779,7 @@
 		SCOPED_CHANNELLOCK(lock, chan);
 
 		json_object = ast_json_pack("s: s, s: s, s: s, s: s, s: s, s: s, s: s, s: o",
-				"type", "fax"
-				"subtype", "receive",
+				"type", "receive"
 				"remote_station_id", S_OR(pbx_builtin_getvar_helper(chan, "REMOTESTATIONID"), ""),
 				"local_station_id", S_OR(pbx_builtin_getvar_helper(chan, "LOCALSTATIONID"), ""),
 				"fax_pages", S_OR(pbx_builtin_getvar_helper(chan, "FAXPAGES"), ""),
@@ -1791,7 +1790,7 @@
 			return -1;
 		}
 
-		message = ast_channel_cached_blob_create(chan, json_object);
+		message = ast_channel_cached_blob_create(chan, ast_channel_fax_type(), json_object);
 		if (!message) {
 			return -1;
 		}
@@ -2260,8 +2259,7 @@
 	{
 		SCOPED_CHANNELLOCK(lock, chan);
 		json_obj = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s, s: s, s: o}",
-				"type", "fax"
-				"subtype", "send",
+				"type", "send"
 				"remote_station_id", S_OR(pbx_builtin_getvar_helper(chan, "REMOTESTATIONID"), ""),

[... 215 lines stripped ...]



More information about the asterisk-commits mailing list