[Asterisk-code-review] stasis bridges: Remove silly usage of RAII VAR. (asterisk[13])
Jenkins2
asteriskteam at digium.com
Thu Jan 11 06:10:19 CST 2018
Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/7918 )
Change subject: stasis_bridges: Remove silly usage of RAII_VAR.
......................................................................
stasis_bridges: Remove silly usage of RAII_VAR.
Change-Id: I0fa7ab05454f183dc4ff10e26d18776d2b0fcf1f
---
M main/stasis_bridges.c
1 file changed, 58 insertions(+), 44 deletions(-)
Approvals:
George Joseph: Looks good to me, but someone else must approve
Richard Mudgett: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved
Jenkins2: Approved for Submit
diff --git a/main/stasis_bridges.c b/main/stasis_bridges.c
index 413c9be..0de4197 100644
--- a/main/stasis_bridges.c
+++ b/main/stasis_bridges.c
@@ -235,7 +235,7 @@
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 @@
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 @@
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 @@
}
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 @@
}
stasis_publish(ast_bridge_topic(bridge), msg);
+ ao2_ref(msg, -1);
}
/*! \brief Destructor for bridge merge messages */
@@ -340,7 +347,7 @@
/*! \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 @@
}
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 @@
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 @@
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 @@
}
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 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 @@
if (bridge) {
obj->bridge = ast_bridge_snapshot_create(bridge);
if (obj->bridge == NULL) {
+ ao2_ref(obj, -1);
+
return NULL;
}
}
@@ -446,6 +455,8 @@
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 @@
}
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 @@
}
msg = ast_bridge_blob_create(ast_channel_entered_bridge_type(), bridge, chan, blob);
+ ast_json_unref(blob);
if (!msg) {
return;
}
@@ -484,11 +493,12 @@
/* 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 @@
/* 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 @@
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 @@
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 @@
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 @@
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 @@
ast_json_string_create(snapshot->video_source_id));
}
- return ast_json_ref(json_bridge);
+ return json_bridge;
}
/*!
@@ -1214,7 +1229,7 @@
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 @@
}
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 @@
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;
}
--
To view, visit https://gerrit.asterisk.org/7918
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I0fa7ab05454f183dc4ff10e26d18776d2b0fcf1f
Gerrit-Change-Number: 7918
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180111/72a06b7c/attachment-0001.html>
More information about the asterisk-code-review
mailing list