[asterisk-commits] qwell: branch qwell/system_registry r393464 - /team/qwell/system_registry/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 2 13:32:24 CDT 2013


Author: qwell
Date: Tue Jul  2 13:32:22 2013
New Revision: 393464

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=393464
Log:
Convert Registry event to to_ami.

Modified:
    team/qwell/system_registry/main/manager_system.c
    team/qwell/system_registry/main/stasis_system.c

Modified: team/qwell/system_registry/main/manager_system.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/system_registry/main/manager_system.c?view=diff&rev=393464&r1=393463&r2=393464
==============================================================================
--- team/qwell/system_registry/main/manager_system.c (original)
+++ team/qwell/system_registry/main/manager_system.c Tue Jul  2 13:32:22 2013
@@ -31,75 +31,10 @@
 #include "asterisk/stasis_message_router.h"
 #include "asterisk/stasis_system.h"
 
-/*** DOCUMENTATION
-	<managerEvent language="en_US" name="Registry">
-		<managerEventInstance class="EVENT_FLAG_SYSTEM">
-			<synopsis>Raised when an outbound registration completes.</synopsis>
-			<syntax>
-				<parameter name="ChannelType">
-					<para>The type of channel that was registered (or not).</para>
-				</parameter>
-				<parameter name="Username">
-					<para>The username portion of the registration.</para>
-				</parameter>
-				<parameter name="Domain">
-					<para>The address portion of the registration.</para>
-				</parameter>
-				<parameter name="Status">
-					<para>The status of the registration request.</para>
-					<enumlist>
-						<enum name="Registered"/>
-						<enum name="Unregistered"/>
-						<enum name="Rejected"/>
-						<enum name="Failed"/>
-					</enumlist>
-				</parameter>
-				<parameter name="Cause">
-					<para>What caused the rejection of the request, if available.</para>
-				</parameter>
-			</syntax>
-		</managerEventInstance>
-	</managerEvent>
- ***/
-
 /*! \brief The \ref stasis subscription returned by the forwarding of the system topic
  * to the manager topic
  */
 static struct stasis_subscription *topic_forwarder;
-
-static void system_registry_cb(void *data, struct stasis_subscription *sub,
-	struct stasis_topic *topic, struct stasis_message *message)
-{
-	const char *channeltype;
-	const char *username;
-	const char *domain;
-	const char *status;
-	const char *cause;
-	struct ast_json_payload *payload = stasis_message_data(message);
-	RAII_VAR(struct ast_str *, cause_string, ast_str_create(32), ast_free);
-
-	if (!cause_string) {
-		return;
-	}
-
-	channeltype = ast_json_string_get(ast_json_object_get(payload->json, "channeltype"));
-	username = ast_json_string_get(ast_json_object_get(payload->json, "username"));
-	domain = ast_json_string_get(ast_json_object_get(payload->json, "domain"));
-	status = ast_json_string_get(ast_json_object_get(payload->json, "status"));
-	cause = ast_json_string_get(ast_json_object_get(payload->json, "cause"));
-
-	if (!ast_strlen_zero(cause)) {
-		ast_str_set(&cause_string, 0, "Cause: %s\r\n", cause);
-	}
-
-	manager_event(EVENT_FLAG_SYSTEM, "Registry",
-		"ChannelType: %s\r\n"
-		"Username: %s\r\n"
-		"Domain: %s\r\n"
-		"Status: %s\r\n"
-		"%s",
-		channeltype, username, domain, status, ast_str_buffer(cause_string));
-}
 
 static void manager_system_shutdown(void)
 {
@@ -134,11 +69,6 @@
 
 	ast_register_atexit(manager_system_shutdown);
 
-	ret |= stasis_message_router_add(message_router,
-					 ast_system_registry_type(),
-					 system_registry_cb,
-					 NULL);
-
 	/* If somehow we failed to add any routes, just shut down the whole
 	 * thing and fail it.
 	 */

Modified: team/qwell/system_registry/main/stasis_system.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/system_registry/main/stasis_system.c?view=diff&rev=393464&r1=393463&r2=393464
==============================================================================
--- team/qwell/system_registry/main/stasis_system.c (original)
+++ team/qwell/system_registry/main/stasis_system.c Tue Jul  2 13:32:22 2013
@@ -35,15 +35,46 @@
 #include "asterisk/stasis.h"
 #include "asterisk/stasis_system.h"
 
+/*** DOCUMENTATION
+	<managerEvent language="en_US" name="Registry">
+		<managerEventInstance class="EVENT_FLAG_SYSTEM">
+			<synopsis>Raised when an outbound registration completes.</synopsis>
+			<syntax>
+				<parameter name="ChannelType">
+					<para>The type of channel that was registered (or not).</para>
+				</parameter>
+				<parameter name="Username">
+					<para>The username portion of the registration.</para>
+				</parameter>
+				<parameter name="Domain">
+					<para>The address portion of the registration.</para>
+				</parameter>
+				<parameter name="Status">
+					<para>The status of the registration request.</para>
+					<enumlist>
+						<enum name="Registered"/>
+						<enum name="Unregistered"/>
+						<enum name="Rejected"/>
+						<enum name="Failed"/>
+					</enumlist>
+				</parameter>
+				<parameter name="Cause">
+					<para>What caused the rejection of the request, if available.</para>
+				</parameter>
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
+ ***/
+
 /*! \brief The \ref stasis topic for system level changes */
 static struct stasis_topic *system_topic;
 
-/*!
- * @{ \brief Define system message types.
- */
+static struct ast_manager_event_blob *system_registry_to_ami(struct stasis_message *message);
+
 STASIS_MESSAGE_TYPE_DEFN(ast_network_change_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_system_registry_type);
-/*! @} */
+STASIS_MESSAGE_TYPE_DEFN(ast_system_registry_type,
+	.to_ami = system_registry_to_ami,
+	);
 
 void ast_system_publish_registry(const char *channeltype, const char *username, const char *domain, const char *status, const char *cause)
 {
@@ -68,6 +99,39 @@
 	}
 
 	stasis_publish(ast_system_topic(), message);
+}
+
+static struct ast_manager_event_blob *system_registry_to_ami(struct stasis_message *message)
+{
+	struct ast_json_payload *payload = stasis_message_data(message);
+	const char *channeltype;
+	const char *username;
+	const char *domain;
+	const char *status;
+	const char *cause;
+	RAII_VAR(struct ast_str *, cause_string, ast_str_create(32), ast_free);
+
+	if (!cause_string) {
+		return NULL;
+	}
+
+	channeltype = ast_json_string_get(ast_json_object_get(payload->json, "channeltype"));
+	username = ast_json_string_get(ast_json_object_get(payload->json, "username"));
+	domain = ast_json_string_get(ast_json_object_get(payload->json, "domain"));
+	status = ast_json_string_get(ast_json_object_get(payload->json, "status"));
+	cause = ast_json_string_get(ast_json_object_get(payload->json, "cause"));
+
+	if (!ast_strlen_zero(cause)) {
+		ast_str_set(&cause_string, 0, "Cause: %s\r\n", cause);
+	}
+
+	return ast_manager_event_blob_create(EVENT_FLAG_SYSTEM, "Registry",
+		"ChannelType: %s\r\n"
+		"Username: %s\r\n"
+		"Domain: %s\r\n"
+		"Status: %s\r\n"
+		"%s",
+		channeltype, username, domain, status, ast_str_buffer(cause_string));
 }
 
 struct stasis_topic *ast_system_topic(void)




More information about the asterisk-commits mailing list