Remove remnant of snapshot blob JSON types
authorKinsey Moore <kmoore@digium.com>
Fri, 31 May 2013 12:41:10 +0000 (12:41 +0000)
committerKinsey Moore <kmoore@digium.com>
Fri, 31 May 2013 12:41:10 +0000 (12:41 +0000)
Remove usage of the once-mandatory snapshot blob type field, refactor
confbridge stasis messages accordingly, and remove
ast_bridge_blob_json_type().

Review: https://reviewboard.asterisk.org/r/2575/

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@390250 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_confbridge.c
apps/confbridge/confbridge_manager.c
apps/confbridge/include/confbridge.h
include/asterisk/stasis_bridging.h
main/stasis_bridging.c

index d52c882..96ef124 100644 (file)
@@ -415,13 +415,12 @@ const char *conf_get_sound(enum conf_sounds sound, struct bridge_profile_sounds
        return "";
 }
 
-static void send_conf_stasis(struct confbridge_conference *conference, struct ast_channel *chan, const char *type, struct ast_json *extras, int channel_topic)
+static void send_conf_stasis(struct confbridge_conference *conference, struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *extras, int channel_topic)
 {
        RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
        RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
 
-       json_object = ast_json_pack("{s: s, s: s}",
-               "type", type,
+       json_object = ast_json_pack("{s: s}",
                "conference", conference->name);
 
        if (!json_object) {
@@ -432,10 +431,10 @@ static void send_conf_stasis(struct confbridge_conference *conference, struct as
                ast_json_object_update(json_object, extras);
        }
 
-       msg = ast_bridge_blob_create(confbridge_message_type(),
-                                        conference->bridge,
-                                        chan,
-                                        json_object);
+       msg = ast_bridge_blob_create(type,
+               conference->bridge,
+               chan,
+               json_object);
        if (!msg) {
                return;
        }
@@ -450,42 +449,42 @@ static void send_conf_stasis(struct confbridge_conference *conference, struct as
 
 static void send_conf_start_event(struct confbridge_conference *conference)
 {
-       send_conf_stasis(conference, NULL, "confbridge_start", NULL, 0);
+       send_conf_stasis(conference, NULL, confbridge_start_type(), NULL, 0);
 }
 
 static void send_conf_end_event(struct confbridge_conference *conference)
 {
-       send_conf_stasis(conference, NULL, "confbridge_end", NULL, 0);
+       send_conf_stasis(conference, NULL, confbridge_end_type(), NULL, 0);
 }
 
 static void send_join_event(struct ast_channel *chan, struct confbridge_conference *conference)
 {
-       send_conf_stasis(conference, chan, "confbridge_join", NULL, 0);
+       send_conf_stasis(conference, chan, confbridge_join_type(), NULL, 0);
 }
 
 static void send_leave_event(struct ast_channel *chan, struct confbridge_conference *conference)
 {
-       send_conf_stasis(conference, chan, "confbridge_leave", NULL, 0);
+       send_conf_stasis(conference, chan, confbridge_leave_type(), NULL, 0);
 }
 
 static void send_start_record_event(struct confbridge_conference *conference)
 {
-       send_conf_stasis(conference, NULL, "confbridge_record", NULL, 0);
+       send_conf_stasis(conference, NULL, confbridge_start_record_type(), NULL, 0);
 }
 
 static void send_stop_record_event(struct confbridge_conference *conference)
 {
-       send_conf_stasis(conference, NULL, "confbridge_stop_record", NULL, 0);
+       send_conf_stasis(conference, NULL, confbridge_stop_record_type(), NULL, 0);
 }
 
 static void send_mute_event(struct ast_channel *chan, struct confbridge_conference *conference)
 {
-       send_conf_stasis(conference, chan, "confbridge_mute", NULL, 1);
+       send_conf_stasis(conference, chan, confbridge_mute_type(), NULL, 1);
 }
 
 static void send_unmute_event(struct ast_channel *chan, struct confbridge_conference *conference)
 {
-       send_conf_stasis(conference, chan, "confbridge_unmute", NULL, 1);
+       send_conf_stasis(conference, chan, confbridge_unmute_type(), NULL, 1);
 }
 
 static void set_rec_filename(struct confbridge_conference *conference, struct ast_str **filename, int is_new)
@@ -1420,7 +1419,7 @@ static void conf_handle_talker_cb(struct ast_bridge_channel *bridge_channel, voi
                return;
        }
 
-       send_conf_stasis(conference, bridge_channel->chan, "confbridge_talking", talking_extras, 0);
+       send_conf_stasis(conference, bridge_channel->chan, confbridge_talking_type(), talking_extras, 0);
        ast_json_unref(talking_extras);
 }
 
index 56fedb9..e99ddda 100644 (file)
@@ -206,61 +206,24 @@ static void append_event_header(struct ast_str **fields_string,
                header, value);
 }
 
-static void stasis_confbridge_cb(void *data, struct stasis_subscription *sub,
-                                       struct stasis_topic *topic,
-                                       struct stasis_message *message)
+static void confbridge_publish_manager_event(
+       struct stasis_message *message,
+       const char *event,
+       struct ast_str *extra_text)
 {
        struct ast_bridge_blob *blob = stasis_message_data(message);
-       const char *type = ast_bridge_blob_json_type(blob);
        const char *conference_name;
-       RAII_VAR(struct ast_str *, bridge_text, NULL, ast_free);
+       RAII_VAR(struct ast_str *, bridge_text,
+               ast_manager_build_bridge_state_string(blob->bridge, ""),
+               ast_free);
        RAII_VAR(struct ast_str *, channel_text, NULL, ast_free);
-       RAII_VAR(struct ast_str *, extra_text, NULL, ast_free);
-       char *event;
-
-       if (!blob || !type) {
-               ast_assert(0);
-               return;
-       }
-
-       if (!strcmp("confbridge_start", type)) {
-               event = "ConfbridgeStart";
-       } else if (!strcmp("confbridge_end", type)) {
-               event = "ConfbridgeEnd";
-       } else if (!strcmp("confbridge_leave", type)) {
-               event = "ConfbridgeLeave";
-       } else if (!strcmp("confbridge_join", type)) {
-               event = "ConfbridgeJoin";
-       } else if (!strcmp("confbridge_record", type)) {
-               event = "ConfbridgeRecord";
-       } else if (!strcmp("confbridge_stop_record", type)) {
-               event = "ConfbridgeStopRecord";
-       } else if (!strcmp("confbridge_mute", type)) {
-               event = "ConfbridgeMute";
-       } else if (!strcmp("confbridge_unmute", type)) {
-               event = "ConfbridgeUnmute";
-       } else if (!strcmp("confbridge_talking", type)) {
-               const char *talking_status = ast_json_string_get(ast_json_object_get(blob->blob, "talking_status"));
-               event = "ConfbridgeTalking";
-
-               if (!talking_status) {
-                       return;
-               }
 
-               append_event_header(&extra_text, "TalkingStatus", talking_status);
-
-       } else {
-               return;
-       }
+       ast_assert(blob != NULL);
+       ast_assert(event != NULL);
 
        conference_name = ast_json_string_get(ast_json_object_get(blob->blob, "conference"));
+       ast_assert(conference_name != NULL);
 
-       if (!conference_name) {
-               ast_assert(0);
-               return;
-       }
-
-       bridge_text = ast_manager_build_bridge_state_string(blob->bridge, "");
        if (blob->channel) {
                channel_text = ast_manager_build_channel_state_string(blob->channel);
        }
@@ -272,20 +235,105 @@ static void stasis_confbridge_cb(void *data, struct stasis_subscription *sub,
                "%s",
                conference_name,
                ast_str_buffer(bridge_text),
-               channel_text ? ast_str_buffer(channel_text) : "",
-               extra_text ? ast_str_buffer(extra_text) : "");
+               S_COR(channel_text, ast_str_buffer(channel_text), ""),
+               S_COR(extra_text, ast_str_buffer(extra_text), ""));
+}
+
+static void confbridge_start_cb(void *data, struct stasis_subscription *sub,
+       struct stasis_topic *topic,
+       struct stasis_message *message)
+{
+       confbridge_publish_manager_event(message, "ConfbridgeStart", NULL);
+}
+
+static void confbridge_end_cb(void *data, struct stasis_subscription *sub,
+       struct stasis_topic *topic,
+       struct stasis_message *message)
+{
+       confbridge_publish_manager_event(message, "ConfbridgeEnd", NULL);
+}
+
+static void confbridge_leave_cb(void *data, struct stasis_subscription *sub,
+       struct stasis_topic *topic,
+       struct stasis_message *message)
+{
+       confbridge_publish_manager_event(message, "ConfbridgeLeave", NULL);
+}
+
+static void confbridge_join_cb(void *data, struct stasis_subscription *sub,
+       struct stasis_topic *topic,
+       struct stasis_message *message)
+{
+       confbridge_publish_manager_event(message, "ConfbridgeJoin", NULL);
+}
+
+static void confbridge_start_record_cb(void *data, struct stasis_subscription *sub,
+       struct stasis_topic *topic,
+       struct stasis_message *message)
+{
+       confbridge_publish_manager_event(message, "ConfbridgeRecord", NULL);
 }
 
-static struct stasis_message_type *confbridge_msg_type;
+static void confbridge_stop_record_cb(void *data, struct stasis_subscription *sub,
+       struct stasis_topic *topic,
+       struct stasis_message *message)
+{
+       confbridge_publish_manager_event(message, "ConfbridgeStopRecord", NULL);
+}
+
+static void confbridge_mute_cb(void *data, struct stasis_subscription *sub,
+       struct stasis_topic *topic,
+       struct stasis_message *message)
+{
+       confbridge_publish_manager_event(message, "ConfbridgeMute", NULL);
+}
+
+static void confbridge_unmute_cb(void *data, struct stasis_subscription *sub,
+       struct stasis_topic *topic,
+       struct stasis_message *message)
+{
+       confbridge_publish_manager_event(message, "ConfbridgeUnmute", NULL);
+}
 
-struct stasis_message_type *confbridge_message_type(void)
+static void confbridge_talking_cb(void *data, struct stasis_subscription *sub,
+       struct stasis_topic *topic,
+       struct stasis_message *message)
 {
-       return confbridge_msg_type;
+       RAII_VAR(struct ast_str *, extra_text, NULL, ast_free);
+       struct ast_bridge_blob *blob = stasis_message_data(message);
+       const char *talking_status = ast_json_string_get(ast_json_object_get(blob->blob, "talking_status"));
+       if (!talking_status) {
+               return;
+       }
+
+       append_event_header(&extra_text, "TalkingStatus", talking_status);
+       if (!extra_text) {
+               return;
+       }
+
+       confbridge_publish_manager_event(message, "ConfbridgeTalking", extra_text);
 }
 
+STASIS_MESSAGE_TYPE_DEFN(confbridge_start_type);
+STASIS_MESSAGE_TYPE_DEFN(confbridge_end_type);
+STASIS_MESSAGE_TYPE_DEFN(confbridge_join_type);
+STASIS_MESSAGE_TYPE_DEFN(confbridge_leave_type);
+STASIS_MESSAGE_TYPE_DEFN(confbridge_start_record_type);
+STASIS_MESSAGE_TYPE_DEFN(confbridge_stop_record_type);
+STASIS_MESSAGE_TYPE_DEFN(confbridge_mute_type);
+STASIS_MESSAGE_TYPE_DEFN(confbridge_unmute_type);
+STASIS_MESSAGE_TYPE_DEFN(confbridge_talking_type);
+
 void manager_confbridge_shutdown(void) {
-       ao2_cleanup(confbridge_msg_type);
-       confbridge_msg_type = NULL;
+       STASIS_MESSAGE_TYPE_CLEANUP(confbridge_start_type);
+       STASIS_MESSAGE_TYPE_CLEANUP(confbridge_end_type);
+       STASIS_MESSAGE_TYPE_CLEANUP(confbridge_join_type);
+       STASIS_MESSAGE_TYPE_CLEANUP(confbridge_leave_type);
+       STASIS_MESSAGE_TYPE_CLEANUP(confbridge_start_record_type);
+       STASIS_MESSAGE_TYPE_CLEANUP(confbridge_stop_record_type);
+       STASIS_MESSAGE_TYPE_CLEANUP(confbridge_mute_type);
+       STASIS_MESSAGE_TYPE_CLEANUP(confbridge_unmute_type);
+       STASIS_MESSAGE_TYPE_CLEANUP(confbridge_talking_type);
 
        if (bridge_state_router) {
                stasis_message_router_unsubscribe(bridge_state_router);
@@ -300,9 +348,15 @@ void manager_confbridge_shutdown(void) {
 
 int manager_confbridge_init(void)
 {
-       if (!(confbridge_msg_type = stasis_message_type_create("confbridge"))) {
-               return -1;
-       }
+       STASIS_MESSAGE_TYPE_INIT(confbridge_start_type);
+       STASIS_MESSAGE_TYPE_INIT(confbridge_end_type);
+       STASIS_MESSAGE_TYPE_INIT(confbridge_join_type);
+       STASIS_MESSAGE_TYPE_INIT(confbridge_leave_type);
+       STASIS_MESSAGE_TYPE_INIT(confbridge_start_record_type);
+       STASIS_MESSAGE_TYPE_INIT(confbridge_stop_record_type);
+       STASIS_MESSAGE_TYPE_INIT(confbridge_mute_type);
+       STASIS_MESSAGE_TYPE_INIT(confbridge_unmute_type);
+       STASIS_MESSAGE_TYPE_INIT(confbridge_talking_type);
 
        bridge_state_router = stasis_message_router_create(
                stasis_caching_get_topic(ast_bridge_topic_all_cached()));
@@ -312,9 +366,65 @@ int manager_confbridge_init(void)
        }
 
        if (stasis_message_router_add(bridge_state_router,
-                                        confbridge_message_type(),
-                                        stasis_confbridge_cb,
-                                        NULL)) {
+                       confbridge_start_type(),
+                       confbridge_start_cb,
+                       NULL)) {
+               manager_confbridge_shutdown();
+               return -1;
+       }
+       if (stasis_message_router_add(bridge_state_router,
+                       confbridge_end_type(),
+                       confbridge_end_cb,
+                       NULL)) {
+               manager_confbridge_shutdown();
+               return -1;
+       }
+       if (stasis_message_router_add(bridge_state_router,
+                       confbridge_join_type(),
+                       confbridge_join_cb,
+                       NULL)) {
+               manager_confbridge_shutdown();
+               return -1;
+       }
+       if (stasis_message_router_add(bridge_state_router,
+                       confbridge_leave_type(),
+                       confbridge_leave_cb,
+                       NULL)) {
+               manager_confbridge_shutdown();
+               return -1;
+       }
+       if (stasis_message_router_add(bridge_state_router,
+                       confbridge_start_record_type(),
+                       confbridge_start_record_cb,
+                       NULL)) {
+               manager_confbridge_shutdown();
+               return -1;
+       }
+       if (stasis_message_router_add(bridge_state_router,
+                       confbridge_stop_record_type(),
+                       confbridge_stop_record_cb,
+                       NULL)) {
+               manager_confbridge_shutdown();
+               return -1;
+       }
+       if (stasis_message_router_add(bridge_state_router,
+                       confbridge_mute_type(),
+                       confbridge_mute_cb,
+                       NULL)) {
+               manager_confbridge_shutdown();
+               return -1;
+       }
+       if (stasis_message_router_add(bridge_state_router,
+                       confbridge_unmute_type(),
+                       confbridge_unmute_cb,
+                       NULL)) {
+               manager_confbridge_shutdown();
+               return -1;
+       }
+       if (stasis_message_router_add(bridge_state_router,
+                       confbridge_talking_type(),
+                       confbridge_talking_cb,
+                       NULL)) {
                manager_confbridge_shutdown();
                return -1;
        }
@@ -328,9 +438,65 @@ int manager_confbridge_init(void)
        }
 
        if (stasis_message_router_add(channel_state_router,
-                                        confbridge_message_type(),
-                                        stasis_confbridge_cb,
-                                        NULL)) {
+                       confbridge_start_type(),
+                       confbridge_start_cb,
+                       NULL)) {
+               manager_confbridge_shutdown();
+               return -1;
+       }
+       if (stasis_message_router_add(channel_state_router,
+                       confbridge_end_type(),
+                       confbridge_end_cb,
+                       NULL)) {
+               manager_confbridge_shutdown();
+               return -1;
+       }
+       if (stasis_message_router_add(channel_state_router,
+                       confbridge_join_type(),
+                       confbridge_join_cb,
+                       NULL)) {
+               manager_confbridge_shutdown();
+               return -1;
+       }
+       if (stasis_message_router_add(channel_state_router,
+                       confbridge_leave_type(),
+                       confbridge_leave_cb,
+                       NULL)) {
+               manager_confbridge_shutdown();
+               return -1;
+       }
+       if (stasis_message_router_add(channel_state_router,
+                       confbridge_start_record_type(),
+                       confbridge_start_record_cb,
+                       NULL)) {
+               manager_confbridge_shutdown();
+               return -1;
+       }
+       if (stasis_message_router_add(channel_state_router,
+                       confbridge_stop_record_type(),
+                       confbridge_stop_record_cb,
+                       NULL)) {
+               manager_confbridge_shutdown();
+               return -1;
+       }
+       if (stasis_message_router_add(channel_state_router,
+                       confbridge_mute_type(),
+                       confbridge_mute_cb,
+                       NULL)) {
+               manager_confbridge_shutdown();
+               return -1;
+       }
+       if (stasis_message_router_add(channel_state_router,
+                       confbridge_unmute_type(),
+                       confbridge_unmute_cb,
+                       NULL)) {
+               manager_confbridge_shutdown();
+               return -1;
+       }
+       if (stasis_message_router_add(channel_state_router,
+                       confbridge_talking_type(),
+                       confbridge_talking_cb,
+                       NULL)) {
                manager_confbridge_shutdown();
                return -1;
        }
index f062014..1af621d 100644 (file)
@@ -465,12 +465,84 @@ int conf_add_post_join_action(struct confbridge_user *user, int (*func)(struct c
 
 /*!
  * \since 12.0
- * \brief get the confbridge stasis message type
+ * \brief get the confbridge start stasis message type
  *
- * \retval stasis message type for confbridge messages if it's available
+ * \retval stasis message type for confbridge start messages if it's available
  * \retval NULL if it isn't
  */
-struct stasis_message_type *confbridge_message_type(void);
+struct stasis_message_type *confbridge_start_type(void);
+
+/*!
+ * \since 12.0
+ * \brief get the confbridge end stasis message type
+ *
+ * \retval stasis message type for confbridge end messages if it's available
+ * \retval NULL if it isn't
+ */
+struct stasis_message_type *confbridge_end_type(void);
+
+/*!
+ * \since 12.0
+ * \brief get the confbridge join stasis message type
+ *
+ * \retval stasis message type for confbridge join messages if it's available
+ * \retval NULL if it isn't
+ */
+struct stasis_message_type *confbridge_join_type(void);
+
+/*!
+ * \since 12.0
+ * \brief get the confbridge leave stasis message type
+ *
+ * \retval stasis message type for confbridge leave messages if it's available
+ * \retval NULL if it isn't
+ */
+struct stasis_message_type *confbridge_leave_type(void);
+
+/*!
+ * \since 12.0
+ * \brief get the confbridge start_record stasis message type
+ *
+ * \retval stasis message type for confbridge start_record messages if it's available
+ * \retval NULL if it isn't
+ */
+struct stasis_message_type *confbridge_start_record_type(void);
+
+/*!
+ * \since 12.0
+ * \brief get the confbridge stop_record stasis message type
+ *
+ * \retval stasis message type for confbridge stop_record messages if it's available
+ * \retval NULL if it isn't
+ */
+struct stasis_message_type *confbridge_stop_record_type(void);
+
+/*!
+ * \since 12.0
+ * \brief get the confbridge mute stasis message type
+ *
+ * \retval stasis message type for confbridge mute messages if it's available
+ * \retval NULL if it isn't
+ */
+struct stasis_message_type *confbridge_mute_type(void);
+
+/*!
+ * \since 12.0
+ * \brief get the confbridge unmute stasis message type
+ *
+ * \retval stasis message type for confbridge unmute messages if it's available
+ * \retval NULL if it isn't
+ */
+struct stasis_message_type *confbridge_unmute_type(void);
+
+/*!
+ * \since 12.0
+ * \brief get the confbridge talking stasis message type
+ *
+ * \retval stasis message type for confbridge talking messages if it's available
+ * \retval NULL if it isn't
+ */
+struct stasis_message_type *confbridge_talking_type(void);
 
 /*!
  * \since 12.0
index 94bc4bc..5b8ff6f 100644 (file)
@@ -183,19 +183,6 @@ struct stasis_message *ast_bridge_blob_create(struct stasis_message_type *type,
 
 /*!
  * \since 12
- * \brief Extracts the type field from a \ref ast_bridge_blob.
- *
- * Returned \c char* is still owned by \a obj
- *
- * \param obj Channel blob object.
- *
- * \retval Type field value from the blob.
- * \retval \c NULL on error.
- */
-const char *ast_bridge_blob_json_type(struct ast_bridge_blob *obj);
-
-/*!
- * \since 12
  * \brief Publish a bridge channel enter event
  *
  * \param bridge The bridge a channel entered
index 56c1dfb..d181c40 100644 (file)
@@ -262,15 +262,6 @@ struct stasis_message *ast_bridge_blob_create(
        return msg;
 }
 
-const char *ast_bridge_blob_json_type(struct ast_bridge_blob *obj)
-{
-       if (obj == NULL) {
-               return NULL;
-       }
-
-       return ast_json_string_get(ast_json_object_get(obj->blob, "type"));
-}
-
 void ast_bridge_publish_enter(struct ast_bridge *bridge, struct ast_channel *chan)
 {
        RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);