[asterisk-commits] qwell: trunk r390268 - in /trunk: include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 31 09:36:16 CDT 2013


Author: qwell
Date: Fri May 31 09:36:08 2013
New Revision: 390268

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390268
Log:
Replace ast_manager_publish_message() with a more useful version.

It's much easier to just create a blob of the message.  Convert some AMI events
to use it.

Review: https://reviewboard.asterisk.org/r/2577/

Modified:
    trunk/include/asterisk/manager.h
    trunk/main/asterisk.c
    trunk/main/manager.c

Modified: trunk/include/asterisk/manager.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/manager.h?view=diff&rev=390268&r1=390267&r2=390268
==============================================================================
--- trunk/include/asterisk/manager.h (original)
+++ trunk/include/asterisk/manager.h Fri May 31 09:36:08 2013
@@ -475,17 +475,18 @@
 
 /*!
  * \since 12
- * \brief Publish a generic \ref stasis_message_type to the \ref stasis_topic for AMI
+ * \brief Publish an event to AMI
+ *
+ * \param type The type of AMI event to publish
+ * \param class_type The class on which to publish the event
+ * \param obj The event data to be published.
  *
  * Publishes a message to the \ref stasis message bus solely for the consumption of AMI.
  * The message will be of the type provided by \ref ast_manager_get_type, and will be
  * published to the topic provided by \ref ast_manager_get_topic. As such, the JSON must
  * be constructed as defined by the \ref ast_manager_get_type message.
- *
- * \retval 0 on success
- * \retval -1 on failure
- */
-int ast_manager_publish_message(struct ast_json *json);
+ */
+void ast_manager_publish_event(const char *type, int class_type, struct ast_json *obj);
 
 /*!
  * \since 12

Modified: trunk/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/asterisk.c?view=diff&rev=390268&r1=390267&r2=390268
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Fri May 31 09:36:08 2013
@@ -1126,49 +1126,13 @@
 	return 0;
 }
 
-/*!
- * \brief Publish a \ref system_status_type message over \ref stasis
- *
- * \param payload The JSON payload to send with the message
- */
-static void publish_system_message(const char *message_type, struct ast_json *obj)
-{
-	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_json *, event_info, NULL, ast_json_unref);
-
-	if (!obj) {
-		return;
-	}
-
-	ast_json_ref(obj);
-	event_info = ast_json_pack("{s: s, s: i, s: o}",
-			"type", message_type,
-			"class_type", EVENT_FLAG_SYSTEM,
-			"event", obj);
-	if (!event_info) {
-		return;
-	}
-
-	payload = ast_json_payload_create(event_info);
-	if (!payload) {
-		return;
-	}
-
-	message = stasis_message_create(ast_manager_get_generic_type(), payload);
-	if (!message) {
-		return;
-	}
-	stasis_publish(ast_manager_get_topic(), message);
-}
-
 static void publish_fully_booted(void)
 {
 	RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
 
 	json_object = ast_json_pack("{s: s}",
 			"Status", "Fully Booted");
-	publish_system_message("FullyBooted", json_object);
+	ast_manager_publish_event("FullyBooted", EVENT_FLAG_SYSTEM, json_object);
 }
 
 static void ast_run_atexits(int run_cleanups)
@@ -2028,7 +1992,7 @@
 		json_object = ast_json_pack("{s: s, s: s}",
 				"Shutdown", active_channels ? "Uncleanly" : "Cleanly",
 				"Restart", restart ? "True" : "False");
-		publish_system_message("Shutdown", json_object);
+		ast_manager_publish_event("Shutdown", EVENT_FLAG_SYSTEM, json_object);
 	}
 	ast_verb(0, "Asterisk %s ending (%d).\n",
 		active_channels ? "uncleanly" : "cleanly", num);

Modified: trunk/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/manager.c?view=diff&rev=390268&r1=390267&r2=390268
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Fri May 31 09:36:08 2013
@@ -1312,37 +1312,34 @@
 	manager_event(class_type, type, "%s", ast_str_buffer(event_buffer));
 }
 
-int ast_manager_publish_message(struct ast_json *obj)
-{
+void ast_manager_publish_event(const char *type, int class_type, struct ast_json *obj)
+{
+	RAII_VAR(struct ast_json *, event_info, NULL, ast_json_unref);
+	RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
-	struct ast_json *type = ast_json_object_get(obj, "type");
-	struct ast_json *class_type = ast_json_object_get(obj, "class_type");
-	struct ast_json *event = ast_json_object_get(obj, "event");
-
-	if (!type) {
-		ast_log(AST_LOG_ERROR, "Attempt to send generic manager event without type field\n");
-		return -1;
-	}
-	if (!class_type) {
-		ast_log(AST_LOG_ERROR, "Attempt to send generic manager event without class type field\n");
-		return -1;
-	}
-	if (!event) {
-		ast_log(AST_LOG_ERROR, "Attempt to send generic manager event without event payload\n");
-		return -1;
-	}
-
-	payload = ast_json_payload_create(obj);
+
+	if (!obj) {
+		return;
+	}
+
+	ast_json_ref(obj);
+	event_info = ast_json_pack("{s: s, s: i, s: o}",
+			"type", type,
+			"class_type", class_type,
+			"event", obj);
+	if (!event_info) {
+		return;
+	}
+
+	payload = ast_json_payload_create(event_info);
 	if (!payload) {
-		return -1;
+		return;
 	}
 	message = stasis_message_create(ast_manager_get_generic_type(), payload);
 	if (!message) {
-		return -1;
+		return;
 	}
 	stasis_publish(ast_manager_get_topic(), message);
-	return 0;
 }
 
 /*! \brief Add a custom hook to be called when an event is fired */




More information about the asterisk-commits mailing list