[asterisk-commits] dlee: branch dlee/detyped r387968 - in /team/dlee/detyped: include/asterisk/ ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 8 11:15:39 CDT 2013


Author: dlee
Date: Wed May  8 11:15:38 2013
New Revision: 387968

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387968
Log:
Create and initialize new message types.

Created a set of macros to make it less boilerplate-ish.

Modified:
    team/dlee/detyped/include/asterisk/stasis.h
    team/dlee/detyped/main/stasis_channels.c

Modified: team/dlee/detyped/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/detyped/include/asterisk/stasis.h?view=diff&rev=387968&r1=387967&r2=387968
==============================================================================
--- team/dlee/detyped/include/asterisk/stasis.h (original)
+++ team/dlee/detyped/include/asterisk/stasis.h Wed May  8 11:15:38 2013
@@ -526,6 +526,38 @@
 
 /*! @{ */
 
+/*!
+ * \brief Boiler-plate removing macro for defining message types.
+ *
+ * \param name Name of message type.
+ * \since 12
+ */
+#define STASIS_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_TYPE_INIT(name)				\
+	({						\
+	__ ## name = stasis_message_type_create(#name);	\
+	__ ## name ? 0 : -1;				\
+	})
+
+#define STASIS_TYPE_CLEANUP(name)		\
+	({					\
+		ao2_cleanup(__ ## name);	\
+		__ ## name = NULL;		\
+	})
 
 /*! @} */
 

Modified: team/dlee/detyped/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/detyped/main/stasis_channels.c?view=diff&rev=387968&r1=387967&r2=387968
==============================================================================
--- team/dlee/detyped/main/stasis_channels.c (original)
+++ team/dlee/detyped/main/stasis_channels.c Wed May  8 11:15:38 2013
@@ -38,27 +38,23 @@
 
 #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 dial messages */
-static struct stasis_message_type *channel_dial_type;
+/*!
+ * @{ \brief Define channel message types.
+ */
+STASIS_TYPE_DEFN(ast_channel_snapshot_type);
+STASIS_TYPE_DEFN(ast_channel_dial_type);
+STASIS_TYPE_DEFN(ast_channel_varset_type);
+STASIS_TYPE_DEFN(ast_channel_user_event_type);
+STASIS_TYPE_DEFN(ast_channel_hangup_request_type);
+STASIS_TYPE_DEFN(ast_channel_dtmf_begin_type);
+STASIS_TYPE_DEFN(ast_channel_dtmf_end_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_snapshot_type(void)
-{
-	return channel_snapshot_type;
-}
 
 struct stasis_topic *ast_channel_topic_all(void)
 {
@@ -297,17 +293,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;
 	}
 
@@ -461,10 +450,13 @@
 
 void ast_stasis_channels_shutdown(void)
 {
-	ao2_cleanup(channel_snapshot_type);
-	channel_snapshot_type = NULL;
-	ao2_cleanup(channel_dial_type);
-	channel_dial_type = NULL;
+	STASIS_TYPE_CLEANUP(ast_channel_snapshot_type);
+	STASIS_TYPE_CLEANUP(ast_channel_dial_type);
+	STASIS_TYPE_CLEANUP(ast_channel_varset_type);
+	STASIS_TYPE_CLEANUP(ast_channel_user_event_type);
+	STASIS_TYPE_CLEANUP(ast_channel_hangup_request_type);
+	STASIS_TYPE_CLEANUP(ast_channel_dtmf_begin_type);
+	STASIS_TYPE_CLEANUP(ast_channel_dtmf_end_type);
 	ao2_cleanup(channel_topic_all);
 	channel_topic_all = NULL;
 	channel_topic_all_cached = stasis_caching_unsubscribe(channel_topic_all_cached);
@@ -472,8 +464,14 @@
 
 void ast_stasis_channels_init(void)
 {
-	channel_snapshot_type = stasis_message_type_create("ast_channel_snapshot");
-	channel_dial_type = stasis_message_type_create("ast_channel_dial");
+	STASIS_TYPE_INIT(ast_channel_snapshot_type);
+	STASIS_TYPE_INIT(ast_channel_dial_type);
+	STASIS_TYPE_INIT(ast_channel_varset_type);
+	STASIS_TYPE_INIT(ast_channel_user_event_type);
+	STASIS_TYPE_INIT(ast_channel_hangup_request_type);
+	STASIS_TYPE_INIT(ast_channel_dtmf_begin_type);
+	STASIS_TYPE_INIT(ast_channel_dtmf_end_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);
 }




More information about the asterisk-commits mailing list