summaryrefslogtreecommitdiff
path: root/main/channel.c
diff options
context:
space:
mode:
authorDavid M. Lee <dlee@digium.com>2013-05-08 18:34:50 +0000
committerDavid M. Lee <dlee@digium.com>2013-05-08 18:34:50 +0000
commit0eb4cf8c194d05214677459feb389f63f60c68af (patch)
tree86f355afb7bda15fe320192ce9daecffa71bfba2 /main/channel.c
parent297feffd4ed67a5b72eb28de0f6c7edcd0edb40d (diff)
Remove required type field from channel blobs
When we first introduced the channel blob types, the JSON blobs were self identifying by a required "type" field in the JSON object itself. This, as it turns out, was a bad idea. When we introduced the message router, it was useless for routing based on the JSON type. And messages had two type fields to check: the stasis_message_type() of the message itself, plus the type field in the JSON blob (but only if it was a blob message). This patch corrects that mistake by removing the required type field from JSON blobs, and introducing first class stasis_message_type objects for the actual message type. Since we now will have a proliferation of message types, I introduced a few macros to help reduce the amount of boilerplate necessary to set them up. Review: https://reviewboard.asterisk.org/r/2509 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@388005 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/channel.c')
-rw-r--r--main/channel.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/main/channel.c b/main/channel.c
index 9ed7e5f25..d63aeb2ba 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -1368,11 +1368,12 @@ int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *fin)
}
/*! \internal \brief Publish a channel blob message */
-static void publish_channel_blob(struct ast_channel *chan, struct ast_json *blob)
+static void publish_channel_blob(struct ast_channel *chan,
+ struct stasis_message_type *type, struct ast_json *blob)
{
RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
if (blob) {
- message = ast_channel_blob_create(chan, blob);
+ message = ast_channel_blob_create(chan, type, blob);
}
if (message) {
stasis_publish(ast_channel_topic(chan), message);
@@ -1382,7 +1383,6 @@ static void publish_channel_blob(struct ast_channel *chan, struct ast_json *blob
/*! \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;
@@ -1390,8 +1390,7 @@ int ast_queue_hangup(struct ast_channel *chan)
/* 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);
- blob = ast_json_pack("{s: s}", "type", "hangup_request");
- publish_channel_blob(chan, blob);
+ publish_channel_blob(chan, ast_channel_hangup_request_type(), NULL);
res = ast_queue_frame(chan, &f);
ast_channel_unlock(chan);
@@ -1416,10 +1415,9 @@ int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
if (cause < 0) {
f.data.uint32 = ast_channel_hangupcause(chan);
}
- blob = ast_json_pack("{s: s, s: i}",
- "type", "hangup_request",
+ blob = ast_json_pack("{s: i}",
"cause", cause);
- publish_channel_blob(chan, blob);
+ publish_channel_blob(chan, ast_channel_hangup_request_type(), blob);
res = ast_queue_frame(chan, &f);
ast_channel_unlock(chan);
@@ -2727,11 +2725,10 @@ int ast_softhangup(struct ast_channel *chan, int cause)
ast_channel_lock(chan);
res = ast_softhangup_nolock(chan, cause);
- blob = ast_json_pack("{s: s, s: i, s: b}",
- "type", "hangup_request",
+ blob = ast_json_pack("{s: i, s: b}",
"cause", cause,
"soft", 1);
- publish_channel_blob(chan, blob);
+ publish_channel_blob(chan, ast_channel_hangup_request_type(), blob);
ast_channel_unlock(chan);
return res;
@@ -3737,15 +3734,14 @@ static void send_dtmf_begin_event(struct ast_channel *chan,
RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
char digit_str[] = { digit, '\0' };
- blob = ast_json_pack("{ s: s, s: s, s: s }",
- "type", "dtmf_begin",
+ blob = ast_json_pack("{ s: s, s: s }",
"digit", digit_str,
"direction", dtmf_direction_to_string(direction));
if (!blob) {
return;
}
- publish_channel_blob(chan, blob);
+ publish_channel_blob(chan, ast_channel_dtmf_begin_type(), blob);
}
static void send_dtmf_end_event(struct ast_channel *chan,
@@ -3754,8 +3750,7 @@ static void send_dtmf_end_event(struct ast_channel *chan,
RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
char digit_str[] = { digit, '\0' };
- blob = ast_json_pack("{ s: s, s: s, s: s, s: i }",
- "type", "dtmf_end",
+ blob = ast_json_pack("{ s: s, s: s, s: i }",
"digit", digit_str,
"direction", dtmf_direction_to_string(direction),
"duration_ms", duration_ms);
@@ -3763,7 +3758,7 @@ static void send_dtmf_end_event(struct ast_channel *chan,
return;
}
- publish_channel_blob(chan, blob);
+ publish_channel_blob(chan, ast_channel_dtmf_end_type(), blob);
}
static void ast_read_generator_actions(struct ast_channel *chan, struct ast_frame *f)