[asterisk-commits] jrose: branch jrose/bridge_projects r385392 - in /team/jrose/bridge_projects:...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 11 18:28:48 CDT 2013


Author: jrose
Date: Thu Apr 11 18:28:44 2013
New Revision: 385392

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385392
Log:
fix conflicts and enable automerge again.

Modified:
    team/jrose/bridge_projects/   (props changed)
    team/jrose/bridge_projects/include/asterisk/manager.h
    team/jrose/bridge_projects/include/asterisk/strings.h
    team/jrose/bridge_projects/main/asterisk.c
    team/jrose/bridge_projects/main/bridging.c
    team/jrose/bridge_projects/main/manager.c
    team/jrose/bridge_projects/main/manager_channels.c
    team/jrose/bridge_projects/main/strings.c
    team/jrose/bridge_projects/res/parking/parking_manager.c

Propchange: team/jrose/bridge_projects/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/jrose/bridge_projects/
------------------------------------------------------------------------------
--- branch-11-blocked (original)
+++ branch-11-blocked Thu Apr 11 18:28:44 2013
@@ -1,1 +1,1 @@
-/branches/11:373240,375247,375702
+/branches/11:373240,375247,375702,385356

Propchange: team/jrose/bridge_projects/
------------------------------------------------------------------------------
--- bridge_construction-integrated (original)
+++ bridge_construction-integrated Thu Apr 11 18:28:44 2013
@@ -1,1 +1,1 @@
-/trunk:1-385316
+/trunk:1-385357

Propchange: team/jrose/bridge_projects/
------------------------------------------------------------------------------
--- bridge_projects-integrated (original)
+++ bridge_projects-integrated Thu Apr 11 18:28:44 2013
@@ -1,1 +1,1 @@
-/team/group/bridge_construction:1-385318
+/team/group/bridge_construction:1-385390

Modified: team/jrose/bridge_projects/include/asterisk/manager.h
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/include/asterisk/manager.h?view=diff&rev=385392&r1=385391&r2=385392
==============================================================================
--- team/jrose/bridge_projects/include/asterisk/manager.h (original)
+++ team/jrose/bridge_projects/include/asterisk/manager.h Thu Apr 11 18:28:44 2013
@@ -317,6 +317,16 @@
 struct ast_datastore *astman_datastore_find(struct mansession *s, const struct ast_datastore_info *info, const char *uid);
 
 struct ast_channel_snapshot;
+
+/*! \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 Generate the AMI message body from a channel snapshot
@@ -330,7 +340,30 @@
  * \retval NULL on error
  * \retval ast_str* on success (must be ast_freed by caller)
  */
-struct ast_str *ast_manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot, const char *suffix);
+struct ast_str *ast_manager_build_channel_state_string_suffix(const struct ast_channel_snapshot *snapshot, const char *suffix);
+
+/*!
+ * \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.
@@ -340,4 +373,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/jrose/bridge_projects/include/asterisk/strings.h
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/include/asterisk/strings.h?view=diff&rev=385392&r1=385391&r2=385392
==============================================================================
--- team/jrose/bridge_projects/include/asterisk/strings.h (original)
+++ team/jrose/bridge_projects/include/asterisk/strings.h Thu Apr 11 18:28:44 2013
@@ -29,6 +29,7 @@
 
 #include "asterisk/utils.h"
 #include "asterisk/threadstorage.h"
+#include "asterisk/astobj2.h"
 
 #if defined(DEBUG_OPAQUE)
 #define __AST_STR_USED used2
@@ -1013,4 +1014,26 @@
 	return abs(hash);
 }
 
+/*!
+ * \since 12
+ * \brief Allocates a hash container for bare strings
+ *
+ * \param buckets The number of buckets to use for the hash container
+ *
+ * \retval AO2 container for strings
+ * \retval NULL if allocation failed
+ */
+struct ao2_container *ast_str_container_alloc(int buckets);
+
+/*!
+ * \since 12
+ * \brief Adds a string to a string container allocated by ast_str_container_alloc
+ *
+ * \param str_container The container to which to add a string
+ * \param add The string to add to the container
+ *
+ * \retval zero on success
+ * \retval non-zero if the operation failed
+ */
+int ast_str_container_add(struct ao2_container *str_container, const char *add);
 #endif /* _ASTERISK_STRINGS_H */

