[asterisk-commits] dlee: branch dlee/ASTERISK-21096 r383335 - in /team/dlee/ASTERISK-21096: incl...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Mar 18 17:18:32 CDT 2013
Author: dlee
Date: Mon Mar 18 17:18:28 2013
New Revision: 383335
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383335
Log:
Moved [Soft]HangupRequest to Stasis
Modified:
team/dlee/ASTERISK-21096/include/asterisk/channel.h
team/dlee/ASTERISK-21096/main/channel.c
team/dlee/ASTERISK-21096/main/channel_internal_api.c
team/dlee/ASTERISK-21096/main/manager_channels.c
Modified: team/dlee/ASTERISK-21096/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-21096/include/asterisk/channel.h?view=diff&rev=383335&r1=383334&r2=383335
==============================================================================
--- team/dlee/ASTERISK-21096/include/asterisk/channel.h (original)
+++ team/dlee/ASTERISK-21096/include/asterisk/channel.h Mon Mar 18 17:18:28 2013
@@ -4165,10 +4165,12 @@
* \since 12
* \brief A topic which publishes the events for a particular channel.
*
- * \param chan Channel.
+ * If the given \a chan is \c NULL, ast_channel_topic_all() is returned.
+ *
+ * \param chan Channel, or \c NULL.
*
* \retval Topic for channel's events.
- * \retval \c NULL if \a chan is \c NULL.
+ * \retval ast_channel_topic_all() if \a chan is \c NULL.
*/
struct stasis_topic *ast_channel_topic(struct ast_channel *chan);
Modified: team/dlee/ASTERISK-21096/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-21096/main/channel.c?view=diff&rev=383335&r1=383334&r2=383335
==============================================================================
--- team/dlee/ASTERISK-21096/main/channel.c (original)
+++ team/dlee/ASTERISK-21096/main/channel.c Mon Mar 18 17:18:28 2013
@@ -243,6 +243,18 @@
stasis_publish(ast_channel_topic(chan), message);
}
+static void publish_channel_blob(struct ast_channel *chan, struct ast_json *blob)
+{
+ RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
+ if (blob) {
+ message = ast_channel_blob_create(chan, blob);
+ }
+ if (message) {
+ stasis_publish(ast_channel_topic(chan), message);
+ }
+}
+
+
static void channel_blob_dtor(void *obj)
{
struct ast_channel_blob *event = obj;
@@ -309,22 +321,7 @@
"type", "varset",
"variable", name,
"value", value);
- if (!blob) {
- ast_log(LOG_ERROR, "Error creating message\n");
- return;
- }
-
- msg = ast_channel_blob_create(chan, ast_json_ref(blob));
-
- if (!msg) {
- return;
- }
-
- if (chan) {
- stasis_publish(ast_channel_topic(chan), msg);
- } else {
- stasis_publish(ast_channel_topic_all(), msg);
- }
+ publish_channel_blob(chan, blob);
}
@@ -1463,22 +1460,16 @@
/*! \brief Queue a hangup frame for channel */
int ast_queue_hangup(struct ast_channel *chan)
{
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+ RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
int res;
/* Yeah, let's not change a lock-critical value without locking */
ast_channel_lock(chan);
ast_channel_softhangup_internal_flag_add(chan, AST_SOFTHANGUP_DEV);
- /*** DOCUMENTATION
- <managerEventInstance>
- <synopsis>Raised when a hangup is requested with no set cause.</synopsis>
- </managerEventInstance>
- ***/
- manager_event(EVENT_FLAG_CALL, "HangupRequest",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n",
- ast_channel_name(chan),
- ast_channel_uniqueid(chan));
+ blob = ast_json_pack("{s: s}", "type", "hangup_request");
+ publish_channel_blob(chan, blob);
res = ast_queue_frame(chan, &f);
ast_channel_unlock(chan);
@@ -1488,6 +1479,8 @@
/*! \brief Queue a hangup frame for channel */
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
{
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+ RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
int res;
@@ -1501,21 +1494,10 @@
if (cause < 0) {
f.data.uint32 = ast_channel_hangupcause(chan);
}
- /*** DOCUMENTATION
- <managerEventInstance>
- <synopsis>Raised when a hangup is requested with a specific cause code.</synopsis>
- <syntax>
- <xi:include xpointer="xpointer(/docs/managerEvent[@name='Hangup']/managerEventInstance/syntax/parameter[@name='Cause'])" />
- </syntax>
- </managerEventInstance>
- ***/
- manager_event(EVENT_FLAG_CALL, "HangupRequest",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Cause: %d\r\n",
- ast_channel_name(chan),
- ast_channel_uniqueid(chan),
- cause);
+ blob = ast_json_pack("{s: s, s: i}",
+ "type", "hangup_request",
+ "cause", cause);
+ publish_channel_blob(chan, blob);
res = ast_queue_frame(chan, &f);
ast_channel_unlock(chan);
@@ -2818,25 +2800,16 @@
/*! \brief Softly hangup a channel, lock */
int ast_softhangup(struct ast_channel *chan, int cause)
{
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
int res;
ast_channel_lock(chan);
res = ast_softhangup_nolock(chan, cause);
- /*** DOCUMENTATION
- <managerEventInstance>
- <synopsis>Raised when a soft hangup is requested with a specific cause code.</synopsis>
- <syntax>
- <xi:include xpointer="xpointer(/docs/managerEvent[@name='Hangup']/managerEventInstance/syntax/parameter[@name='Cause'])" />
- </syntax>
- </managerEventInstance>
- ***/
- manager_event(EVENT_FLAG_CALL, "SoftHangupRequest",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Cause: %d\r\n",
- ast_channel_name(chan),
- ast_channel_uniqueid(chan),
- cause);
+ blob = ast_json_pack("{s: s, s: i, s: b}",
+ "type", "hangup_request",
+ "cause", cause,
+ "soft", 1);
+ publish_channel_blob(chan, blob);
ast_channel_unlock(chan);
return res;
Modified: team/dlee/ASTERISK-21096/main/channel_internal_api.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-21096/main/channel_internal_api.c?view=diff&rev=383335&r1=383334&r2=383335
==============================================================================
--- team/dlee/ASTERISK-21096/main/channel_internal_api.c (original)
+++ team/dlee/ASTERISK-21096/main/channel_internal_api.c Mon Mar 18 17:18:28 2013
@@ -1385,7 +1385,7 @@
struct stasis_topic *ast_channel_topic(struct ast_channel *chan)
{
- return chan->topic;
+ return chan ? chan->topic : ast_channel_topic_all();
}
void ast_channel_internal_setup_topics(struct ast_channel *chan)
Modified: team/dlee/ASTERISK-21096/main/manager_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-21096/main/manager_channels.c?view=diff&rev=383335&r1=383334&r2=383335
==============================================================================
--- team/dlee/ASTERISK-21096/main/manager_channels.c (original)
+++ team/dlee/ASTERISK-21096/main/manager_channels.c Mon Mar 18 17:18:28 2013
@@ -104,6 +104,24 @@
<syntax>
<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
</syntax>
+ </managerEventInstance>
+ </managerEvent>
+ <managerEvent language="en_US" name="HangupRequest">
+ <managerEventInstance class="EVENT_FLAG_CALL">
+ <synopsis>Raised when a hangup is requested.</synopsis>
+ <syntax>
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='Hangup']/managerEventInstance/syntax/parameter[@name='Cause'])" />
+ </syntax>
+ </managerEventInstance>
+ </managerEvent>
+ <managerEvent language="en_US" name="SoftHangupRequest">
+ <managerEventInstance class="EVENT_FLAG_CALL">
+ <synopsis>Raised when a soft hangup is requested with a specific cause code.</synopsis>
+ <syntax>
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+ <xi:include xpointer="xpointer(/docs/managerEvent[@name='Hangup']/managerEventInstance/syntax/parameter[@name='Cause'])" />
+ </syntax>
</managerEventInstance>
</managerEvent>
***/
@@ -213,6 +231,17 @@
{
RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
+
+ channel_event_string = manager_build_channel_state_string(snapshot);
+
+ if (!channel_event_string) {
+ return;
+ }
+
+ /* XXX manager.c channelvars should be appeneded to this event
+ * i.e. ChanVariable(SIP/blink-00000000): foo=bar
+ */
+
/*** DOCUMENTATION
<managerEventInstance>
<synopsis>Raised when a channel receives new Caller ID information.</synopsis>
@@ -224,16 +253,6 @@
</syntax>
</managerEventInstance>
***/
-
- channel_event_string = manager_build_channel_state_string(snapshot);
-
- if (!channel_event_string) {
- return;
- }
-
- /* XXX manager.c channelvars should be appeneded to this event
- * i.e. ChanVariable(SIP/blink-00000000): foo=bar
- */
manager_event(EVENT_FLAG_CALL, "NewCallerid",
"%s"
"CID-CallingPres: %d (%s)\r\n",
@@ -388,6 +407,43 @@
ast_str_buffer(channel_event_string), eventname, body);
}
+static void channel_hangup_request(struct ast_channel_blob *obj)
+{
+ RAII_VAR(struct ast_str *, extra, NULL, ast_free);
+ RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
+ struct ast_json *cause;
+ int is_soft;
+ char *manager_event = "HangupRequest";
+
+ extra = ast_str_create(20);
+ if (!extra) {
+ return;
+ }
+
+ channel_event_string = manager_build_channel_state_string(obj->snapshot);
+
+ if (!channel_event_string) {
+ return;
+ }
+
+ cause = ast_json_object_get(obj->blob, "cause");
+ if (cause) {
+ ast_str_append(&extra, 0,
+ "Cause: %jd\r\n",
+ ast_json_integer_get(cause));
+ }
+
+ is_soft = ast_json_is_true(ast_json_object_get(obj->blob, "soft"));
+ if (is_soft) {
+ manager_event = "SoftHangupRequest";
+ }
+
+ manager_event(EVENT_FLAG_CALL, manager_event,
+ "%s%s",
+ ast_str_buffer(channel_event_string),
+ ast_str_buffer(extra));
+}
+
/*!
* \brief Callback processing messages on the channel topic.
*/
@@ -401,6 +457,8 @@
channel_varset(obj);
} else if (strcmp("userevent", ast_channel_blob_type(obj)) == 0) {
channel_userevent(obj);
+ } else if (strcmp("hangup_request", ast_channel_blob_type(obj)) == 0) {
+ channel_hangup_request(obj);
}
}
More information about the asterisk-commits
mailing list