Merge "stasis_bridges: Remove silly usage of RAII_VAR." into 13

certified/13.21
Jenkins2 7 years ago committed by Gerrit Code Review
commit 6acabbeaca

@ -235,7 +235,7 @@ static void bridge_snapshot_dtor(void *obj)
struct ast_bridge_snapshot *ast_bridge_snapshot_create(struct ast_bridge *bridge)
{
RAII_VAR(struct ast_bridge_snapshot *, snapshot, NULL, ao2_cleanup);
struct ast_bridge_snapshot *snapshot;
struct ast_bridge_channel *bridge_channel;
snapshot = ao2_alloc_options(sizeof(*snapshot), bridge_snapshot_dtor,
@ -247,17 +247,22 @@ struct ast_bridge_snapshot *ast_bridge_snapshot_create(struct ast_bridge *bridge
if (ast_string_field_init(snapshot, 128)
|| ast_string_field_init_extended(snapshot, video_source_id)) {
ao2_ref(snapshot, -1);
return NULL;
}
snapshot->channels = ast_str_container_alloc(SNAPSHOT_CHANNELS_BUCKETS);
if (!snapshot->channels) {
ao2_ref(snapshot, -1);
return NULL;
}
AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {
if (ast_str_container_add(snapshot->channels,
ast_channel_uniqueid(bridge_channel->chan))) {
ao2_ref(snapshot, -1);
return NULL;
}
}
@ -283,14 +288,13 @@ struct ast_bridge_snapshot *ast_bridge_snapshot_create(struct ast_bridge *bridge
ast_channel_uniqueid(bridge->softmix.video_mode.mode_data.talker_src_data.chan_vsrc));
}
ao2_ref(snapshot, +1);
return snapshot;
}
void ast_bridge_publish_state(struct ast_bridge *bridge)
{
RAII_VAR(struct ast_bridge_snapshot *, snapshot, NULL, ao2_cleanup);
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
struct ast_bridge_snapshot *snapshot;
struct stasis_message *msg;
if (!ast_bridge_snapshot_type()) {
return;
@ -304,17 +308,19 @@ void ast_bridge_publish_state(struct ast_bridge *bridge)
}
msg = stasis_message_create(ast_bridge_snapshot_type(), snapshot);
ao2_ref(snapshot, -1);
if (!msg) {
return;
}
stasis_publish(ast_bridge_topic(bridge), msg);
ao2_ref(msg, -1);
}
static void bridge_publish_state_from_blob(struct ast_bridge *bridge,
struct ast_bridge_blob *obj)
{
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
struct stasis_message *msg;
ast_assert(obj != NULL);
@ -324,6 +330,7 @@ static void bridge_publish_state_from_blob(struct ast_bridge *bridge,
}
stasis_publish(ast_bridge_topic(bridge), msg);
ao2_ref(msg, -1);
}
/*! \brief Destructor for bridge merge messages */
@ -340,7 +347,7 @@ static void bridge_merge_message_dtor(void *obj)
/*! \brief Bridge merge message creation helper */
static struct ast_bridge_merge_message *bridge_merge_message_create(struct ast_bridge *to, struct ast_bridge *from)
{
RAII_VAR(struct ast_bridge_merge_message *, msg, NULL, ao2_cleanup);
struct ast_bridge_merge_message *msg;
msg = ao2_alloc(sizeof(*msg), bridge_merge_message_dtor);
if (!msg) {
@ -348,16 +355,13 @@ static struct ast_bridge_merge_message *bridge_merge_message_create(struct ast_b
}
msg->to = ast_bridge_snapshot_create(to);
if (!msg->to) {
return NULL;
}
msg->from = ast_bridge_snapshot_create(from);
if (!msg->from) {
if (!msg->to || !msg->from) {
ao2_ref(msg, -1);
return NULL;
}
ao2_ref(msg, +1);
return msg;
}
@ -366,16 +370,17 @@ static struct ast_json *ast_bridge_merge_message_to_json(
const struct stasis_message_sanitizer *sanitize)
{
struct ast_bridge_merge_message *merge = stasis_message_data(msg);
RAII_VAR(struct ast_json *, json_bridge_to,
ast_bridge_snapshot_to_json(merge->to, sanitize), ast_json_unref);
RAII_VAR(struct ast_json *, json_bridge_from,
ast_bridge_snapshot_to_json(merge->from, sanitize), ast_json_unref);
struct ast_json *json_bridge_to = ast_bridge_snapshot_to_json(merge->to, sanitize);
struct ast_json *json_bridge_from = ast_bridge_snapshot_to_json(merge->from, sanitize);
if (!json_bridge_to || !json_bridge_from) {
ast_json_unref(json_bridge_to);
ast_json_unref(json_bridge_from);
return NULL;
}
return ast_json_pack("{s: s, s: o, s: O, s: O}",
return ast_json_pack("{s: s, s: o, s: o, s: o}",
"type", "BridgeMerged",
"timestamp", ast_json_timeval(*stasis_message_timestamp(msg), NULL),
"bridge", json_bridge_to,
@ -384,8 +389,8 @@ static struct ast_json *ast_bridge_merge_message_to_json(
void ast_bridge_publish_merge(struct ast_bridge *to, struct ast_bridge *from)
{
RAII_VAR(struct ast_bridge_merge_message *, merge_msg, NULL, ao2_cleanup);
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
struct ast_bridge_merge_message *merge_msg;
struct stasis_message *msg;
if (!ast_bridge_merge_message_type()) {
return;
@ -400,11 +405,13 @@ void ast_bridge_publish_merge(struct ast_bridge *to, struct ast_bridge *from)
}
msg = stasis_message_create(ast_bridge_merge_message_type(), merge_msg);
ao2_ref(merge_msg, -1);
if (!msg) {
return;
}
stasis_publish(ast_bridge_topic_all(), msg);
ao2_ref(msg, -1);
}
static void bridge_blob_dtor(void *obj)
@ -424,8 +431,8 @@ struct stasis_message *ast_bridge_blob_create(
struct ast_channel *chan,
struct ast_json *blob)
{
RAII_VAR(struct ast_bridge_blob *, obj, NULL, ao2_cleanup);
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
struct ast_bridge_blob *obj;
struct stasis_message *msg;
if (!message_type) {
return NULL;
@ -439,6 +446,8 @@ struct stasis_message *ast_bridge_blob_create(
if (bridge) {
obj->bridge = ast_bridge_snapshot_create(bridge);
if (obj->bridge == NULL) {
ao2_ref(obj, -1);
return NULL;
}
}
@ -446,6 +455,8 @@ struct stasis_message *ast_bridge_blob_create(
if (chan) {
obj->channel = ast_channel_snapshot_get_latest(ast_channel_uniqueid(chan));
if (obj->channel == NULL) {
ao2_ref(obj, -1);
return NULL;
}
}
@ -455,19 +466,16 @@ struct stasis_message *ast_bridge_blob_create(
}
msg = stasis_message_create(message_type, obj);
if (!msg) {
return NULL;
}
ao2_ref(obj, -1);
ao2_ref(msg, +1);
return msg;
}
void ast_bridge_publish_enter(struct ast_bridge *bridge, struct ast_channel *chan,
struct ast_channel *swap)
{
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
struct stasis_message *msg;
struct ast_json *blob = NULL;
if (swap) {
blob = ast_json_pack("{s: s}", "swap", ast_channel_uniqueid(swap));
@ -477,6 +485,7 @@ void ast_bridge_publish_enter(struct ast_bridge *bridge, struct ast_channel *cha
}
msg = ast_bridge_blob_create(ast_channel_entered_bridge_type(), bridge, chan, blob);
ast_json_unref(blob);
if (!msg) {
return;
}
@ -484,11 +493,12 @@ void ast_bridge_publish_enter(struct ast_bridge *bridge, struct ast_channel *cha
/* enter blob first, then state */
stasis_publish(ast_bridge_topic(bridge), msg);
bridge_publish_state_from_blob(bridge, stasis_message_data(msg));
ao2_ref(msg, -1);
}
void ast_bridge_publish_leave(struct ast_bridge *bridge, struct ast_channel *chan)
{
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
struct stasis_message *msg;
msg = ast_bridge_blob_create(ast_channel_left_bridge_type(), bridge, chan, NULL);
if (!msg) {
@ -498,6 +508,7 @@ void ast_bridge_publish_leave(struct ast_bridge *bridge, struct ast_channel *cha
/* state first, then leave blob (opposite of enter, preserves nesting of events) */
bridge_publish_state_from_blob(bridge, stasis_message_data(msg));
stasis_publish(ast_bridge_topic(bridge), msg);
ao2_ref(msg, -1);
}
static struct ast_json *simple_bridge_channel_event(
@ -507,16 +518,17 @@ static struct ast_json *simple_bridge_channel_event(
const struct timeval *tv,
const struct stasis_message_sanitizer *sanitize)
{
RAII_VAR(struct ast_json *, json_bridge,
ast_bridge_snapshot_to_json(bridge_snapshot, sanitize), ast_json_unref);
RAII_VAR(struct ast_json *, json_channel,
ast_channel_snapshot_to_json(channel_snapshot, sanitize), ast_json_unref);
struct ast_json *json_bridge = ast_bridge_snapshot_to_json(bridge_snapshot, sanitize);
struct ast_json *json_channel = ast_channel_snapshot_to_json(channel_snapshot, sanitize);
if (!json_bridge || !json_channel) {
ast_json_unref(json_bridge);
ast_json_unref(json_channel);
return NULL;
}
return ast_json_pack("{s: s, s: o, s: O, s: O}",
return ast_json_pack("{s: s, s: o, s: o, s: o}",
"type", type,
"timestamp", ast_json_timeval(*tv, NULL),
"bridge", json_bridge,
@ -546,9 +558,10 @@ struct ast_json *ast_channel_left_bridge_to_json(
static struct ast_json *container_to_json_array(struct ao2_container *items,
const struct stasis_message_sanitizer *sanitize)
{
RAII_VAR(struct ast_json *, json_items, ast_json_array_create(), ast_json_unref);
struct ast_json *json_items = ast_json_array_create();
char *item;
struct ao2_iterator it;
if (!json_items) {
return NULL;
}
@ -562,12 +575,14 @@ static struct ast_json *container_to_json_array(struct ao2_container *items,
if (ast_json_array_append(json_items, ast_json_string_create(item))) {
ao2_cleanup(item);
ao2_iterator_destroy(&it);
ast_json_unref(json_items);
return NULL;
}
}
ao2_iterator_destroy(&it);
return ast_json_ref(json_items);
return json_items;
}
static const char *capability2str(uint32_t capabilities)
@ -583,7 +598,7 @@ struct ast_json *ast_bridge_snapshot_to_json(
const struct ast_bridge_snapshot *snapshot,
const struct stasis_message_sanitizer *sanitize)
{
RAII_VAR(struct ast_json *, json_bridge, NULL, ast_json_unref);
struct ast_json *json_bridge;
struct ast_json *json_channels;
if (snapshot == NULL) {
@ -614,7 +629,7 @@ struct ast_json *ast_bridge_snapshot_to_json(
ast_json_string_create(snapshot->video_source_id));
}
return ast_json_ref(json_bridge);
return json_bridge;
}
/*!
@ -1214,7 +1229,7 @@ int ast_attended_transfer_message_add_link(struct ast_attended_transfer_message
void ast_bridge_publish_attended_transfer(struct ast_attended_transfer_message *transfer_msg)
{
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
struct stasis_message *msg;
msg = stasis_message_create(ast_attended_transfer_type(), transfer_msg);
if (!msg) {
@ -1222,11 +1237,12 @@ void ast_bridge_publish_attended_transfer(struct ast_attended_transfer_message *
}
stasis_publish(ast_bridge_topic_all(), msg);
ao2_ref(msg, -1);
}
struct ast_bridge_snapshot *ast_bridge_snapshot_get_latest(const char *uniqueid)
{
RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
struct stasis_message *message;
struct ast_bridge_snapshot *snapshot;
ast_assert(!ast_strlen_zero(uniqueid));
@ -1238,11 +1254,9 @@ struct ast_bridge_snapshot *ast_bridge_snapshot_get_latest(const char *uniqueid)
return NULL;
}
snapshot = stasis_message_data(message);
if (!snapshot) {
return NULL;
}
ao2_ref(snapshot, +1);
snapshot = ao2_bump(stasis_message_data(message));
ao2_ref(message, -1);
return snapshot;
}

Loading…
Cancel
Save