[asterisk-commits] cdr.c: Eliminated simple RAII VAR usages. (asterisk[master])
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Oct 11 12:04:09 CDT 2017
Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/6725 )
Change subject: cdr.c: Eliminated simple RAII_VAR usages.
......................................................................
cdr.c: Eliminated simple RAII_VAR usages.
Change-Id: I150505db307249a962987e7b941bdd369bb91f35
---
M main/cdr.c
1 file changed, 74 insertions(+), 55 deletions(-)
Approvals:
Corey Farrell: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, but someone else must approve
Sean Bright: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Jenkins2: Approved for Submit
diff --git a/main/cdr.c b/main/cdr.c
index b94bbcf..1ea2445 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -1564,11 +1564,10 @@
for (it_cdrs = ao2_iterator_init(bridge->channels, 0);
!success && (channel_id = ao2_iterator_next(&it_cdrs));
ao2_ref(channel_id, -1)) {
- RAII_VAR(struct cdr_object *, cand_cdr_master,
- ao2_find(active_cdrs_by_channel, channel_id, OBJ_SEARCH_KEY),
- ao2_cleanup);
+ struct cdr_object *cand_cdr_master;
struct cdr_object *cand_cdr;
+ cand_cdr_master = ao2_find(active_cdrs_by_channel, channel_id, OBJ_SEARCH_KEY);
if (!cand_cdr_master) {
continue;
}
@@ -1590,6 +1589,7 @@
break;
}
ao2_unlock(cand_cdr_master);
+ ao2_cleanup(cand_cdr_master);
}
ao2_iterator_destroy(&it_cdrs);
@@ -1712,11 +1712,10 @@
for (it_cdrs = ao2_iterator_init(bridge->channels, 0);
!success && (channel_id = ao2_iterator_next(&it_cdrs));
ao2_ref(channel_id, -1)) {
- RAII_VAR(struct cdr_object *, cand_cdr_master,
- ao2_find(active_cdrs_by_channel, channel_id, OBJ_SEARCH_KEY),
- ao2_cleanup);
+ struct cdr_object *cand_cdr_master;
struct cdr_object *cand_cdr;
+ cand_cdr_master = ao2_find(active_cdrs_by_channel, channel_id, OBJ_SEARCH_KEY);
if (!cand_cdr_master) {
continue;
}
@@ -1751,6 +1750,7 @@
break;
}
ao2_unlock(cand_cdr_master);
+ ao2_cleanup(cand_cdr_master);
}
ao2_iterator_destroy(&it_cdrs);
@@ -1921,7 +1921,7 @@
static void handle_dial_message(void *data, struct stasis_subscription *sub, struct stasis_message *message)
{
RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(module_configs), ao2_cleanup);
- RAII_VAR(struct cdr_object *, cdr, NULL, ao2_cleanup);
+ struct cdr_object *cdr;
struct ast_multi_channel_blob *payload = stasis_message_data(message);
struct ast_channel_snapshot *caller;
struct ast_channel_snapshot *peer;
@@ -1957,7 +1957,6 @@
} else {
cdr = ao2_find(active_cdrs_by_channel, peer->uniqueid, OBJ_SEARCH_KEY);
}
-
if (!cdr) {
ast_log(AST_LOG_WARNING, "No CDR for channel %s\n", caller ? caller->name : peer->name);
ast_assert(0);
@@ -1997,15 +1996,12 @@
struct cdr_object *new_cdr;
new_cdr = cdr_object_create_and_append(cdr);
- if (!new_cdr) {
- ao2_unlock(cdr);
- return;
+ if (new_cdr) {
+ new_cdr->fn_table->process_dial_begin(new_cdr, caller, peer);
}
- new_cdr->fn_table->process_dial_begin(new_cdr,
- caller,
- peer);
}
ao2_unlock(cdr);
+ ao2_cleanup(cdr);
}
static int cdr_object_finalize_party_b(void *obj, void *arg, int flags)
@@ -2079,7 +2075,7 @@
*/
static void handle_channel_cache_message(void *data, struct stasis_subscription *sub, struct stasis_message *message)
{
- RAII_VAR(struct cdr_object *, cdr, NULL, ao2_cleanup);
+ struct cdr_object *cdr;
RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(module_configs), ao2_cleanup);
struct stasis_cache_update *update = stasis_message_data(message);
struct ast_channel_snapshot *old_snapshot;
@@ -2107,12 +2103,11 @@
}
cdr->is_root = 1;
ao2_link(active_cdrs_by_channel, cdr);
+ } else {
+ cdr = ao2_find(active_cdrs_by_channel, uniqueid, OBJ_SEARCH_KEY);
}
/* Handle Party A */
- if (!cdr) {
- cdr = ao2_find(active_cdrs_by_channel, uniqueid, OBJ_SEARCH_KEY);
- }
if (!cdr) {
ast_log(AST_LOG_WARNING, "No CDR for channel %s\n", name);
ast_assert(0);
@@ -2120,6 +2115,7 @@
ao2_lock(cdr);
if (new_snapshot) {
int all_reject = 1;
+
for (it_cdr = cdr; it_cdr; it_cdr = it_cdr->next) {
if (!it_cdr->fn_table->process_party_a) {
continue;
@@ -2129,6 +2125,7 @@
if (all_reject && check_new_cdr_needed(old_snapshot, new_snapshot)) {
/* We're not hung up and we have a new snapshot - we need a new CDR */
struct cdr_object *new_cdr;
+
new_cdr = cdr_object_create_and_append(cdr);
if (new_cdr) {
new_cdr->fn_table->process_party_a(new_cdr, new_snapshot);
@@ -2154,6 +2151,7 @@
old_snapshot);
}
+ ao2_cleanup(cdr);
}
struct bridge_leave_data {
@@ -2216,9 +2214,7 @@
struct ast_channel_snapshot *channel = update->channel;
RAII_VAR(struct module_config *, mod_cfg,
ao2_global_obj_ref(module_configs), ao2_cleanup);
- RAII_VAR(struct cdr_object *, cdr,
- ao2_find(active_cdrs_by_channel, channel->uniqueid, OBJ_SEARCH_KEY),
- ao2_cleanup);
+ struct cdr_object *cdr;
struct cdr_object *it_cdr;
struct bridge_leave_data leave_data = {
.bridge = bridge,
@@ -2239,6 +2235,7 @@
(unsigned int)stasis_message_timestamp(message)->tv_sec,
(unsigned int)stasis_message_timestamp(message)->tv_usec);
+ cdr = ao2_find(active_cdrs_by_channel, channel->uniqueid, OBJ_SEARCH_KEY);
if (!cdr) {
ast_log(AST_LOG_WARNING, "No CDR for channel %s\n", channel->name);
ast_assert(0);
@@ -2259,16 +2256,16 @@
}
}
ao2_unlock(cdr);
- if (!left_bridge) {
- return;
+
+ /* Party B */
+ if (left_bridge
+ && strcmp(bridge->subclass, "parking")) {
+ ao2_callback(active_cdrs_by_channel, OBJ_NODATA,
+ cdr_object_party_b_left_bridge_cb,
+ &leave_data);
}
- if (strcmp(bridge->subclass, "parking")) {
- /* Party B */
- ao2_callback(active_cdrs_by_channel, OBJ_NODATA,
- cdr_object_party_b_left_bridge_cb,
- &leave_data);
- }
+ ao2_cleanup(cdr);
}
/*!
@@ -2373,16 +2370,13 @@
it_channels = ao2_iterator_init(bridge->channels, 0);
while ((channel_id = ao2_iterator_next(&it_channels))) {
- RAII_VAR(struct cdr_object *, cand_cdr,
- ao2_find(active_cdrs_by_channel, channel_id, OBJ_SEARCH_KEY),
- ao2_cleanup);
+ struct cdr_object *cand_cdr;
- if (!cand_cdr) {
- ao2_ref(channel_id, -1);
- continue;
+ cand_cdr = ao2_find(active_cdrs_by_channel, channel_id, OBJ_SEARCH_KEY);
+ if (cand_cdr) {
+ bridge_candidate_process(cdr, cand_cdr);
+ ao2_ref(cand_cdr, -1);
}
-
- bridge_candidate_process(cdr, cand_cdr);
ao2_ref(channel_id, -1);
}
@@ -2519,9 +2513,7 @@
struct ast_bridge_blob *update = stasis_message_data(message);
struct ast_bridge_snapshot *bridge = update->bridge;
struct ast_channel_snapshot *channel = update->channel;
- RAII_VAR(struct cdr_object *, cdr,
- ao2_find(active_cdrs_by_channel, channel->uniqueid, OBJ_SEARCH_KEY),
- ao2_cleanup);
+ struct cdr_object *cdr;
RAII_VAR(struct module_config *, mod_cfg,
ao2_global_obj_ref(module_configs), ao2_cleanup);
@@ -2538,6 +2530,7 @@
(unsigned int)stasis_message_timestamp(message)->tv_sec,
(unsigned int)stasis_message_timestamp(message)->tv_usec);
+ cdr = ao2_find(active_cdrs_by_channel, channel->uniqueid, OBJ_SEARCH_KEY);
if (!cdr) {
ast_log(AST_LOG_WARNING, "No CDR for channel %s\n", channel->name);
ast_assert(0);
@@ -2549,6 +2542,7 @@
} else {
handle_standard_bridge_enter_message(cdr, bridge, channel);
}
+ ao2_cleanup(cdr);
}
/*!
@@ -2563,7 +2557,7 @@
{
struct ast_parked_call_payload *payload = stasis_message_data(message);
struct ast_channel_snapshot *channel = payload->parkee;
- RAII_VAR(struct cdr_object *, cdr, NULL, ao2_cleanup);
+ struct cdr_object *cdr;
RAII_VAR(struct module_config *, mod_cfg,
ao2_global_obj_ref(module_configs), ao2_cleanup);
int unhandled = 1;
@@ -2605,7 +2599,9 @@
if (unhandled) {
/* Nothing handled the messgae - we need a new one! */
- struct cdr_object *new_cdr = cdr_object_create_and_append(cdr);
+ struct cdr_object *new_cdr;
+
+ new_cdr = cdr_object_create_and_append(cdr);
if (new_cdr) {
/* As the new CDR is created in the single state, it is guaranteed
* to have a function for the parked call message and will handle
@@ -2616,6 +2612,7 @@
ao2_unlock(cdr);
+ ao2_cleanup(cdr);
}
/*!
@@ -3108,15 +3105,16 @@
int ast_cdr_getvar(const char *channel_name, const char *name, char *value, size_t length)
{
- RAII_VAR(struct cdr_object *, cdr, cdr_object_get_by_name(channel_name), ao2_cleanup);
+ struct cdr_object *cdr;
struct cdr_object *cdr_obj;
- if (!cdr) {
- ast_log(AST_LOG_ERROR, "Unable to find CDR for channel %s\n", channel_name);
+ if (ast_strlen_zero(name)) {
return 1;
}
- if (ast_strlen_zero(name)) {
+ cdr = cdr_object_get_by_name(channel_name);
+ if (!cdr) {
+ ast_log(AST_LOG_ERROR, "Unable to find CDR for channel %s\n", channel_name);
return 1;
}
@@ -3130,18 +3128,20 @@
ao2_unlock(cdr);
+ ao2_cleanup(cdr);
return 0;
}
int ast_cdr_serialize_variables(const char *channel_name, struct ast_str **buf, char delim, char sep)
{
- RAII_VAR(struct cdr_object *, cdr, cdr_object_get_by_name(channel_name), ao2_cleanup);
+ struct cdr_object *cdr;
struct cdr_object *it_cdr;
struct ast_var_t *variable;
const char *var;
char workspace[256];
int total = 0, x = 0, i;
+ cdr = cdr_object_get_by_name(channel_name);
if (!cdr) {
RAII_VAR(struct module_config *, mod_cfg,
ao2_global_obj_ref(module_configs), ao2_cleanup);
@@ -3190,6 +3190,7 @@
}
}
ao2_unlock(cdr);
+ ao2_cleanup(cdr);
return total;
}
@@ -3257,7 +3258,7 @@
void ast_cdr_setuserfield(const char *channel_name, const char *userfield)
{
- RAII_VAR(struct cdr_object *, cdr, cdr_object_get_by_name(channel_name), ao2_cleanup);
+ struct cdr_object *cdr;
struct party_b_userfield_update party_b_info = {
.channel_name = channel_name,
.userfield = userfield,
@@ -3265,6 +3266,7 @@
struct cdr_object *it_cdr;
/* Handle Party A */
+ cdr = cdr_object_get_by_name(channel_name);
if (cdr) {
ao2_lock(cdr);
for (it_cdr = cdr; it_cdr; it_cdr = it_cdr->next) {
@@ -3281,6 +3283,7 @@
cdr_object_update_party_b_userfield_cb,
&party_b_info);
+ ao2_cleanup(cdr);
}
static void post_cdr(struct ast_cdr *cdr)
@@ -3319,9 +3322,10 @@
int ast_cdr_set_property(const char *channel_name, enum ast_cdr_options option)
{
- RAII_VAR(struct cdr_object *, cdr, cdr_object_get_by_name(channel_name), ao2_cleanup);
+ struct cdr_object *cdr;
struct cdr_object *it_cdr;
+ cdr = cdr_object_get_by_name(channel_name);
if (!cdr) {
return -1;
}
@@ -3339,14 +3343,16 @@
}
ao2_unlock(cdr);
+ ao2_cleanup(cdr);
return 0;
}
int ast_cdr_clear_property(const char *channel_name, enum ast_cdr_options option)
{
- RAII_VAR(struct cdr_object *, cdr, cdr_object_get_by_name(channel_name), ao2_cleanup);
+ struct cdr_object *cdr;
struct cdr_object *it_cdr;
+ cdr = cdr_object_get_by_name(channel_name);
if (!cdr) {
return -1;
}
@@ -3360,15 +3366,17 @@
}
ao2_unlock(cdr);
+ ao2_cleanup(cdr);
return 0;
}
int ast_cdr_reset(const char *channel_name, int keep_variables)
{
- RAII_VAR(struct cdr_object *, cdr, cdr_object_get_by_name(channel_name), ao2_cleanup);
+ struct cdr_object *cdr;
struct ast_var_t *vardata;
struct cdr_object *it_cdr;
+ cdr = cdr_object_get_by_name(channel_name);
if (!cdr) {
return -1;
}
@@ -3396,6 +3404,7 @@
}
ao2_unlock(cdr);
+ ao2_cleanup(cdr);
return 0;
}
@@ -3805,7 +3814,7 @@
char answer_time_buffer[64];
char end_time_buffer[64];
const char *channel_name = a->argv[3];
- RAII_VAR(struct cdr_object *, cdr, NULL, ao2_cleanup);
+ struct cdr_object *cdr;
#define TITLE_STRING "%-10.10s %-20.20s %-25.25s %-15.15s %-15.15s %-8.8s %-8.8s %-8.8s %-8.8s %-8.8s\n"
#define FORMAT_STRING "%-10.10s %-20.20s %-25.25s %-15.15s %-15.15s %-8.8s %-8.8s %-8.8s %-8.8ld %-8.8ld\n"
@@ -3850,6 +3859,9 @@
(long)ast_tvdiff_ms(end, it_cdr->start) / 1000);
}
ao2_unlock(cdr);
+
+ ao2_cleanup(cdr);
+
#undef FORMAT_STRING
#undef TITLE_STRING
}
@@ -4264,8 +4276,6 @@
void ast_cdr_engine_term(void)
{
RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(module_configs), ao2_cleanup);
- RAII_VAR(void *, payload, NULL, ao2_cleanup);
- RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
/* Since this is called explicitly during process shutdown, we might not have ever
* been initialized. If so, the config object will be NULL.
@@ -4275,9 +4285,16 @@
}
if (cdr_sync_message_type()) {
+ void *payload;
+ struct stasis_message *message;
+
+ if (!stasis_router) {
+ return;
+ }
+
/* Make sure we have the needed items */
payload = ao2_alloc(sizeof(*payload), NULL);
- if (!stasis_router || !payload) {
+ if (!payload) {
return;
}
@@ -4287,6 +4304,8 @@
if (message) {
stasis_message_router_publish_sync(stasis_router, message);
}
+ ao2_cleanup(message);
+ ao2_cleanup(payload);
}
if (ast_test_flag(&mod_cfg->general->settings, CDR_BATCHMODE)) {
--
To view, visit https://gerrit.asterisk.org/6725
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I150505db307249a962987e7b941bdd369bb91f35
Gerrit-Change-Number: 6725
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-commits/attachments/20171011/783afd34/attachment-0001.html>
More information about the asterisk-commits
mailing list