[asterisk-commits] kmoore: branch kmoore/channel_event_refactor r391428 - in /team/kmoore/channe...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jun 11 13:41:54 CDT 2013
Author: kmoore
Date: Tue Jun 11 13:41:52 2013
New Revision: 391428
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=391428
Log:
Refactor SessionTimeout AMI event
Modified:
team/kmoore/channel_event_refactor/apps/app_meetme.c
team/kmoore/channel_event_refactor/apps/app_queue.c
team/kmoore/channel_event_refactor/channels/chan_sip.c
team/kmoore/channel_event_refactor/include/asterisk/stasis.h
team/kmoore/channel_event_refactor/res/res_agi.c
Modified: team/kmoore/channel_event_refactor/apps/app_meetme.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel_event_refactor/apps/app_meetme.c?view=diff&rev=391428&r1=391427&r2=391428
==============================================================================
--- team/kmoore/channel_event_refactor/apps/app_meetme.c (original)
+++ team/kmoore/channel_event_refactor/apps/app_meetme.c Tue Jun 11 13:41:52 2013
@@ -1117,75 +1117,15 @@
15,
};
-/*!
- * \internal
- * \brief accessor for join message type
- * \since 12.0.0
- *
- * \retval pointer to the stasis message type
- * \retval NULL if not initialized
- */
-static struct stasis_message_type *meetme_join_type(void);
-
-/*!
- * \internal
- * \brief accessor for leave message type
- * \since 12.0.0
- *
- * \retval pointer to the stasis message type
- * \retval NULL if not initialized
- */
-static struct stasis_message_type *meetme_leave_type(void);
-
-/*!
- * \internal
- * \brief accessor for end message type
- * \since 12.0.0
- *
- * \retval pointer to the stasis message type
- * \retval NULL if not initialized
- */
-static struct stasis_message_type *meetme_end_type(void);
-
-/*!
- * \internal
- * \brief accessor for mute message type
- * \since 12.0.0
- *
- * \retval pointer to the stasis message type
- * \retval NULL if not initialized
- */
-static struct stasis_message_type *meetme_mute_type(void);
-
-/*!
- * \internal
- * \brief accessor for talking message type
- * \since 12.0.0
- *
- * \retval pointer to the stasis message type
- * \retval NULL if not initialized
- */
-static struct stasis_message_type *meetme_talking_type(void);
-
-/*!
- * \internal
- * \brief accessor for talk request message type
- * \since 12.0.0
- *
- * \retval pointer to the stasis message type
- * \retval NULL if not initialized
- */
-static struct stasis_message_type *meetme_talk_request_type(void);
-
/* Routes the various meetme message types to the meetme stasis callback function to turn them into events */
static struct stasis_message_router *meetme_event_message_router;
-STASIS_MESSAGE_TYPE_DEFN(meetme_join_type);
-STASIS_MESSAGE_TYPE_DEFN(meetme_leave_type);
-STASIS_MESSAGE_TYPE_DEFN(meetme_end_type);
-STASIS_MESSAGE_TYPE_DEFN(meetme_mute_type);
-STASIS_MESSAGE_TYPE_DEFN(meetme_talking_type);
-STASIS_MESSAGE_TYPE_DEFN(meetme_talk_request_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(meetme_join_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(meetme_leave_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(meetme_end_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(meetme_mute_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(meetme_talking_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(meetme_talk_request_type);
static void meetme_stasis_cb(void *data, struct stasis_subscription *sub,
struct stasis_topic *topic, struct stasis_message *message);
Modified: team/kmoore/channel_event_refactor/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel_event_refactor/apps/app_queue.c?view=diff&rev=391428&r1=391427&r2=391428
==============================================================================
--- team/kmoore/channel_event_refactor/apps/app_queue.c (original)
+++ team/kmoore/channel_event_refactor/apps/app_queue.c Tue Jun 11 13:41:52 2013
@@ -1811,39 +1811,22 @@
new->opos = *pos;
}
-struct stasis_message_type *queue_caller_join_type(void);
-struct stasis_message_type *queue_caller_leave_type(void);
-struct stasis_message_type *queue_caller_abandon_type(void);
-
-struct stasis_message_type *queue_member_status_type(void);
-struct stasis_message_type *queue_member_added_type(void);
-struct stasis_message_type *queue_member_removed_type(void);
-struct stasis_message_type *queue_member_pause_type(void);
-struct stasis_message_type *queue_member_penalty_type(void);
-struct stasis_message_type *queue_member_ringinuse_type(void);
-
-struct stasis_message_type *queue_agent_called_type(void);
-struct stasis_message_type *queue_agent_connect_type(void);
-struct stasis_message_type *queue_agent_complete_type(void);
-struct stasis_message_type *queue_agent_dump_type(void);
-struct stasis_message_type *queue_agent_ringnoanswer_type(void);
-
-STASIS_MESSAGE_TYPE_DEFN(queue_caller_join_type);
-STASIS_MESSAGE_TYPE_DEFN(queue_caller_leave_type);
-STASIS_MESSAGE_TYPE_DEFN(queue_caller_abandon_type);
-
-STASIS_MESSAGE_TYPE_DEFN(queue_member_status_type);
-STASIS_MESSAGE_TYPE_DEFN(queue_member_added_type);
-STASIS_MESSAGE_TYPE_DEFN(queue_member_removed_type);
-STASIS_MESSAGE_TYPE_DEFN(queue_member_pause_type);
-STASIS_MESSAGE_TYPE_DEFN(queue_member_penalty_type);
-STASIS_MESSAGE_TYPE_DEFN(queue_member_ringinuse_type);
-
-STASIS_MESSAGE_TYPE_DEFN(queue_agent_called_type);
-STASIS_MESSAGE_TYPE_DEFN(queue_agent_connect_type);
-STASIS_MESSAGE_TYPE_DEFN(queue_agent_complete_type);
-STASIS_MESSAGE_TYPE_DEFN(queue_agent_dump_type);
-STASIS_MESSAGE_TYPE_DEFN(queue_agent_ringnoanswer_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_caller_join_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_caller_leave_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_caller_abandon_type);
+
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_member_status_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_member_added_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_member_removed_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_member_pause_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_member_penalty_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_member_ringinuse_type);
+
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_agent_called_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_agent_connect_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_agent_complete_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_agent_dump_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(queue_agent_ringnoanswer_type);
static void queue_channel_manager_event(void *data,
struct stasis_subscription *sub, struct stasis_topic *topic,
Modified: team/kmoore/channel_event_refactor/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel_event_refactor/channels/chan_sip.c?view=diff&rev=391428&r1=391427&r2=391428
==============================================================================
--- team/kmoore/channel_event_refactor/channels/chan_sip.c (original)
+++ team/kmoore/channel_event_refactor/channels/chan_sip.c Tue Jun 11 13:41:52 2013
@@ -296,6 +296,7 @@
#include "asterisk/app.h"
#include "asterisk/bridging.h"
#include "asterisk/stasis_endpoints.h"
+#include "asterisk/stasis_channels.h"
#include "asterisk/features_config.h"
/*** DOCUMENTATION
@@ -1043,6 +1044,11 @@
/*! \brief Global authentication container protection while adjusting the references. */
AST_MUTEX_DEFINE_STATIC(authl_lock);
+static struct ast_manager_event_blob *session_timeout_to_ami(struct stasis_message *msg);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(session_timeout_type,
+ .to_ami = session_timeout_to_ami,
+ );
+
/* --- Sockets and networking --------------*/
/*! \brief Main socket for UDP SIP communication.
@@ -28481,6 +28487,39 @@
return 0;
}
+static struct ast_manager_event_blob *session_timeout_to_ami(struct stasis_message *msg)
+{
+ RAII_VAR(struct ast_str *, channel_string, NULL, ast_free);
+ struct ast_channel_blob *obj = stasis_message_data(msg);
+ const char *source = ast_json_string_get(ast_json_object_get(obj->blob, "source"));
+
+ channel_string = ast_manager_build_channel_state_string(obj->snapshot);
+ if (!channel_string) {
+ return NULL;
+ }
+
+ return ast_manager_event_blob_create(EVENT_FLAG_CALL, "SessionTimeout",
+ "%s"
+ "Source: %s\r\n",
+ ast_str_buffer(channel_string), source);
+}
+
+/*! \brief Sends a session timeout channel blob used to produce SessionTimeout AMI messages */
+static void send_session_timeout(struct ast_channel *chan, const char *source)
+{
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+
+ ast_assert(chan != NULL);
+ ast_assert(source != NULL);
+
+ blob = ast_json_pack("{s: s}", "source", source);
+ if (!blob) {
+ return;
+ }
+
+ ast_channel_publish_blob(chan, session_timeout_type(), blob);
+}
+
/*!
* \brief helper function for the monitoring thread -- seems to be called with the assumption that the dialog is locked
*
@@ -28556,8 +28595,8 @@
}
ast_log(LOG_NOTICE, "Disconnecting call '%s' for lack of RTP activity in %ld seconds\n",
ast_channel_name(dialog->owner), (long) (t - dialog->lastrtprx));
- manager_event(EVENT_FLAG_CALL, "SessionTimeout", "Source: RTPTimeout\r\n"
- "Channel: %s\r\nUniqueid: %s\r\n", ast_channel_name(dialog->owner), ast_channel_uniqueid(dialog->owner));
+ send_session_timeout(dialog->owner, "RTPTimeout");
+
/* Issue a softhangup */
ast_softhangup_nolock(dialog->owner, AST_SOFTHANGUP_DEV);
ast_channel_unlock(dialog->owner);
@@ -28836,8 +28875,7 @@
sip_pvt_lock(p);
}
- manager_event(EVENT_FLAG_CALL, "SessionTimeout", "Source: SIPSessionTimer\r\n"
- "Channel: %s\r\nUniqueid: %s\r\n", ast_channel_name(p->owner), ast_channel_uniqueid(p->owner));
+ send_session_timeout(p->owner, "SIPSessionTimer");
ast_softhangup_nolock(p->owner, AST_SOFTHANGUP_DEV);
ast_channel_unlock(p->owner);
sip_pvt_unlock(p);
@@ -34088,6 +34126,10 @@
{
ast_verbose("SIP channel loading...\n");
+ if (STASIS_MESSAGE_TYPE_INIT(session_timeout_type)) {
+ return AST_MODULE_LOAD_FAILURE;
+ }
+
if (!(sip_tech.capabilities = ast_format_cap_alloc())) {
return AST_MODULE_LOAD_FAILURE;
}
@@ -34454,6 +34496,8 @@
ast_format_cap_destroy(sip_tech.capabilities);
sip_cfg.caps = ast_format_cap_destroy(sip_cfg.caps);
+ STASIS_MESSAGE_TYPE_CLEANUP(session_timeout_type);
+
return 0;
}
Modified: team/kmoore/channel_event_refactor/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel_event_refactor/include/asterisk/stasis.h?view=diff&rev=391428&r1=391427&r2=391428
==============================================================================
--- team/kmoore/channel_event_refactor/include/asterisk/stasis.h (original)
+++ team/kmoore/channel_event_refactor/include/asterisk/stasis.h Tue Jun 11 13:41:52 2013
@@ -722,6 +722,32 @@
}
/*!
+ * \brief Boiler-plate removing macro for defining local message types.
+ *
+ * \code
+ * STASIS_MESSAGE_TYPE_DEFN_LOCAL(ast_foo_type,
+ * .to_ami = foo_to_ami,
+ * .to_json = foo_to_json,
+ * );
+ * \endcode
+ *
+ * \param name Name of message type.
+ * \param ... Virtual table methods for messages of this type.
+ * \since 12
+ */
+#define STASIS_MESSAGE_TYPE_DEFN_LOCAL(name, ...) \
+ static struct stasis_message_vtable _priv_ ## name ## _v = { \
+ __VA_ARGS__ \
+ }; \
+ static struct stasis_message_type *_priv_ ## name; \
+ static struct stasis_message_type *name(void) { \
+ if (_priv_ ## name == NULL) { \
+ stasis_log_bad_type_access(#name); \
+ } \
+ return _priv_ ## name; \
+ }
+
+/*!
* \brief Boiler-plate removing macro for initializing message types.
*
* \code
Modified: team/kmoore/channel_event_refactor/res/res_agi.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel_event_refactor/res/res_agi.c?view=diff&rev=391428&r1=391427&r2=391428
==============================================================================
--- team/kmoore/channel_event_refactor/res/res_agi.c (original)
+++ team/kmoore/channel_event_refactor/res/res_agi.c Tue Jun 11 13:41:52 2013
@@ -1027,17 +1027,11 @@
AGI_RESULT_HANGUP,
};
-struct stasis_message_type *agi_exec_start_type(void);
-struct stasis_message_type *agi_exec_end_type(void);
-struct stasis_message_type *agi_async_start_type(void);
-struct stasis_message_type *agi_async_exec_type(void);
-struct stasis_message_type *agi_async_end_type(void);
-
-STASIS_MESSAGE_TYPE_DEFN(agi_exec_start_type);
-STASIS_MESSAGE_TYPE_DEFN(agi_exec_end_type);
-STASIS_MESSAGE_TYPE_DEFN(agi_async_start_type);
-STASIS_MESSAGE_TYPE_DEFN(agi_async_exec_type);
-STASIS_MESSAGE_TYPE_DEFN(agi_async_end_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(agi_exec_start_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(agi_exec_end_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(agi_async_start_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(agi_async_exec_type);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(agi_async_end_type);
static void agi_channel_manager_event(void *data,
struct stasis_subscription *sub, struct stasis_topic *topic,
More information about the asterisk-commits
mailing list