[asterisk-commits] file: branch file/stasis_peerevent r389242 - in /team/file/stasis_peerevent: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon May 20 11:31:27 CDT 2013


Author: file
Date: Mon May 20 11:31:23 2013
New Revision: 389242

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389242
Log:
Add manager_endpoints which takes in the endpoint state type and then spits out a PeerStatus event.

Added:
    team/file/stasis_peerevent/main/manager_endpoints.c   (with props)
Modified:
    team/file/stasis_peerevent/include/asterisk/manager.h
    team/file/stasis_peerevent/main/manager.c

Modified: team/file/stasis_peerevent/include/asterisk/manager.h
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/include/asterisk/manager.h?view=diff&rev=389242&r1=389241&r2=389242
==============================================================================
--- team/file/stasis_peerevent/include/asterisk/manager.h (original)
+++ team/file/stasis_peerevent/include/asterisk/manager.h Mon May 20 11:31:23 2013
@@ -355,4 +355,12 @@
  */
 int manager_channels_init(void);
 
+/*!
+ * \brief Initialize support for AMI endpoint events.
+ * \return 0 on success.
+ * \return non-zero on error.
+ * \since 12
+ */
+int manager_endpoints_init(void);
+
 #endif /* _ASTERISK_MANAGER_H */

Modified: team/file/stasis_peerevent/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/main/manager.c?view=diff&rev=389242&r1=389241&r2=389242
==============================================================================
--- team/file/stasis_peerevent/main/manager.c (original)
+++ team/file/stasis_peerevent/main/manager.c Mon May 20 11:31:23 2013
@@ -7506,7 +7506,7 @@
 
 	manager_enabled = 0;
 
-	if (manager_channels_init()) {
+	if (manager_channels_init() || manager_endpoints_init()) {
 		return -1;
 	}
 

Added: team/file/stasis_peerevent/main/manager_endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/main/manager_endpoints.c?view=auto&rev=389242
==============================================================================
--- team/file/stasis_peerevent/main/manager_endpoints.c (added)
+++ team/file/stasis_peerevent/main/manager_endpoints.c Mon May 20 11:31:23 2013
@@ -1,0 +1,132 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Joshua Colp <jcolp at digium.com>
+ * David M. Lee, II <dlee at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief The Asterisk Management Interface - AMI (endpoint handling)
+ *
+ * \author Joshua Colp <jcolp at digium.com>
+ * \author David M. Lee, II <dlee at digium.com>
+ *
+  */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/callerid.h"
+#include "asterisk/channel.h"
+#include "asterisk/manager.h"
+#include "asterisk/stasis_message_router.h"
+#include "asterisk/pbx.h"
+#include "asterisk/stasis_endpoints.h"
+
+static struct stasis_message_router *endpoint_router;
+
+/*!
+ * \brief Callback used to determine whether a key should be skipped when converting a JSON object to a manager blob
+ * \param key Key from JSON blob to be evaluated
+ * \retval non-zero if the key should be excluded
+ * \retval zero if the key should not be excluded
+ */
+typedef int (*key_exclusion_cb)(const char *key);
+
+static struct ast_str *manager_str_from_json_object(struct ast_json *blob, key_exclusion_cb exclusion_cb)
+{
+	struct ast_str *output_str = ast_str_create(32);
+	struct ast_json_iter *blob_iter = ast_json_object_iter(blob);
+	if (!output_str || !blob_iter) {
+		return NULL;
+	}
+
+	do {
+		const char *key = ast_json_object_iter_key(blob_iter);
+		const char *value = ast_json_string_get(ast_json_object_iter_value(blob_iter));
+		if (exclusion_cb && exclusion_cb(key)) {
+			continue;
+		}
+
+		ast_str_append(&output_str, 0, "%s: %s\r\n", key, value);
+		if (!output_str) {
+			return NULL;
+		}
+	} while ((blob_iter = ast_json_object_iter_next(blob, blob_iter)));
+
+	return output_str;
+}
+
+static void endpoint_state_cb(void *data, struct stasis_subscription *sub,
+				    struct stasis_topic *topic,
+				    struct stasis_message *message)
+{
+	struct ast_endpoint_blob *obj = stasis_message_data(message);
+	RAII_VAR(struct ast_str *, peerstatus_event_string, NULL, ast_free);
+
+	peerstatus_event_string = manager_str_from_json_object(obj->blob, NULL);
+
+	manager_event(EVENT_FLAG_SYSTEM, "PeerStatus",
+		"ChannelType: %s\r\n"
+		"Peer: %s/%s\r\n"
+		"%s\r\n",
+		obj->snapshot->tech,
+		obj->snapshot->tech,
+		obj->snapshot->resource,
+		ast_str_buffer(peerstatus_event_string));
+}
+
+static void manager_endpoints_shutdown(void)
+{
+	stasis_message_router_unsubscribe_and_join(endpoint_router);
+	endpoint_router = NULL;
+}
+
+int manager_endpoints_init(void)
+{
+	int ret = 0;
+
+	if (endpoint_router) {
+		/* Already initialized */
+		return 0;
+	}
+
+	ast_register_atexit(manager_endpoints_shutdown);
+
+	endpoint_router = stasis_message_router_create(
+		stasis_caching_get_topic(ast_endpoint_topic_all_cached()));
+
+	if (!endpoint_router) {
+		return -1;
+	}
+
+	ret |= stasis_message_router_add(endpoint_router,
+					 ast_endpoint_state_type(),
+					 endpoint_state_cb,
+					 NULL);
+
+	/* If somehow we failed to add any routes, just shut down the whole
+	 * thing and fail it.
+	 */
+	if (ret) {
+		manager_endpoints_shutdown();
+		return -1;
+	}
+
+	return 0;
+}
+

Propchange: team/file/stasis_peerevent/main/manager_endpoints.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/file/stasis_peerevent/main/manager_endpoints.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/file/stasis_peerevent/main/manager_endpoints.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list