[asterisk-commits] kmoore: branch kmoore/channel_event_refactor r391450 - /team/kmoore/channel_e...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jun 11 15:34:38 CDT 2013
Author: kmoore
Date: Tue Jun 11 15:34:36 2013
New Revision: 391450
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=391450
Log:
Refactor GTalk ChannelUpdate event
Modified:
team/kmoore/channel_event_refactor/channels/chan_gtalk.c
Modified: team/kmoore/channel_event_refactor/channels/chan_gtalk.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel_event_refactor/channels/chan_gtalk.c?view=diff&rev=391450&r1=391449&r2=391450
==============================================================================
--- team/kmoore/channel_event_refactor/channels/chan_gtalk.c (original)
+++ team/kmoore/channel_event_refactor/channels/chan_gtalk.c Tue Jun 11 15:34:36 2013
@@ -46,6 +46,23 @@
<use type="external">openssl</use>
<support_level>deprecated</support_level>
<replacement>chan_motif</replacement>
+ ***/
+
+/*** DOCUMENTATION
+ <managerEvent language="en_US" name="ChannelUpdate">
+ <managerEventInstance class="EVENT_FLAG_SYSTEM">
+ <synopsis>Raised when a GTalk SID is established for a call.</synopsis>
+ <syntax>
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+ <parameter name="Gtalk-SID">
+ <para>The source of the session timeout.</para>
+ </parameter>
+ <parameter name="Channeltype">
+ <para>The type of the channel (always <literal>Gtalk</literal>).</para>
+ </parameter>
+ </syntax>
+ </managerEventInstance>
+ </managerEvent>
***/
#include "asterisk.h"
@@ -86,6 +103,7 @@
#include "asterisk/jabber.h"
#include "asterisk/jingle.h"
#include "asterisk/features.h"
+#include "asterisk/stasis_channels.h"
#define GOOGLE_CONFIG "gtalk.conf"
@@ -255,6 +273,11 @@
static struct gtalk_container gtalk_list;
+static struct ast_manager_event_blob *channel_update_to_ami(struct stasis_message *msg);
+STASIS_MESSAGE_TYPE_DEFN_LOCAL(channel_update_type,
+ .to_ami = channel_update_to_ami,
+ );
+
static void gtalk_member_destroy(struct gtalk *obj)
{
obj->cap = ast_format_cap_destroy(obj->cap);
@@ -538,6 +561,41 @@
return IKS_FILTER_EAT;
}
+static struct ast_manager_event_blob *channel_update_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 *sid = ast_json_string_get(ast_json_object_get(obj->blob, "gtalk_sid"));
+
+ if (obj->snapshot) {
+ channel_string = ast_manager_build_channel_state_string(obj->snapshot);
+ if (!channel_string) {
+ return NULL;
+ }
+ }
+
+ return ast_manager_event_blob_create(EVENT_FLAG_SYSTEM, "ChannelUpdate",
+ "%s"
+ "Channeltype: Gtalk\r\n"
+ "Gtalk-SID: %s\r\n",
+ S_COR(obj->snapshot, ast_str_buffer(channel_string), ""), sid);
+}
+
+/*! \brief Sends a session timeout channel blob used to produce SessionTimeout AMI messages */
+static void send_channel_update(struct ast_channel *chan, const char *sid)
+{
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+
+ ast_assert(sid != NULL);
+
+ blob = ast_json_pack("{s: s}", "gtalk_sid", sid);
+ if (!blob) {
+ return;
+ }
+
+ ast_channel_publish_blob(chan, channel_update_type(), blob);
+}
+
static int gtalk_answer(struct ast_channel *ast)
{
struct gtalk_pvt *p = ast_channel_tech_pvt(ast);
@@ -546,8 +604,7 @@
ast_debug(1, "Answer!\n");
ast_mutex_lock(&p->lock);
gtalk_invite(p, p->them, p->us,p->sid, 0);
- manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate", "Channel: %s\r\nChanneltype: %s\r\nGtalk-SID: %s\r\n",
- ast_channel_name(ast), "GTALK", p->sid);
+ send_channel_update(ast, p->sid);
ast_mutex_unlock(&p->lock);
return res;
}
@@ -1216,9 +1273,7 @@
ast_hangup(tmp);
tmp = NULL;
} else {
- manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate",
- "Channel: %s\r\nChanneltype: %s\r\nGtalk-SID: %s\r\n",
- i->owner ? ast_channel_name(i->owner) : "", "Gtalk", i->sid);
+ send_channel_update(i->owner, i->sid);
}
return tmp;
}
@@ -2322,6 +2377,10 @@
char *jabber_loaded = ast_module_helper("", "res_jabber.so", 0, 0, 0, 0);
struct ast_format tmpfmt;
+ if (STASIS_MESSAGE_TYPE_INIT(channel_update_type)) {
+ return AST_MODULE_LOAD_FAILURE;
+ }
+
if (!(gtalk_tech.capabilities = ast_format_cap_alloc())) {
return AST_MODULE_LOAD_DECLINE;
}
@@ -2419,6 +2478,7 @@
ASTOBJ_CONTAINER_DESTROY(>alk_list);
global_capability = ast_format_cap_destroy(global_capability);
gtalk_tech.capabilities = ast_format_cap_destroy(gtalk_tech.capabilities);
+ STASIS_MESSAGE_TYPE_CLEANUP(channel_update_type);
return 0;
}
More information about the asterisk-commits
mailing list