[asterisk-commits] dlee: branch dlee/stasis-vtable r390171 - in /team/dlee/stasis-vtable: includ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 30 15:29:04 CDT 2013


Author: dlee
Date: Thu May 30 15:29:02 2013
New Revision: 390171

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390171
Log:
to_ami that actually might be useful

Modified:
    team/dlee/stasis-vtable/include/asterisk/manager.h
    team/dlee/stasis-vtable/include/asterisk/stasis.h
    team/dlee/stasis-vtable/main/manager.c
    team/dlee/stasis-vtable/main/stasis_message.c
    team/dlee/stasis-vtable/tests/test_stasis.c

Modified: team/dlee/stasis-vtable/include/asterisk/manager.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-vtable/include/asterisk/manager.h?view=diff&rev=390171&r1=390170&r2=390171
==============================================================================
--- team/dlee/stasis-vtable/include/asterisk/manager.h (original)
+++ team/dlee/stasis-vtable/include/asterisk/manager.h Thu May 30 15:29:02 2013
@@ -401,7 +401,9 @@
 
 /*!
  * \since 12
- * \brief Construct a \ref snapshot_manager_event.
+ * \brief Construct a \ref ast_manager_event_blob.
+ *
+ * The returned object is AO2 managed, so clean up with ao2_cleanup().
  *
  * \param event_flags Flags the event should be raised with.
  * \param manager_event The event to be raised, should be a string literal.

Modified: team/dlee/stasis-vtable/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-vtable/include/asterisk/stasis.h?view=diff&rev=390171&r1=390170&r2=390171
==============================================================================
--- team/dlee/stasis-vtable/include/asterisk/stasis.h (original)
+++ team/dlee/stasis-vtable/include/asterisk/stasis.h Thu May 30 15:29:02 2013
@@ -155,6 +155,7 @@
  */
 
 #include "asterisk/json.h"
+#include "asterisk/manager.h"
 #include "asterisk/utils.h"
 
 /*! @{ */
@@ -196,15 +197,16 @@
 	 * The returned string is newly allocated, so free using ast_free().
 	 *
 	 * \param message Message to convert to AMI string.
-	 * \return Newly allocated string with AMI message.
+	 * \return Newly allocated \ref ast_manager_event_blob.
 	 * \return \c NULL on error.
 	 * \return \c NULL if AMI format is not support.
 	 */
-	char *(*to_ami)(struct stasis_message *message);
+	struct ast_manager_event_blob *(*to_ami)(
+		struct stasis_message *message);
 };
 
 /*!
- * \brief Register a new message type.
+ * \brief Create a new message type.
  *
  * \ref stasis_message_type is an AO2 object, so ao2_cleanup() when you're done
  * with it.
@@ -292,7 +294,8 @@
  * \return \c NULL on error.
  * \return \c NULL if AMI format is not support.
  */
-char *stasis_message_to_ami(struct stasis_message *message);
+struct ast_manager_event_blob *stasis_message_to_ami(
+	struct stasis_message *message);
 
 /*! @} */
 
@@ -712,7 +715,6 @@
  * \param ... Virtual table methods for messages of this type.
  * \since 12
  */
-<<<<<<< .working
 #define STASIS_MESSAGE_TYPE_DEFN(name, ...)				\
 	static struct stasis_message_vtable _priv_ ## name ## _v = {	\
 		__VA_ARGS__						\

Modified: team/dlee/stasis-vtable/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-vtable/main/manager.c?view=diff&rev=390171&r1=390170&r2=390171
==============================================================================
--- team/dlee/stasis-vtable/main/manager.c (original)
+++ team/dlee/stasis-vtable/main/manager.c Thu May 30 15:29:02 2013
@@ -1293,6 +1293,24 @@
 
 	return output_str;
 }
