[asterisk-commits] kmoore: branch kmoore/stasis-bridging-channel_events r385353 - in /team/kmoor...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Apr 11 14:28:57 CDT 2013
Author: kmoore
Date: Thu Apr 11 14:28:55 2013
New Revision: 385353
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385353
Log:
Add Stasis infrastructure for bridging
Add the base necessary to publish bridge state information to whatever
consumers need it. The first of these consumers is bridge AMI events
and AMI actions used to query for information about the bridges.
Review: https://reviewboard.asterisk.org/r/2438/
(issue ASTERISK-21057)
........
Merged revisions 385352 from http://svn.asterisk.org/svn/asterisk/team/group/bridge_construction
Added:
team/kmoore/stasis-bridging-channel_events/include/asterisk/stasis_bridging.h
- copied unchanged from r385352, team/group/bridge_construction/include/asterisk/stasis_bridging.h
team/kmoore/stasis-bridging-channel_events/main/manager_bridging.c
- copied unchanged from r385352, team/group/bridge_construction/main/manager_bridging.c
team/kmoore/stasis-bridging-channel_events/main/stasis_bridging.c
- copied unchanged from r385352, team/group/bridge_construction/main/stasis_bridging.c
Modified:
team/kmoore/stasis-bridging-channel_events/ (props changed)
team/kmoore/stasis-bridging-channel_events/include/asterisk/manager.h
team/kmoore/stasis-bridging-channel_events/main/asterisk.c
team/kmoore/stasis-bridging-channel_events/main/bridging.c
team/kmoore/stasis-bridging-channel_events/main/manager.c
team/kmoore/stasis-bridging-channel_events/main/manager_channels.c
Propchange: team/kmoore/stasis-bridging-channel_events/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Thu Apr 11 14:28:55 2013
@@ -1,1 +1,1 @@
-/team/group/bridge_construction:1-385336
+/team/group/bridge_construction:1-385352
Modified: team/kmoore/stasis-bridging-channel_events/include/asterisk/manager.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging-channel_events/include/asterisk/manager.h?view=diff&rev=385353&r1=385352&r2=385353
==============================================================================
--- team/kmoore/stasis-bridging-channel_events/include/asterisk/manager.h (original)
+++ team/kmoore/stasis-bridging-channel_events/include/asterisk/manager.h Thu Apr 11 14:28:55 2013
@@ -316,6 +316,38 @@
*/
struct ast_datastore *astman_datastore_find(struct mansession *s, const struct ast_datastore_info *info, const char *uid);
+/*! \brief Struct containing info for an AMI event to send out. */
+struct ast_manager_event_blob {
+ int event_flags; /*!< Flags the event should be raised with. */
+ const char *manager_event; /*!< The event to be raised, should be a string literal. */
+ AST_DECLARE_STRING_FIELDS(
+ AST_STRING_FIELD(extra_fields); /*!< Extra fields to include in the event. */
+ );
+};
+
+/*!
+ * \since 12
+ * \brief Construct a \ref snapshot_manager_event.
+ *
+ * \param event_flags Flags the event should be raised with.
+ * \param manager_event The event to be raised, should be a string literal.
+ * \param extra_fields_fmt Format string for extra fields to include.
+ * Or NO_EXTRA_FIELDS for no extra fields.
+ *
+ * \return New \ref ast_manager_snapshot_event object.
+ * \return \c NULL on error.
+ */
+struct ast_manager_event_blob *
+__attribute__((format(printf, 3, 4)))
+ast_manager_event_blob_create(
+ int event_flags,
+ const char *manager_event,
+ const char *extra_fields_fmt,
+ ...);
+
+/*! GCC warns about blank or NULL format strings. So, shenanigans! */
+#define NO_EXTRA_FIELDS "%s", ""
+
/*!
* \brief Initialize support for AMI channel events.
* \return 0 on success.
@@ -324,4 +356,12 @@
*/
int manager_channels_init(void);
+/*!
+ * \brief Initialize support for AMI channel events.
+ * \return 0 on success.
+ * \return non-zero on error.
+ * \since 12
+ */
+int manager_bridging_init(void);
+
#endif /* _ASTERISK_MANAGER_H */
Modified: team/kmoore/stasis-bridging-channel_events/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging-channel_events/main/asterisk.c?view=diff&rev=385353&r1=385352&r2=385353
==============================================================================
--- team/kmoore/stasis-bridging-channel_events/main/asterisk.c (original)
+++ team/kmoore/stasis-bridging-channel_events/main/asterisk.c Thu Apr 11 14:28:55 2013
@@ -4220,11 +4220,6 @@
ast_http_init(); /* Start the HTTP server, if needed */
- if (init_manager()) {
- printf("%s", term_quit());
- exit(1);
- }
-
if (ast_cdr_engine_init()) {
printf("%s", term_quit());
exit(1);
@@ -4274,6 +4269,11 @@
}
if (ast_bridging_init()) {
+ printf("%s", term_quit());
+ exit(1);
+ }
+
+ if (init_manager()) {
printf("%s", term_quit());
exit(1);
}
Modified: team/kmoore/stasis-bridging-channel_events/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging-channel_events/main/bridging.c?view=diff&rev=385353&r1=385352&r2=385353
==============================================================================
--- team/kmoore/stasis-bridging-channel_events/main/bridging.c (original)
+++ team/kmoore/stasis-bridging-channel_events/main/bridging.c Thu Apr 11 14:28:55 2013
@@ -40,6 +40,7 @@
#include "asterisk/lock.h"
#include "asterisk/linkedlists.h"
#include "asterisk/bridging.h"
+#include "asterisk/stasis_bridging.h"
#include "asterisk/bridging_technology.h"
#include "asterisk/app.h"
#include "asterisk/file.h"
@@ -439,6 +440,7 @@
bridge->v_table->pull(bridge, bridge_channel);
bridge->reconfigured = 1;
+ ast_bridge_publish_leave(bridge, bridge_channel->chan);
}
/*!
@@ -510,6 +512,7 @@
}
bridge->reconfigured = 1;
+ ast_bridge_publish_enter(bridge, bridge_channel->chan);
}
/*!
@@ -1129,6 +1132,12 @@
static void destroy_bridge(void *obj)
{
struct ast_bridge *bridge = obj;
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+
+ msg = stasis_cache_clear_create(ast_bridge_snapshot_type(), bridge->uniqueid);
+ if (msg) {
+ stasis_publish(ast_bridge_topic(bridge), msg);
+ }
ast_debug(1, "Bridge %s: actually destroying %s bridge, nobody wants it anymore\n",
bridge->uniqueid, bridge->v_table->name);
@@ -1229,6 +1238,11 @@
return NULL;
}
+ if (!ast_bridge_topic(self)) {
+ ao2_ref(self, -1);
+ return NULL;
+ }
+
return self;
}
@@ -1335,6 +1349,9 @@
bridge = ast_bridge_alloc(sizeof(struct ast_bridge), &ast_bridge_base_v_table);
bridge = ast_bridge_base_init(bridge, capabilities, flags);
+ if (bridge) {
+ ast_bridge_publish_state(bridge);
+ }
return bridge;
}
@@ -3032,6 +3049,8 @@
ast_debug(1, "Merging bridge %s into bridge %s\n",
bridge2->uniqueid, bridge1->uniqueid);
+ ast_bridge_publish_merge(bridge1, bridge2);
+
/* Move channels from bridge2 over to bridge1 */
while ((bridge_channel = AST_LIST_FIRST(&bridge2->channels))) {
bridge_channel_pull(bridge_channel);
@@ -4049,6 +4068,7 @@
{
ao2_cleanup(bridge_manager);
bridge_manager = NULL;
+ ast_stasis_bridging_shutdown();
}
int ast_bridging_init(void)
@@ -4058,6 +4078,8 @@
return -1;
}
+ ast_stasis_bridging_init();
+
ast_register_atexit(bridge_shutdown);
return 0;
}
Modified: team/kmoore/stasis-bridging-channel_events/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging-channel_events/main/manager.c?view=diff&rev=385353&r1=385352&r2=385353
==============================================================================
--- team/kmoore/stasis-bridging-channel_events/main/manager.c (original)
+++ team/kmoore/stasis-bridging-channel_events/main/manager.c Thu Apr 11 14:28:55 2013
@@ -7500,6 +7500,10 @@
return -1;
}
+ if (manager_bridging_init()) {
+ return -1;
+ }
+
if (!registered) {
/* Register default actions */
ast_manager_register_xml_core("Ping", 0, action_ping);
@@ -8010,3 +8014,45 @@
return datastore;
}
+
+static void manager_event_blob_dtor(void *obj)
+{
+ struct ast_manager_event_blob *ev = obj;
+ ast_string_field_free_memory(ev);
+}
+
+struct ast_manager_event_blob *
+__attribute__((format(printf, 3, 4)))
+ast_manager_event_blob_create(
+ int event_flags,
+ const char *manager_event,
+ const char *extra_fields_fmt,
+ ...)
+{
+ RAII_VAR(struct ast_manager_event_blob *, ev, NULL, ao2_cleanup);
+ va_list argp;
+
+ ast_assert(extra_fields_fmt != NULL);
+ ast_assert(manager_event != NULL);
+
+ ev = ao2_alloc(sizeof(*ev), manager_event_blob_dtor);
+ if (!ev) {
+ return NULL;
+ }
+
+ if (ast_string_field_init(ev, 20)) {
+ return NULL;
+ }
+
+ ev->manager_event = manager_event;
+ ev->event_flags = event_flags;
+
+ va_start(argp, extra_fields_fmt);
+ ast_string_field_ptr_build_va(ev, &ev->extra_fields, extra_fields_fmt,
+ argp);
+ va_end(argp);
+
+ ao2_ref(ev, +1);
+ return ev;
+}
+
Modified: team/kmoore/stasis-bridging-channel_events/main/manager_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging-channel_events/main/manager_channels.c?view=diff&rev=385353&r1=385352&r2=385353
==============================================================================
--- team/kmoore/stasis-bridging-channel_events/main/manager_channels.c (original)
+++ team/kmoore/stasis-bridging-channel_events/main/manager_channels.c Thu Apr 11 14:28:55 2013
@@ -305,83 +305,18 @@
* \retval ast_str* on success (must be ast_freed by caller)
*/
static struct ast_str *manager_build_channel_state_string(
- const struct ast_channel_snapshot *snapshot)
+ const struct ast_channel_snapshot *snapshot)
{
return manager_build_channel_state_string_suffix(snapshot, "");
}
-/*! \brief Struct containing info for an AMI channel event to send out. */
-struct snapshot_manager_event {
- /*! event_flags manager_event() flags parameter. */
- int event_flags;
- /*! manager_event manager_event() category. */
- const char *manager_event;
- AST_DECLARE_STRING_FIELDS(
- /* extra fields to include in the event. */
- AST_STRING_FIELD(extra_fields);
- );
-};
-
-static void snapshot_manager_event_dtor(void *obj)
-{
- struct snapshot_manager_event *ev = obj;
- ast_string_field_free_memory(ev);
-}
-
-/*!
- * \brief Construct a \ref snapshot_manager_event.
- * \param event_flags manager_event() flags parameter.
- * \param manager_event manager_event() category.
- * \param extra_fields_fmt Format string for extra fields to include.
- * Or NO_EXTRA_FIELDS for no extra fields.
- * \return New \ref snapshot_manager_event object.
- * \return \c NULL on error.
- */
-static struct snapshot_manager_event *
-__attribute__((format(printf, 3, 4)))
-snapshot_manager_event_create(
- int event_flags,
- const char *manager_event,
- const char *extra_fields_fmt,
- ...)
-{
- RAII_VAR(struct snapshot_manager_event *, ev, NULL, ao2_cleanup);
- va_list argp;
-
- ast_assert(extra_fields_fmt != NULL);
- ast_assert(manager_event != NULL);
-
- ev = ao2_alloc(sizeof(*ev), snapshot_manager_event_dtor);
- if (!ev) {
- return NULL;
- }
-
- if (ast_string_field_init(ev, 20)) {
- return NULL;
- }
-
- ev->manager_event = manager_event;
- ev->event_flags = event_flags;
-
- va_start(argp, extra_fields_fmt);
- ast_string_field_ptr_build_va(ev, &ev->extra_fields, extra_fields_fmt,
- argp);
- va_end(argp);
-
- ao2_ref(ev, +1);
- return ev;
-}
-
-/*! GCC warns about blank or NULL format strings. So, shenanigans! */
-#define NO_EXTRA_FIELDS "%s", ""
-
/*! \brief Typedef for callbacks that get called on channel snapshot updates */
-typedef struct snapshot_manager_event *(*snapshot_monitor)(
+typedef struct ast_manager_event_blob *(*channel_snapshot_monitor)(
struct ast_channel_snapshot *old_snapshot,
struct ast_channel_snapshot *new_snapshot);
/*! \brief Handle channel state changes */
-static struct snapshot_manager_event *channel_state_change(
+static struct ast_manager_event_blob *channel_state_change(
struct ast_channel_snapshot *old_snapshot,
struct ast_channel_snapshot *new_snapshot)
{
@@ -398,7 +333,7 @@
*/
if (!old_snapshot) {
- return snapshot_manager_event_create(
+ return ast_manager_event_blob_create(
EVENT_FLAG_CALL, "Newchannel", NO_EXTRA_FIELDS);
}
@@ -406,7 +341,7 @@
is_hungup = ast_test_flag(&new_snapshot->flags, AST_FLAG_ZOMBIE) ? 1 : 0;
if (!was_hungup && is_hungup) {
- return snapshot_manager_event_create(
+ return ast_manager_event_blob_create(
EVENT_FLAG_CALL, "Hangup",
"Cause: %d\r\n"
"Cause-txt: %s\r\n",
@@ -415,7 +350,7 @@
}
if (old_snapshot->state != new_snapshot->state) {
- return snapshot_manager_event_create(
+ return ast_manager_event_blob_create(
EVENT_FLAG_CALL, "Newstate", NO_EXTRA_FIELDS);
}
@@ -451,7 +386,7 @@
strcmp(old_snapshot->exten, new_snapshot->exten) == 0;
}
-static struct snapshot_manager_event *channel_newexten(
+static struct ast_manager_event_blob *channel_newexten(
struct ast_channel_snapshot *old_snapshot,
struct ast_channel_snapshot *new_snapshot)
{
@@ -470,7 +405,7 @@
}
/* DEPRECATED: Extension field deprecated in 12; remove in 14 */
- return snapshot_manager_event_create(
+ return ast_manager_event_blob_create(
EVENT_FLAG_CALL, "Newexten",
"Extension: %s\r\n"
"Application: %s\r\n"
@@ -497,7 +432,7 @@
strcmp(old_snapshot->caller_name, new_snapshot->caller_name) == 0;
}
-static struct snapshot_manager_event *channel_new_callerid(
+static struct ast_manager_event_blob *channel_new_callerid(
struct ast_channel_snapshot *old_snapshot,
struct ast_channel_snapshot *new_snapshot)
{
@@ -510,14 +445,14 @@
return NULL;
}
- return snapshot_manager_event_create(
+ return ast_manager_event_blob_create(
EVENT_FLAG_CALL, "NewCallerid",
"CID-CallingPres: %d (%s)\r\n",
new_snapshot->caller_pres,
ast_describe_caller_presentation(new_snapshot->caller_pres));
}
-snapshot_monitor monitors[] = {
+channel_snapshot_monitor channel_monitors[] = {
channel_state_change,
channel_newexten,
channel_new_callerid
@@ -542,9 +477,9 @@
old_snapshot = stasis_message_data(update->old_snapshot);
new_snapshot = stasis_message_data(update->new_snapshot);
- for (i = 0; i < ARRAY_LEN(monitors); ++i) {
- RAII_VAR(struct snapshot_manager_event *, ev, NULL, ao2_cleanup);
- ev = monitors[i](old_snapshot, new_snapshot);
+ for (i = 0; i < ARRAY_LEN(channel_monitors); ++i) {
+ RAII_VAR(struct ast_manager_event_blob *, ev, NULL, ao2_cleanup);
+ ev = channel_monitors[i](old_snapshot, new_snapshot);
if (!ev) {
continue;
More information about the asterisk-commits
mailing list