Modified: team/jrose/bridge_projects/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/main/asterisk.c?view=diff&rev=385392&r1=385391&r2=385392
==============================================================================
--- team/jrose/bridge_projects/main/asterisk.c (original)
+++ team/jrose/bridge_projects/main/asterisk.c Thu Apr 11 18:28:44 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/jrose/bridge_projects/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/main/bridging.c?view=diff&rev=385392&r1=385391&r2=385392
==============================================================================
--- team/jrose/bridge_projects/main/bridging.c (original)
+++ team/jrose/bridge_projects/main/bridging.c Thu Apr 11 18:28:44 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);
@@ -4113,10 +4132,16 @@
 {
 	ao2_cleanup(bridge_manager);
 	bridge_manager = NULL;
+	ast_stasis_bridging_shutdown();
 }
 
 int ast_bridging_init(void)
 {
+	if (ast_stasis_bridging_init()) {
+		bridge_shutdown();
+		return -1;
+	}
+
 	bridge_manager = bridge_manager_create();
 	if (!bridge_manager) {
 		return -1;

Modified: team/jrose/bridge_projects/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/main/manager.c?view=diff&rev=385392&r1=385391&r2=385392
==============================================================================
--- team/jrose/bridge_projects/main/manager.c (original)
+++ team/jrose/bridge_projects/main/manager.c Thu Apr 11 18:28:44 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/jrose/bridge_projects/main/manager_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/main/manager_channels.c?view=diff&rev=385392&r1=385391&r2=385392
==============================================================================
--- team/jrose/bridge_projects/main/manager_channels.c (original)
+++ team/jrose/bridge_projects/main/manager_channels.c Thu Apr 11 18:28:44 2013
@@ -232,7 +232,7 @@
 	</managerEvent>
  ***/
 
-struct ast_str *ast_manager_build_channel_state_string(
+struct ast_str *ast_manager_build_channel_state_string_suffix(
 	const struct ast_channel_snapshot *snapshot,
 	const char *suffix)
 {
@@ -287,78 +287,29 @@
 	return out;
 }
 
-/*! \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.
+ * \brief Generate the AMI message body from a channel snapshot
+ * \internal
+ *
+ * \param snapshot the channel snapshot for which to generate an AMI message
+ *                 body
+ *
+ * \retval NULL on error
+ * \retval ast_str* on success (must be ast_freed by caller)
  */
-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", ""
+static struct ast_str *manager_build_channel_state_string(
+		const struct ast_channel_snapshot *snapshot)
+{
+	return ast_manager_build_channel_state_string_suffix(snapshot, "");
+}
 
 /*! \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)
 {
@@ -375,7 +326,7 @@
 	 */
 
 	if (!old_snapshot) {
-		return snapshot_manager_event_create(
+		return ast_manager_event_blob_create(
 			EVENT_FLAG_CALL, "Newchannel", NO_EXTRA_FIELDS);
 	}
 
@@ -383,7 +334,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",
@@ -392,7 +343,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);
 	}
 
@@ -428,7 +379,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)
 {
@@ -447,7 +398,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"
@@ -474,7 +425,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)
 {
@@ -487,14 +438,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
@@ -519,9 +470,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;
@@ -530,7 +481,7 @@
 		/* If we haven't already, build the channel event string */
 		if (!channel_event_string) {
 			channel_event_string =
-				ast_manager_build_channel_state_string(new_snapshot, NULL);
+				manager_build_channel_state_string(new_snapshot);
 			if (!channel_event_string) {
 				return;
 			}
@@ -549,7 +500,7 @@
 	const char *value = ast_json_string_get(ast_json_object_get(obj->blob, "value"));
 
 	if (obj->snapshot) {
-		channel_event_string = ast_manager_build_channel_state_string(obj->snapshot, NULL);
+		channel_event_string = manager_build_channel_state_string(obj->snapshot);
 	} else {
 		channel_event_string = ast_str_create(35);
 		ast_str_set(&channel_event_string, 0,
@@ -591,7 +542,7 @@
 
 	eventname = ast_json_string_get(ast_json_object_get(obj->blob, "eventname"));
 	body = ast_json_string_get(ast_json_object_get(obj->blob, "body"));
-	channel_event_string = ast_manager_build_channel_state_string(obj->snapshot, NULL);
+	channel_event_string = manager_build_channel_state_string(obj->snapshot);
 
 	if (!channel_event_string) {
 		return;
@@ -631,7 +582,7 @@
 		return;
 	}
 
-	channel_event_string = ast_manager_build_channel_state_string(obj->snapshot, NULL);
+	channel_event_string = manager_build_channel_state_string(obj->snapshot);
 	if (!channel_event_string) {
 		return;
 	}
@@ -697,13 +648,13 @@
 
 	/* Peer is required - otherwise, who are we dialing? */
 	ast_assert(peer != NULL);
-	peer_event_string = ast_manager_build_channel_state_string(peer, "Dest");
+	peer_event_string = ast_manager_build_channel_state_string_suffix(peer, "Dest");
 	if (!peer_event_string) {
 		return;
 	}
 
 	if (caller) {
-		caller_event_string = ast_manager_build_channel_state_string(caller, NULL);
+		caller_event_string = manager_build_channel_state_string(caller);
 		if (!caller_event_string) {
 			return;
 		}

Modified: team/jrose/bridge_projects/main/strings.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/main/strings.c?view=diff&rev=385392&r1=385391&r2=385392
==============================================================================
--- team/jrose/bridge_projects/main/strings.c (original)
+++ team/jrose/bridge_projects/main/strings.c Thu Apr 11 18:28:44 2013
@@ -160,3 +160,30 @@
 	return (*buf)->__AST_STR_STR;
 }
 
+static int str_hash(const void *obj, const int flags)
+{
+	return ast_str_hash(obj);
+}
+
+static int str_cmp(void *lhs, void *rhs, int flags)
+{
+	return strcmp(lhs, rhs) ? 0 : CMP_MATCH;
+}
+
+struct ao2_container *ast_str_container_alloc(int buckets)
+{
+	return ao2_container_alloc(buckets, str_hash, str_cmp);
+}
+
+int ast_str_container_add(struct ao2_container *str_container, const char *add)
+{
+	RAII_VAR(char *, ao2_add, ao2_alloc(strlen(add) + 1, NULL), ao2_cleanup);
+
+	if (!ao2_add) {
+		return -1;
+	}
+
+	/* safe strcpy */
+	strcpy(ao2_add, add);
+	return ao2_link(str_container, ao2_add);
+}

Modified: team/jrose/bridge_projects/res/parking/parking_manager.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/bridge_projects/res/parking/parking_manager.c?view=diff&rev=385392&r1=385391&r2=385392
==============================================================================
--- team/jrose/bridge_projects/res/parking/parking_manager.c (original)
+++ team/jrose/bridge_projects/res/parking/parking_manager.c Thu Apr 11 18:28:44 2013
@@ -104,8 +104,8 @@
 		return NULL;
 	}
 
-	parkee_string = ast_manager_build_channel_state_string(payload->parkee, "Parkee");
-	parker_string = ast_manager_build_channel_state_string(payload->parker, "Parker");
+	parkee_string = ast_manager_build_channel_state_string_suffix(payload->parkee, "Parkee");
+	parker_string = ast_manager_build_channel_state_string_suffix(payload->parker, "Parker");
 
 	res = ast_str_set(&out, 0,
 		"%s" /* parkee channel state */




More information about the asterisk-commits mailing list