[asterisk-commits] qwell: branch qwell/system_registry r392044 - in /team/qwell/system_registry:...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jun 17 12:20:27 CDT 2013
Author: qwell
Date: Mon Jun 17 12:20:23 2013
New Revision: 392044
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392044
Log:
Do the system topic shuffle.
Added:
team/qwell/system_registry/include/asterisk/stasis_system.h
- copied, changed from r392030, team/qwell/system_registry/include/asterisk/stasis_endpoints.h
team/qwell/system_registry/main/stasis_system.c
- copied, changed from r392030, team/qwell/system_registry/main/stasis_bridging.c
Modified:
team/qwell/system_registry/channels/chan_iax2.c
team/qwell/system_registry/channels/chan_sip.c
team/qwell/system_registry/include/asterisk.h
team/qwell/system_registry/include/asterisk/app.h
team/qwell/system_registry/main/asterisk.c
team/qwell/system_registry/main/manager_system.c
team/qwell/system_registry/res/res_stun_monitor.c
Modified: team/qwell/system_registry/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/system_registry/channels/chan_iax2.c?view=diff&rev=392044&r1=392043&r2=392044
==============================================================================
--- team/qwell/system_registry/channels/chan_iax2.c (original)
+++ team/qwell/system_registry/channels/chan_iax2.c Mon Jun 17 12:20:23 2013
@@ -102,6 +102,8 @@
#include "asterisk/netsock2.h"
#include "asterisk/security_events.h"
#include "asterisk/bridging.h"
+#include "asterisk/stasis.h"
+#include "asterisk/stasis_system.h"
#include "iax2/include/iax2.h"
#include "iax2/include/firmware.h"
@@ -8391,27 +8393,7 @@
static void iax2_publish_registry(const char *username, const char *domain, const char *status, const char *cause)
{
- RAII_VAR(struct ast_json *, registry, NULL, ast_json_unref);
- RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
- RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
-
- registry = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s}",
- "type", "registry",
- "channeltype", "IAX2",
- "username", username,
- "domain", domain,
- "status", status,
- "cause", S_OR(cause, ""));
-
- if (!(payload = ast_json_payload_create(registry))) {
- return;
- }
-
- if (!(message = stasis_message_create(ast_system_registry_type(), payload))) {
- return;
- }
-
- stasis_publish(ast_system_topic(), message);
+ ast_system_publish_registry("IAX2", username, domain, status, cause);
}
/*! \brief Acknowledgment received for OUR registration */
Modified: team/qwell/system_registry/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/system_registry/channels/chan_sip.c?view=diff&rev=392044&r1=392043&r2=392044
==============================================================================
--- team/qwell/system_registry/channels/chan_sip.c (original)
+++ team/qwell/system_registry/channels/chan_sip.c Mon Jun 17 12:20:23 2013
@@ -295,7 +295,9 @@
#include "asterisk/sip_api.h"
#include "asterisk/app.h"
#include "asterisk/bridging.h"
+#include "asterisk/stasis.h"
#include "asterisk/stasis_endpoints.h"
+#include "asterisk/stasis_system.h"
#include "asterisk/features_config.h"
/*** DOCUMENTATION
@@ -15060,26 +15062,7 @@
static void sip_publish_registry(const char *username, const char *domain, const char *status)
{
- RAII_VAR(struct ast_json *, registry, NULL, ast_json_unref);
- RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
- RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
-
- registry = ast_json_pack("{s: s, s: s, s: s, s: s, s: s}",
- "type", "registry",
- "channeltype", "SIP",
- "username", username,
- "domain", domain,
- "status", status);
-
- if (!(payload = ast_json_payload_create(registry))) {
- return;
- }
-
- if (!(message = stasis_message_create(ast_system_registry_type(), payload))) {
- return;
- }
-
- stasis_publish(ast_system_topic(), message);
+ ast_system_publish_registry("SIP", username, domain, status, NULL);
}
/*! \brief Update registration with SIP Proxy.
Modified: team/qwell/system_registry/include/asterisk.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/system_registry/include/asterisk.h?view=diff&rev=392044&r1=392043&r2=392044
==============================================================================
--- team/qwell/system_registry/include/asterisk.h (original)
+++ team/qwell/system_registry/include/asterisk.h Mon Jun 17 12:20:23 2013
@@ -216,27 +216,6 @@
#define ast_mark(a, b) do { } while (0)
#endif /* LOW_MEMORY */
-/*!
- * \since 12
- * \brief A \ref stasis topic which publishes messages regarding system changes
- *
- * \retval \ref stasis_topic for system level changes
- * \retval NULL on error
- */
-struct stasis_topic *ast_system_topic(void);
-
-/*!
- * \since 12
- * \brief A \ref stasis_message_type for network changes
- *
- * \retval NULL on error
- * \retval \ref stasis_message_type for network changes
- *
- * \note Messages of this type should always be issued on and expected from
- * the \ref ast_system_topic \ref stasis topic
- */
-struct stasis_message_type *ast_network_change_type(void);
-
/*! \brief
* Definition of various structures that many asterisk files need,
* but only because they need to know that the type exists.
Modified: team/qwell/system_registry/include/asterisk/app.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/system_registry/include/asterisk/app.h?view=diff&rev=392044&r1=392043&r2=392044
==============================================================================
--- team/qwell/system_registry/include/asterisk/app.h (original)
+++ team/qwell/system_registry/include/asterisk/app.h Mon Jun 17 12:20:23 2013
@@ -29,6 +29,7 @@
#include "asterisk/file.h"
#include "asterisk/linkedlists.h"
#include "asterisk/utils.h"
+#include "asterisk/stasis.h"
struct ast_flags64;
Copied: team/qwell/system_registry/include/asterisk/stasis_system.h (from r392030, team/qwell/system_registry/include/asterisk/stasis_endpoints.h)
URL: http://svnview.digium.com/svn/asterisk/team/qwell/system_registry/include/asterisk/stasis_system.h?view=diff&rev=392044&p1=team/qwell/system_registry/include/asterisk/stasis_endpoints.h&r1=392030&p2=team/qwell/system_registry/include/asterisk/stasis_system.h&r2=392044
==============================================================================
--- team/qwell/system_registry/include/asterisk/stasis_endpoints.h (original)
+++ team/qwell/system_registry/include/asterisk/stasis_system.h Mon Jun 17 12:20:23 2013
@@ -3,7 +3,7 @@
*
* Copyright (C) 2013, Digium, Inc.
*
- * David M. Lee, II <dlee at digium.com>
+ * Jason Parker <jparker at digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
@@ -16,141 +16,56 @@
* at the top of the source tree.
*/
-#ifndef _ASTERISK_STASIS_ENDPOINTS_H
-#define _ASTERISK_STASIS_ENDPOINTS_H
+#ifndef _ASTERISK_STASIS_SYSTEM_H
+#define _ASTERISK_STASIS_SYSTEM_H
-/*! \file
+#include "asterisk/json.h"
+#include "asterisk/stasis.h"
+
+/*!
+ * \since 12
+ * \brief Publish a channel driver outgoing registration message
*
- * \brief Endpoint abstractions.
+ * \param channeltype The channel driver that published the message
+ * \param username The username that was used to register
+ * \param domain The domain that was used to register
+ * \param status The result of the registration
+ * \param cause The reason for the result
+ */
+void ast_system_publish_registry(const char *channeltype, const char *username, const char *domain, const char *status, const char *cause);
+
+/*!
+ * \since 12
+ * \brief A \ref stasis topic which publishes messages regarding system changes
*
- * \author David M. Lee, II <dlee at digium.com>
+ * \retval \ref stasis_topic for system level changes
+ * \retval NULL on error
+ */
+struct stasis_topic *ast_system_topic(void);
+
+/*!
+ * \since 12
+ * \brief A \ref stasis_message_type for network changes
+ *
+ * \retval NULL on error
+ * \retval \ref stasis_message_type for network changes
+ *
+ * \note Messages of this type should always be issued on and expected from
+ * the \ref ast_system_topic \ref stasis topic
+ */
+struct stasis_message_type *ast_network_change_type(void);
+
+/*!
+ * \brief A \ref stasis_message_type for outbound registration.
* \since 12
*/
-
-#include "asterisk/endpoints.h"
-#include "asterisk/json.h"
-#include "asterisk/stasis.h"
-#include "asterisk/stringfields.h"
-
-/*! \addtogroup StasisTopicsAndMessages
- * @{
- */
+struct stasis_message_type *ast_system_registry_type(void);
/*!
- * \brief A snapshot of an endpoint's state.
- *
- * The id for an endpoint is tech/resource. The duplication is needed because
- * there are several cases where any of the three values would be needed, and
- * constantly splitting or reassembling would be a pain.
- *
- * \since 12
+ * \brief Initialize the stasis system topic and message types
+ * \retval 0 on success
+ * \retval -1 on failure
*/
-struct ast_endpoint_snapshot {
- AST_DECLARE_STRING_FIELDS(
- AST_STRING_FIELD(id); /*!< unique id for this endpoint. */
- AST_STRING_FIELD(tech); /*!< Channel technology */
- AST_STRING_FIELD(resource); /*!< Tech-unique name */
- );
+int ast_stasis_system_init(void);
- /*! Endpoint state */
- enum ast_endpoint_state state;
- /*!
- * Maximum number of channels this endpoint supports. If the upper limit
- * for an endpoint is unknown, this field is set to -1.
- */
- int max_channels;
- /*! Number of channels currently active on this endpoint */
- int num_channels;
- /*! Channel ids */
- char *channel_ids[];
-};
-
-/*!
- * \brief Blob of data associated with an endpoint.
- *
- * The blob is actually a JSON object of structured data. It has a "type" field
- * which contains the type string describing this blob.
- *
- * \since 12
- */
-struct ast_endpoint_blob {
- struct ast_endpoint_snapshot *snapshot;
- struct ast_json *blob;
-};
-
-/*!
- * \brief Message type for \ref ast_endpoint_snapshot.
- * \since 12
- */
-struct stasis_message_type *ast_endpoint_snapshot_type(void);
-
-/*!
- * \brief Create a snapshot of an endpoint
- * \param endpoint Endpoint to snap a shot of.
- * \return Snapshot of the endpoint.
- * \return \c NULL on error.
- * \since 12
- */
-struct ast_endpoint_snapshot *ast_endpoint_snapshot_create(
- struct ast_endpoint *endpoint);
-
-/*!
- * \brief Returns the topic for a specific endpoint.
- *
- * \param endpoint The endpoint.
- * \return The topic for the given endpoint.
- * \return ast_endpoint_topic_all() if endpoint is \c NULL.
- * \since 12
- */
-struct stasis_topic *ast_endpoint_topic(struct ast_endpoint *endpoint);
-
-/*!
- * \brief Topic for all endpoint releated messages.
- * \since 12
- */
-struct stasis_topic *ast_endpoint_topic_all(void);
-
-/*!
- * \brief Cached topic for all endpoint related messages.
- * \since 12
- */
-struct stasis_caching_topic *ast_endpoint_topic_all_cached(void);
-
-/*!
- * \brief Retrieve the most recent snapshot for the endpoint with the given
- * name.
- *
- * \param tech Name of the endpoint's technology.
- * \param resource Resource name of the endpoint.
- * \param guaranteed Whether to require all pending messages to have been processed or not.
- * \return Snapshot of the endpoint with the given name.
- * \return \c NULL if endpoint is not found, or on error.
- * \since 12
- */
-struct ast_endpoint_snapshot *ast_endpoint_latest_snapshot(const char *tech,
- const char *resource,
- unsigned int guaranteed
-);
-
-/*! @} */
-
-/*!
- * \brief Build a JSON object from a \ref ast_endpoint_snapshot.
- *
- * \param snapshot Endpoint snapshot.
- * \return JSON object representing endpoint snapshot.
- * \return \c NULL on error
- */
-struct ast_json *ast_endpoint_snapshot_to_json(
- const struct ast_endpoint_snapshot *snapshot);
-
-/*!
- * \brief Initialization function for endpoint stasis support.
- *
- * \return 0 on success.
- * \return non-zero on error.
- * \since 12
- */
-int ast_endpoint_stasis_init(void);
-
-#endif /* _ASTERISK_STASIS_ENDPOINTS_H */
+#endif /* _ASTERISK_STASIS_SYSTEM_H */
Modified: team/qwell/system_registry/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/system_registry/main/asterisk.c?view=diff&rev=392044&r1=392043&r2=392044
==============================================================================
--- team/qwell/system_registry/main/asterisk.c (original)
+++ team/qwell/system_registry/main/asterisk.c Mon Jun 17 12:20:23 2013
@@ -243,6 +243,7 @@
#include "asterisk/stasis.h"
#include "asterisk/json.h"
#include "asterisk/stasis_endpoints.h"
+#include "asterisk/stasis_system.h"
#include "asterisk/security_events.h"
#include "../defaults.h"
@@ -446,21 +447,12 @@
unsigned int need_quit_handler:1;
} sig_flags;
-/*! \brief The \ref stasis topic for system level changes */
-static struct stasis_topic *system_topic;
-
-/*!\ brief The \ref stasis_message_type for network changes */
-STASIS_MESSAGE_TYPE_DEFN(ast_network_change_type);
-
#if !defined(LOW_MEMORY)
struct file_version {
AST_RWLIST_ENTRY(file_version) list;
const char *file;
char *version;
};
-
-/*! \brief The \ref stasis topic for system level changes */
-static struct stasis_topic *system_topic;
static AST_RWLIST_HEAD_STATIC(file_versions, file_version);
@@ -1095,36 +1087,6 @@
}
#endif /* ! LOW_MEMORY */
-
-struct stasis_topic *ast_system_topic(void)
-{
- return system_topic;
-}
-
-/*! \brief Cleanup the \ref stasis system level items */
-static void stasis_system_topic_cleanup(void)
-{
- ao2_cleanup(system_topic);
- system_topic = NULL;
- STASIS_MESSAGE_TYPE_CLEANUP(ast_network_change_type);
-}
-
-/*! \brief Initialize the system level items for \ref stasis */
-static int stasis_system_topic_init(void)
-{
- ast_register_cleanup(stasis_system_topic_cleanup);
-
- system_topic = stasis_topic_create("ast_system");
- if (!system_topic) {
- return 1;
- }
-
- if (STASIS_MESSAGE_TYPE_INIT(ast_network_change_type) != 0) {
- return -1;
- }
-
- return 0;
-}
static void publish_fully_booted(void)
{
@@ -4206,7 +4168,7 @@
printf("Stasis initialization failed.\n%s", term_quit());
exit(1);
}
- if (stasis_system_topic_init()) {
+ if (ast_stasis_system_init()) {
printf("Stasis system-level information initialization failed.\n%s", term_quit());
exit(1);
}
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=392044&r1=392043&r2=392044
==============================================================================
--- team/qwell/system_registry/main/manager_system.c (original)
+++ team/qwell/system_registry/main/manager_system.c Mon Jun 17 12:20:23 2013
@@ -27,11 +27,10 @@
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-//#include "asterisk/manager.h"
#include "asterisk/app.h"
-//#include "asterisk/channel.h"
+#include "asterisk/stasis.h"
#include "asterisk/stasis_message_router.h"
-#include "asterisk/stasis.h"
+#include "asterisk/stasis_system.h"
/*** DOCUMENTATION
***/
@@ -41,24 +40,26 @@
*/
static struct stasis_subscription *topic_forwarder;
-static void system_registry_cb(struct ast_json *obj)
+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, NULL, ast_free);
if (!(cause_string = ast_str_create(32))) {
return;
}
- channeltype = ast_json_string_get(ast_json_object_get(obj, "channeltype"));
- username = ast_json_string_get(ast_json_object_get(obj, "username"));
- domain = ast_json_string_get(ast_json_object_get(obj, "domain"));
- status = ast_json_string_get(ast_json_object_get(obj, "status"));
- cause = ast_json_string_get(ast_json_object_get(obj, "cause"));
+ 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);
@@ -131,7 +132,7 @@
ast_register_atexit(manager_system_shutdown);
ret |= stasis_message_router_add(message_router,
- ast_system_register_type(),
+ ast_system_registry_type(),
system_registry_cb,
NULL);
Copied: team/qwell/system_registry/main/stasis_system.c (from r392030, team/qwell/system_registry/main/stasis_bridging.c)
URL: http://svnview.digium.com/svn/asterisk/team/qwell/system_registry/main/stasis_system.c?view=diff&rev=392044&p1=team/qwell/system_registry/main/stasis_bridging.c&r1=392030&p2=team/qwell/system_registry/main/stasis_system.c&r2=392044
==============================================================================
--- team/qwell/system_registry/main/stasis_bridging.c (original)
+++ team/qwell/system_registry/main/stasis_system.c Mon Jun 17 12:20:23 2013
@@ -3,7 +3,7 @@
*
* Copyright (C) 2013, Digium, Inc.
*
- * Kinsey Moore <kmoore at digium.com>
+ * Jason Parker <jparker at digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
@@ -18,9 +18,9 @@
/*! \file
*
- * \brief Stasis Messages and Data Types for Bridge Objects
+ * \brief Stasis Messages and Data Types for System events
*
- * \author Kinsey Moore <kmoore at digium.com>
+ * \author Jason Parker <jparker at digium.com>
*/
/*** MODULEINFO
@@ -33,344 +33,74 @@
#include "asterisk/astobj2.h"
#include "asterisk/stasis.h"
-#include "asterisk/channel.h"
-#include "asterisk/stasis_bridging.h"
-#include "asterisk/stasis_channels.h"
-#include "asterisk/bridging.h"
-#include "asterisk/bridging_technology.h"
+#include "asterisk/stasis_system.h"
-#define SNAPSHOT_CHANNELS_BUCKETS 13
+/*! \brief The \ref stasis topic for system level changes */
+static struct stasis_topic *system_topic;
/*!
- * @{ \brief Define bridge message types.
+ * @{ \brief Define system message types.
*/
-STASIS_MESSAGE_TYPE_DEFN(ast_bridge_snapshot_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_bridge_merge_message_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_entered_bridge_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_left_bridge_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_network_change_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_system_registry_type);
/*! @} */
-/*! \brief Aggregate topic for bridge messages */
-static struct stasis_topic *bridge_topic_all;
+void ast_system_publish_registry(const char *channeltype, const char *username, const char *domain, const char *status, const char *cause)
+{
+ RAII_VAR(struct ast_json *, registry, NULL, ast_json_unref);
+ RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
+ RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
-/*! \brief Caching aggregate topic for bridge snapshots */
-static struct stasis_caching_topic *bridge_topic_all_cached;
+ registry = ast_json_pack("{s: s, s: s, s: s, s: s, s: s, s: s}",
+ "type", "registry",
+ "channeltype", channeltype,
+ "username", username,
+ "domain", domain,
+ "status", status,
+ "cause", S_OR(cause, ""));
-/*! \brief Topic pool for individual bridge topics */
-static struct stasis_topic_pool *bridge_topic_pool;
-
-/*! \brief Destructor for bridge snapshots */
-static void bridge_snapshot_dtor(void *obj)
-{
- struct ast_bridge_snapshot *snapshot = obj;
- ast_string_field_free_memory(snapshot);
- ao2_cleanup(snapshot->channels);
- snapshot->channels = NULL;
-}
-
-struct ast_bridge_snapshot *ast_bridge_snapshot_create(struct ast_bridge *bridge)
-{
- RAII_VAR(struct ast_bridge_snapshot *, snapshot, NULL, ao2_cleanup);
- struct ast_bridge_channel *bridge_channel;
-
- snapshot = ao2_alloc(sizeof(*snapshot), bridge_snapshot_dtor);
- if (!snapshot || ast_string_field_init(snapshot, 128)) {
- return NULL;
- }
-
- snapshot->channels = ast_str_container_alloc(SNAPSHOT_CHANNELS_BUCKETS);
- if (!snapshot->channels) {
- return NULL;
- }
-
- AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {
- if (ast_str_container_add(snapshot->channels,
- ast_channel_uniqueid(bridge_channel->chan))) {
- return NULL;
- }
- }
-
- ast_string_field_set(snapshot, uniqueid, bridge->uniqueid);
- ast_string_field_set(snapshot, technology, bridge->technology->name);
-
- snapshot->feature_flags = bridge->feature_flags;
- snapshot->capabilities = bridge->technology->capabilities;
- snapshot->num_channels = bridge->num_channels;
- snapshot->num_active = bridge->num_active;
-
- ao2_ref(snapshot, +1);
- return snapshot;
-}
-
-struct stasis_topic *ast_bridge_topic(struct ast_bridge *bridge)
-{
- struct stasis_topic *bridge_topic = stasis_topic_pool_get_topic(bridge_topic_pool, bridge->uniqueid);
- if (!bridge_topic) {
- return ast_bridge_topic_all();
- }
- return bridge_topic;
-}
-
-struct stasis_topic *ast_bridge_topic_all(void)
-{
- return bridge_topic_all;
-}
-
-struct stasis_caching_topic *ast_bridge_topic_all_cached(void)
-{
- return bridge_topic_all_cached;
-}
-
-void ast_bridge_publish_state(struct ast_bridge *bridge)
-{
- RAII_VAR(struct ast_bridge_snapshot *, snapshot, NULL, ao2_cleanup);
- RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
-
- ast_assert(bridge != NULL);
-
- snapshot = ast_bridge_snapshot_create(bridge);
- if (!snapshot) {
+ if (!(payload = ast_json_payload_create(registry))) {
return;
}
- msg = stasis_message_create(ast_bridge_snapshot_type(), snapshot);
- if (!msg) {
+ if (!(message = stasis_message_create(ast_system_registry_type(), payload))) {
return;
}
- stasis_publish(ast_bridge_topic(bridge), msg);
+ stasis_publish(ast_system_topic(), message);
}
-static void bridge_publish_state_from_blob(struct ast_bridge_blob *obj)
+struct stasis_topic *ast_system_topic(void)
{
- RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+ return system_topic;
+}
- ast_assert(obj != NULL);
+/*! \brief Cleanup the \ref stasis system level items */
+static void stasis_system_cleanup(void)
+{
+ ao2_cleanup(system_topic);
+ system_topic = NULL;
+ STASIS_MESSAGE_TYPE_CLEANUP(ast_network_change_type);
+ STASIS_MESSAGE_TYPE_CLEANUP(ast_system_registry_type);
+}
- msg = stasis_message_create(ast_bridge_snapshot_type(), obj->bridge);
- if (!msg) {
- return;
+/*! \brief Initialize the system level items for \ref stasis */
+int ast_stasis_system_init(void)
+{
+ ast_register_cleanup(stasis_system_cleanup);
+
+ system_topic = stasis_topic_create("ast_system");
+ if (!system_topic) {
+ return 1;
}
- stasis_publish(stasis_topic_pool_get_topic(bridge_topic_pool, obj->bridge->uniqueid), msg);
-}
-
-/*! \brief Destructor for bridge merge messages */
-static void bridge_merge_message_dtor(void *obj)
-{
- struct ast_bridge_merge_message *msg = obj;
-
- ao2_cleanup(msg->to);
- msg->to = NULL;
- ao2_cleanup(msg->from);
- msg->from = NULL;
-}
-
-/*! \brief Bridge merge message creation helper */
-static struct ast_bridge_merge_message *bridge_merge_message_create(struct ast_bridge *to, struct ast_bridge *from)
-{
- RAII_VAR(struct ast_bridge_merge_message *, msg, NULL, ao2_cleanup);
-
- msg = ao2_alloc(sizeof(*msg), bridge_merge_message_dtor);
- if (!msg) {
- return NULL;
+ if (STASIS_MESSAGE_TYPE_INIT(ast_network_change_type) != 0) {
+ return -1;
}
- msg->to = ast_bridge_snapshot_create(to);
- if (!msg->to) {
- return NULL;
+ if (STASIS_MESSAGE_TYPE_INIT(ast_system_registry_type) != 0) {
+ return -1;
}
- msg->from = ast_bridge_snapshot_create(from);
- if (!msg->from) {
- return NULL;
- }
-
- ao2_ref(msg, +1);
- return msg;
+ return 0;
}
-
-void ast_bridge_publish_merge(struct ast_bridge *to, struct ast_bridge *from)
-{
- RAII_VAR(struct ast_bridge_merge_message *, merge_msg, NULL, ao2_cleanup);
- RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
-
- ast_assert(to != NULL);
- ast_assert(from != NULL);
-
- merge_msg = bridge_merge_message_create(to, from);
- if (!merge_msg) {
- return;
- }
-
- msg = stasis_message_create(ast_bridge_merge_message_type(), merge_msg);
- if (!msg) {
- return;
- }
-
- stasis_publish(ast_bridge_topic_all(), msg);
-}
-
-static void bridge_blob_dtor(void *obj)
-{
- struct ast_bridge_blob *event = obj;
- ao2_cleanup(event->bridge);
- event->bridge = NULL;
- ao2_cleanup(event->channel);
- event->channel = NULL;
- ast_json_unref(event->blob);
- event->blob = NULL;
-}
-
-struct stasis_message *ast_bridge_blob_create(
- struct stasis_message_type *message_type,
- struct ast_bridge *bridge,
- struct ast_channel *chan,
- struct ast_json *blob)
-{
- RAII_VAR(struct ast_bridge_blob *, obj, NULL, ao2_cleanup);
- RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
-
- obj = ao2_alloc(sizeof(*obj), bridge_blob_dtor);
- if (!obj) {
- return NULL;
- }
-
- if (bridge) {
- obj->bridge = ast_bridge_snapshot_create(bridge);
- if (obj->bridge == NULL) {
- return NULL;
- }
- }
-
- if (chan) {
- obj->channel = ast_channel_snapshot_create(chan);
- if (obj->channel == NULL) {
- return NULL;
- }
- }
-
- if (blob) {
- obj->blob = ast_json_ref(blob);
- }
-
- msg = stasis_message_create(message_type, obj);
- if (!msg) {
- return NULL;
- }
-
- ao2_ref(msg, +1);
- return msg;
-}
-
-void ast_bridge_publish_enter(struct ast_bridge *bridge, struct ast_channel *chan)
-{
- RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
-
- msg = ast_bridge_blob_create(ast_channel_entered_bridge_type(), bridge, chan, NULL);
- if (!msg) {
- return;
- }
-
- /* enter blob first, then state */
- stasis_publish(ast_bridge_topic(bridge), msg);
- bridge_publish_state_from_blob(stasis_message_data(msg));
-}
-
-void ast_bridge_publish_leave(struct ast_bridge *bridge, struct ast_channel *chan)
-{
- RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
-
- msg = ast_bridge_blob_create(ast_channel_left_bridge_type(), bridge, chan, NULL);
- if (!msg) {
- return;
- }
-
- /* state first, then leave blob (opposite of enter, preserves nesting of events) */
- bridge_publish_state_from_blob(stasis_message_data(msg));
- stasis_publish(ast_bridge_topic(bridge), msg);
-}
-
-struct ast_json *ast_bridge_snapshot_to_json(const struct ast_bridge_snapshot *snapshot)
-{
- RAII_VAR(struct ast_json *, json_chan, NULL, ast_json_unref);
- int r = 0;
-
- if (snapshot == NULL) {
- return NULL;
- }
-
- json_chan = ast_json_object_create();
- if (!json_chan) { ast_log(LOG_ERROR, "Error creating channel json object\n"); return NULL; }
-
- r = ast_json_object_set(json_chan, "bridge-uniqueid", ast_json_string_create(snapshot->uniqueid));
- if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
- r = ast_json_object_set(json_chan, "bridge-technology", ast_json_string_create(snapshot->technology));
- if (r) { ast_log(LOG_ERROR, "Error adding attrib to channel json object\n"); return NULL; }
-
- return ast_json_ref(json_chan);
-}
-
-struct ast_bridge_snapshot *ast_bridge_snapshot_get_latest(const char *uniqueid)
-{
- RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
- struct ast_bridge_snapshot *snapshot;
-
- ast_assert(!ast_strlen_zero(uniqueid));
-
- message = stasis_cache_get(ast_bridge_topic_all_cached(),
- ast_bridge_snapshot_type(),
- uniqueid);
- if (!message) {
- return NULL;
- }
-
- snapshot = stasis_message_data(message);
- if (!snapshot) {
- return NULL;
- }
- ao2_ref(snapshot, +1);
- return snapshot;
-}
-
-static void stasis_bridging_cleanup(void)
-{
- ao2_cleanup(bridge_topic_all);
- bridge_topic_all = NULL;
- bridge_topic_all_cached = stasis_caching_unsubscribe_and_join(
- bridge_topic_all_cached);
- ao2_cleanup(bridge_topic_pool);
- bridge_topic_pool = NULL;
-
- STASIS_MESSAGE_TYPE_CLEANUP(ast_bridge_snapshot_type);
- STASIS_MESSAGE_TYPE_CLEANUP(ast_bridge_merge_message_type);
- STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_entered_bridge_type);
- STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_left_bridge_type);
-}
-
-/*! \brief snapshot ID getter for caching topic */
-static const char *bridge_snapshot_get_id(struct stasis_message *msg)
-{
- struct ast_bridge_snapshot *snapshot;
- if (stasis_message_type(msg) != ast_bridge_snapshot_type()) {
- return NULL;
- }
- snapshot = stasis_message_data(msg);
- return snapshot->uniqueid;
-}
-
-int ast_stasis_bridging_init(void)
-{
- ast_register_cleanup(stasis_bridging_cleanup);
-
- STASIS_MESSAGE_TYPE_INIT(ast_bridge_snapshot_type);
- STASIS_MESSAGE_TYPE_INIT(ast_bridge_merge_message_type);
- STASIS_MESSAGE_TYPE_INIT(ast_channel_entered_bridge_type);
- STASIS_MESSAGE_TYPE_INIT(ast_channel_left_bridge_type);
- bridge_topic_all = stasis_topic_create("ast_bridge_topic_all");
- bridge_topic_all_cached = stasis_caching_topic_create(bridge_topic_all, bridge_snapshot_get_id);
- bridge_topic_pool = stasis_topic_pool_create(bridge_topic_all);
- return !bridge_topic_all
- || !bridge_topic_all_cached
- || !bridge_topic_pool ? -1 : 0;
-}
Modified: team/qwell/system_registry/res/res_stun_monitor.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/system_registry/res/res_stun_monitor.c?view=diff&rev=392044&r1=392043&r2=392044
==============================================================================
--- team/qwell/system_registry/res/res_stun_monitor.c (original)
+++ team/qwell/system_registry/res/res_stun_monitor.c Mon Jun 17 12:20:23 2013
@@ -39,8 +39,9 @@
#include "asterisk/lock.h"
#include "asterisk/acl.h"
#include "asterisk/cli.h"
+#include "asterisk/json.h"
#include "asterisk/stasis.h"
-#include "asterisk/json.h"
+#include "asterisk/stasis_system.h"
#include "asterisk/astobj2.h"
#include <fcntl.h>
More information about the asterisk-commits
mailing list