[svn-commits] dlee: branch dlee/json_main r382796 - in /team/dlee/json_main: apps/ main/
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Mon Mar 11 11:21:14 CDT 2013
Author: dlee
Date: Mon Mar 11 11:21:11 2013
New Revision: 382796
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382796
Log:
Moved app_userevent to use Stasis
Modified:
team/dlee/json_main/apps/app_userevent.c
team/dlee/json_main/main/manager.c
Modified: team/dlee/json_main/apps/app_userevent.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/json_main/apps/app_userevent.c?view=diff&rev=382796&r1=382795&r2=382796
==============================================================================
--- team/dlee/json_main/apps/app_userevent.c (original)
+++ team/dlee/json_main/apps/app_userevent.c Mon Mar 11 11:21:11 2013
@@ -33,6 +33,7 @@
#include "asterisk/module.h"
#include "asterisk/manager.h"
#include "asterisk/app.h"
+#include "asterisk/json.h"
/*** DOCUMENTATION
<application name="UserEvent" language="en_US">
@@ -68,11 +69,12 @@
AST_APP_ARG(eventname);
AST_APP_ARG(extra)[100];
);
- struct ast_str *body = ast_str_create(16);
+ RAII_VAR(struct ast_str *, body, ast_str_create(16), ast_free);
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+ RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
- ast_free(body);
return -1;
}
@@ -89,24 +91,21 @@
ast_str_append(&body, 0, "%s\r\n", args.extra[x]);
}
- /*** DOCUMENTATION
- <managerEventInstance>
- <synopsis>A user defined event raised from the dialplan.</synopsis>
- <parameter name="UserEvent">
- <para>The event name, as specified in the dialplan.</para>
- </parameter>
- <see-also>
- <ref type="application">UserEvent</ref>
- </see-also>
- </managerEventInstance>
- ***/
- manager_event(EVENT_FLAG_USER, "UserEvent",
- "UserEvent: %s\r\n"
- "Uniqueid: %s\r\n"
- "%s",
- args.eventname, ast_channel_uniqueid(chan), ast_str_buffer(body));
+ blob = ast_json_pack("{s: s, s: s, s: s}",
+ "type", "userevent",
+ "eventname", args.eventname,
+ "body", ast_str_buffer(body));
+ if (!blob) {
+ ast_log(LOG_WARNING, "Unable to create message buffer\n");
+ return -1;
+ }
- ast_free(body);
+ msg = ast_channel_blob_create(chan, blob);
+ if (!msg) {
+ return -1;
+ }
+
+ stasis_publish(ast_channel_topic(chan), msg);
return 0;
}
Modified: team/dlee/json_main/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/json_main/main/manager.c?view=diff&rev=382796&r1=382795&r2=382796
==============================================================================
--- team/dlee/json_main/main/manager.c (original)
+++ team/dlee/json_main/main/manager.c Mon Mar 11 11:21:11 2013
@@ -7499,8 +7499,10 @@
return out;
}
-static void channel_snapshot_update(struct ast_channel_snapshot *old_snapshot, struct ast_channel_snapshot *new_snapshot)
-{
+static void channel_snapshot_update(struct stasis_cache_update *update)
+{
+ struct ast_channel_snapshot *old_snapshot = stasis_message_data(update->old_snapshot);
+ struct ast_channel_snapshot *new_snapshot = stasis_message_data(update->new_snapshot);
int is_hungup;
char *manager_event = NULL;
@@ -7533,8 +7535,21 @@
}
}
-static void channel_varset(const char *channel_name, const char *uniqueid, const char *name, const char *value)
-{
+static void channel_varset(struct ast_channel_blob *obj)
+{
+ const char *variable = ast_json_string_get(ast_json_object_get(obj->blob, "variable"));
+ const char *value = ast_json_string_get(ast_json_object_get(obj->blob, "value"));
+ const char *name;
+ const char *uniqueid;
+
+ if (obj->snapshot) {
+ name = obj->snapshot->name;
+ uniqueid = obj->snapshot->uniqueid;
+ } else {
+ name = "none";
+ uniqueid = "none";
+ }
+
/*** DOCUMENTATION
<managerEventInstance>
<synopsis>Raised when a variable is set to a particular value.</synopsis>
@@ -7545,7 +7560,35 @@
"Variable: %s\r\n"
"Value: %s\r\n"
"Uniqueid: %s\r\n",
- channel_name, name, value, uniqueid);
+ name, variable, value, uniqueid);
+}
+
+static void channel_userevent(struct ast_channel_blob *obj)
+{
+ const char *uniqueid;
+ const char *eventname;
+ const char *body;
+
+ uniqueid = obj->snapshot->uniqueid;
+ eventname = ast_json_string_get(ast_json_object_get(obj->blob, "eventname"));
+ body = ast_json_string_get(ast_json_object_get(obj->blob, "body"));
+
+ /*** DOCUMENTATION
+ <managerEventInstance>
+ <synopsis>A user defined event raised from the dialplan.</synopsis>
+ <parameter name="UserEvent">
+ <para>The event name, as specified in the dialplan.</para>
+ </parameter>
+ <see-also>
+ <ref type="application">UserEvent</ref>
+ </see-also>
+ </managerEventInstance>
+ ***/
+ manager_event(EVENT_FLAG_USER, "UserEvent",
+ "UserEvent: %s\r\n"
+ "Uniqueid: %s\r\n"
+ "%s",
+ eventname, uniqueid, body);
}
static void channel_event_cb(void *data, struct stasis_subscription *sub,
@@ -7554,30 +7597,15 @@
if (stasis_message_type(message) == stasis_cache_update()) {
struct stasis_cache_update *update = stasis_message_data(message);
if (ast_channel_snapshot() == update->type) {
- struct ast_channel_snapshot *old_snapshot =
- stasis_message_data(update->old_snapshot);
- struct ast_channel_snapshot *new_snapshot =
- stasis_message_data(update->new_snapshot);
- channel_snapshot_update(old_snapshot, new_snapshot);
+ channel_snapshot_update(update);
}
} else if (stasis_message_type(message) == ast_channel_blob()) {
struct ast_channel_blob *obj = stasis_message_data(message);
if (strcmp("varset", ast_channel_blob_type(obj)) == 0) {
- const char *variable = ast_json_string_get(ast_json_object_get(obj->blob, "variable"));
- const char *value = ast_json_string_get(ast_json_object_get(obj->blob, "value"));
- const char *name;
- const char *uniqueid;
-
- if (obj->snapshot) {
- name = obj->snapshot->name;
- uniqueid = obj->snapshot->uniqueid;
- } else {
- name = "none";
- uniqueid = "none";
- }
-
- channel_varset(name, uniqueid, variable, value);
+ channel_varset(obj);
+ } else if (strcmp("userevent", ast_channel_blob_type(obj)) == 0) {
+ channel_userevent(obj);
}
}
}
More information about the svn-commits
mailing list