Fix documentation replication issues
[asterisk/asterisk.git] / apps / confbridge / confbridge_manager.c
index 56fedb9..e6e859f 100644 (file)
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/channel.h"
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "asterisk/channel.h"
-#include "asterisk/bridging.h"
+#include "asterisk/bridge.h"
 #include "asterisk/stasis.h"
 #include "asterisk/stasis_channels.h"
 #include "asterisk/stasis.h"
 #include "asterisk/stasis_channels.h"
-#include "asterisk/stasis_bridging.h"
+#include "asterisk/stasis_bridges.h"
 #include "asterisk/manager.h"
 #include "asterisk/stasis_message_router.h"
 #include "include/confbridge.h"
 #include "asterisk/manager.h"
 #include "asterisk/stasis_message_router.h"
 #include "include/confbridge.h"
@@ -44,7 +44,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='BridgeCreate']/managerEventInstance/syntax/parameter)" />
+                               <bridge_snapshot/>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">ConfbridgeEnd</ref>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">ConfbridgeEnd</ref>
@@ -59,7 +59,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='BridgeCreate']/managerEventInstance/syntax/parameter)" />
+                               <bridge_snapshot/>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">ConfbridgeStart</ref>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">ConfbridgeStart</ref>
@@ -74,8 +74,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='BridgeCreate']/managerEventInstance/syntax/parameter)" />
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <bridge_snapshot/>
+                               <channel_snapshot/>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">ConfbridgeLeave</ref>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">ConfbridgeLeave</ref>
@@ -90,8 +90,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='BridgeCreate']/managerEventInstance/syntax/parameter)" />
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <bridge_snapshot/>
+                               <channel_snapshot/>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">ConfbridgeJoin</ref>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">ConfbridgeJoin</ref>
@@ -106,7 +106,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='BridgeCreate']/managerEventInstance/syntax/parameter)" />
+                               <bridge_snapshot/>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">ConfbridgeStopRecord</ref>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">ConfbridgeStopRecord</ref>
@@ -121,7 +121,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='BridgeCreate']/managerEventInstance/syntax/parameter)" />
+                               <bridge_snapshot/>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">ConfbridgeRecord</ref>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">ConfbridgeRecord</ref>
@@ -136,8 +136,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='BridgeCreate']/managerEventInstance/syntax/parameter)" />
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <bridge_snapshot/>
+                               <channel_snapshot/>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">ConfbridgeUnmute</ref>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">ConfbridgeUnmute</ref>
@@ -152,8 +152,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='BridgeCreate']/managerEventInstance/syntax/parameter)" />
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <bridge_snapshot/>
+                               <channel_snapshot/>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">ConfbridgeMute</ref>
                        </syntax>
                        <see-also>
                                <ref type="managerEvent">ConfbridgeMute</ref>
@@ -161,7 +161,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                        </see-also>
                </managerEventInstance>
        </managerEvent>
                        </see-also>
                </managerEventInstance>
        </managerEvent>
-
        <managerEvent language="en_US" name="ConfbridgeTalking">
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when a confbridge participant unmutes.</synopsis>
        <managerEvent language="en_US" name="ConfbridgeTalking">
                <managerEventInstance class="EVENT_FLAG_CALL">
                        <synopsis>Raised when a confbridge participant unmutes.</synopsis>
@@ -169,8 +168,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
                                <parameter name="Conference">
                                        <para>The name of the Confbridge conference.</para>
                                </parameter>
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='BridgeCreate']/managerEventInstance/syntax/parameter)" />
-                               <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+                               <bridge_snapshot/>
+                               <channel_snapshot/>
                                <parameter name="TalkingStatus">
                                        <enumlist>
                                                <enum name="on"/>
                                <parameter name="TalkingStatus">
                                        <enumlist>
                                                <enum name="on"/>
@@ -188,79 +187,27 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 static struct stasis_message_router *bridge_state_router;
 static struct stasis_message_router *channel_state_router;
 
 static struct stasis_message_router *bridge_state_router;
 static struct stasis_message_router *channel_state_router;
 
-static void append_event_header(struct ast_str **fields_string,
-                                       const char *header, const char *value)
-{
-       struct ast_str *working_str = *fields_string;
-
-       if (!working_str) {
-               working_str = ast_str_create(128);
-               if (!working_str) {
-                       return;
-               }
-               *fields_string = working_str;
-       }
-
-       ast_str_append(&working_str, 0,
-               "%s: %s\r\n",
-               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);
 {
        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 *, channel_text, NULL, ast_free);
        const char *conference_name;
        RAII_VAR(struct ast_str *, bridge_text, NULL, 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;
-       }
+       ast_assert(blob != NULL);
+       ast_assert(event != NULL);
 
 
-       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 {
+       bridge_text = ast_manager_build_bridge_state_string(blob->bridge, "");
+       if (!bridge_text) {
                return;
        }
 
        conference_name = ast_json_string_get(ast_json_object_get(blob->blob, "conference"));
                return;
        }
 
        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);
        }
        if (blob->channel) {
                channel_text = ast_manager_build_channel_state_string(blob->channel);
        }
@@ -272,20 +219,105 @@ static void stasis_confbridge_cb(void *data, struct stasis_subscription *sub,
                "%s",
                conference_name,
                ast_str_buffer(bridge_text),
                "%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 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 struct stasis_message_type *confbridge_msg_type;
+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;
+       }
+
+       ast_str_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) {
 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);
 
        if (bridge_state_router) {
                stasis_message_router_unsubscribe(bridge_state_router);
@@ -300,27 +332,89 @@ void manager_confbridge_shutdown(void) {
 
 int manager_confbridge_init(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(
 
        bridge_state_router = stasis_message_router_create(
-               stasis_caching_get_topic(ast_bridge_topic_all_cached()));
+               ast_bridge_topic_all_cached());
 
        if (!bridge_state_router) {
                return -1;
        }
 
        if (stasis_message_router_add(bridge_state_router,
 
        if (!bridge_state_router) {
                return -1;
        }
 
        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;
        }
 
        channel_state_router = stasis_message_router_create(
                manager_confbridge_shutdown();
                return -1;
        }
 
        channel_state_router = stasis_message_router_create(
-               stasis_caching_get_topic(ast_channel_topic_all_cached()));
+               ast_channel_topic_all_cached());
 
        if (!channel_state_router) {
                manager_confbridge_shutdown();
 
        if (!channel_state_router) {
                manager_confbridge_shutdown();
@@ -328,9 +422,65 @@ int manager_confbridge_init(void)
        }
 
        if (stasis_message_router_add(channel_state_router,
        }
 
        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;
        }
                manager_confbridge_shutdown();
                return -1;
        }