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
This commit is contained in:
David M. Lee
2013-05-08 18:34:50 +00:00
parent 297feffd4e
commit 0eb4cf8c19
8 changed files with 238 additions and 201 deletions

View File

@@ -470,19 +470,17 @@ static void dtmf_handler(struct app *app, struct ast_channel_blob *obj)
app_send(app, msg);
}
static void blob_handler(struct app *app, struct ast_channel_blob *blob)
{
/* To simplify events, we'll only generate on DTMF end */
if (strcmp(ast_channel_blob_json_type(blob), "dtmf_end") == 0) {
dtmf_handler(app, blob);
}
}
static void sub_handler(void *data, struct stasis_subscription *sub,
struct stasis_topic *topic,
struct stasis_message *message)
{
struct app *app = data;
if (stasis_subscription_final_message(sub, message)) {
ao2_cleanup(data);
return;
}
if (ast_channel_snapshot_type() == stasis_message_type(message)) {
RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
struct ast_channel_snapshot *snapshot =
@@ -493,13 +491,12 @@ static void sub_handler(void *data, struct stasis_subscription *sub,
return;
}
app_send(app, msg);
} else if (ast_channel_blob_type() == stasis_message_type(message)) {
} else if (ast_channel_dtmf_end_type() == stasis_message_type(message)) {
/* To simplify events, we'll only generate on DTMF end */
struct ast_channel_blob *blob = stasis_message_data(message);
blob_handler(app, blob);
}
if (stasis_subscription_final_message(sub, message)) {
ao2_cleanup(data);
dtmf_handler(app, blob);
}
}
/*!