+
+static void manager_default_msg_cb(void *data, struct stasis_subscription *sub,
+				    struct stasis_topic *topic,
+				    struct stasis_message *message)
+{
+	RAII_VAR(struct ast_manager_event_blob *, ev, NULL, ao2_cleanup);
+
+	ev = stasis_message_to_ami(message);
+
+	if (ev == NULL) {
+		/* Not and AMI message; disregard */
+		return;
+	}
+
+	manager_event(ev->event_flags, ev->manager_event, "%s",
+		ev->extra_fields);
+}
+
 
 static void manager_generic_msg_cb(void *data, struct stasis_subscription *sub,
 				    struct stasis_topic *topic,
@@ -7667,7 +7685,12 @@
  */
 static int manager_subscriptions_init(void)
 {
-	STASIS_MESSAGE_TYPE_INIT(ast_manager_get_generic_type);
+	int res;
+
+	res = STASIS_MESSAGE_TYPE_INIT(ast_manager_get_generic_type);
+	if (res != 0) {
+		return -1;
+	}
 	manager_topic = stasis_topic_create("manager_topic");
 	if (!manager_topic) {
 		return -1;
@@ -7677,10 +7700,13 @@
 		return -1;
 	}
 
-	if (stasis_message_router_add(stasis_router,
-					 ast_manager_get_generic_type(),
-					 manager_generic_msg_cb,
-					 NULL)) {
+	res |= stasis_message_router_set_default(stasis_router,
+		manager_default_msg_cb, NULL);
+
+	res |= stasis_message_router_add(stasis_router,
+		ast_manager_get_generic_type(), manager_generic_msg_cb, NULL);
+
+	if (res != 0) {
 		return -1;
 	}
 	return 0;

Modified: team/dlee/stasis-vtable/main/stasis_message.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-vtable/main/stasis_message.c?view=diff&rev=390171&r1=390170&r2=390171
==============================================================================
--- team/dlee/stasis-vtable/main/stasis_message.c (original)
+++ team/dlee/stasis-vtable/main/stasis_message.c Thu May 30 15:29:02 2013
@@ -156,7 +156,7 @@
 		msg->type->vtable->fn(__VA_ARGS__);	\
 	})
 
-char *stasis_message_to_ami(struct stasis_message *msg)
+struct ast_manager_event_blob *stasis_message_to_ami(struct stasis_message *msg)
 {
 	return INVOKE_VIRTUAL(to_ami, msg);
 }

Modified: team/dlee/stasis-vtable/tests/test_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-vtable/tests/test_stasis.c?view=diff&rev=390171&r1=390170&r2=390171
==============================================================================
--- team/dlee/stasis-vtable/tests/test_stasis.c (original)
+++ team/dlee/stasis-vtable/tests/test_stasis.c Thu May 30 15:29:02 2013
@@ -48,13 +48,19 @@
 	return ast_json_string_create(text);
 }
 
-static char *fake_ami(struct stasis_message *message)
-{
+static struct ast_manager_event_blob *fake_ami(struct stasis_message *message)
+{
+	RAII_VAR(struct ast_manager_event_blob *, res, NULL, ao2_cleanup);
 	const char *text = stasis_message_data(message);
-	char *res;
-
-	ast_asprintf(&res, "FakeMI: %s", text);
-
+
+	res = ast_manager_event_blob_create(EVENT_FLAG_TEST, "FakeMI",
+		"Message: %s", text);
+
+	if (res == NULL) {
+		return NULL;
+	}
+
+	ao2_ref(res, +1);
 	return res;
 }
 
@@ -1076,7 +1082,7 @@
 	RAII_VAR(struct stasis_message_type *, type, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, uut, NULL, ao2_cleanup);
 	RAII_VAR(char *, data, NULL, ao2_cleanup);
-	RAII_VAR(char *, actual, NULL, ast_free);
+	RAII_VAR(struct ast_manager_event_blob *, actual, NULL, ao2_cleanup);
 	char *expected = "SomeData";
 
 	switch (cmd) {
@@ -1113,9 +1119,9 @@
 	RAII_VAR(struct stasis_message_type *, type, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, uut, NULL, ao2_cleanup);
 	RAII_VAR(char *, data, NULL, ao2_cleanup);
-	RAII_VAR(char *, actual, NULL, ast_free);
+	RAII_VAR(struct ast_manager_event_blob *, actual, NULL, ao2_cleanup);
 	const char *expected_text = "SomeData";
-	const char *expected = "FakeMI: SomeData";
+	const char *expected = "Message: SomeData";
 
 	switch (cmd) {
 	case TEST_INIT:
@@ -1136,7 +1142,7 @@
 	ast_test_validate(test, NULL != uut);
 
 	actual = stasis_message_to_ami(uut);
-	ast_test_validate(test, strcmp(expected, actual) == 0);
+	ast_test_validate(test, strcmp(expected, actual->extra_fields) == 0);
 
 	return AST_TEST_PASS;
 }




More information about the asterisk-commits mailing list