[Asterisk-code-review] cdr.c: Rename the Party A CDR container. (asterisk[13])

Joshua Colp asteriskteam at digium.com
Tue Oct 17 11:06:25 CDT 2017


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/6766 )

Change subject: cdr.c: Rename the Party A CDR container.
......................................................................

cdr.c: Rename the Party A CDR container.

* Rename the Party A CDR container from active_cdrs_by_channel to
active_cdrs_master.

* Renamed the support functions associated with active_cdrs_master
appropriately.

ASTERISK-27335

Change-Id: I6104bb3edc3a0b7243ce502e45e8832b0cff14f7
---
M main/cdr.c
1 file changed, 45 insertions(+), 38 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/main/cdr.c b/main/cdr.c
index ee1bb36..1424607 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -348,8 +348,8 @@
 AST_MUTEX_DEFINE_STATIC(cdr_pending_lock);
 static ast_cond_t cdr_pending_cond;
 
-/*! \brief A container of the active CDRs indexed by Party A channel id */
-static struct ao2_container *active_cdrs_by_channel;
+/*! \brief A container of the active master CDRs indexed by Party A channel uniqueid */
+static struct ao2_container *active_cdrs_master;
 
 /*! \brief A container of all active CDRs indexed by Party B channel name */
 static struct ao2_container *active_cdrs_all;
@@ -709,7 +709,7 @@
 	struct ast_flags flags;                 /*!< Flags on the CDR */
 	AST_DECLARE_STRING_FIELDS(
 		AST_STRING_FIELD(linkedid);         /*!< Linked ID. Cached here as it may change out from party A, which must be immutable */
-		AST_STRING_FIELD(uniqueid);			/*!< Unique id of party A. Cached here as it is the primary key of this CDR */
+		AST_STRING_FIELD(uniqueid);			/*!< Unique id of party A. Cached here as it is the master CDR container key */
 		AST_STRING_FIELD(name);             /*!< Channel name of party A. Cached here as the party A address may change */
 		AST_STRING_FIELD(bridge);           /*!< The bridge the party A happens to be in. */
 		AST_STRING_FIELD(appl);             /*!< The last accepted application party A was in */
@@ -797,9 +797,12 @@
 		cdr->fn_table->init_function(cdr);
 	}
 }
-/*! \internal
- * \brief Hash function for containers of CDRs indexing by Party A uniqueid */
-static int cdr_object_channel_hash_fn(const void *obj, const int flags)
+
+/*!
+ * \internal
+ * \brief Hash function for master CDR container indexed by Party A uniqueid.
+ */
+static int cdr_master_hash_fn(const void *obj, const int flags)
 {
 	const struct cdr_object *cdr;
 	const char *key;
@@ -819,10 +822,11 @@
 	return ast_str_case_hash(key);
 }
 
-/*! \internal
- * \brief Comparison function for containers of CDRs indexing by Party A uniqueid
+/*!
+ * \internal
+ * \brief Comparison function for master CDR container indexed by Party A uniqueid.
  */
-static int cdr_object_channel_cmp_fn(void *obj, void *arg, int flags)
+static int cdr_master_cmp_fn(void *obj, void *arg, int flags)
 {
     struct cdr_object *left = obj;
     struct cdr_object *right = arg;
@@ -1717,7 +1721,7 @@
 		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);
+		cand_cdr_master = ao2_find(active_cdrs_master, channel_id, OBJ_SEARCH_KEY);
 		if (!cand_cdr_master) {
 			continue;
 		}
@@ -1865,7 +1869,7 @@
 			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);
+			cand_cdr_master = ao2_find(active_cdrs_master, channel_id, OBJ_SEARCH_KEY);
 			if (!cand_cdr_master) {
 				continue;
 			}
@@ -2088,9 +2092,9 @@
 
 	/* Figure out who is running this show */
 	if (caller) {
-		cdr = ao2_find(active_cdrs_by_channel, caller->uniqueid, OBJ_SEARCH_KEY);
+		cdr = ao2_find(active_cdrs_master, caller->uniqueid, OBJ_SEARCH_KEY);
 	} else {
-		cdr = ao2_find(active_cdrs_by_channel, peer->uniqueid, OBJ_SEARCH_KEY);
+		cdr = ao2_find(active_cdrs_master, peer->uniqueid, OBJ_SEARCH_KEY);
 	}
 	if (!cdr) {
 		ast_log(AST_LOG_WARNING, "No CDR for channel %s\n", caller ? caller->name : peer->name);
@@ -2245,12 +2249,12 @@
 			return;
 		}
 		cdr->is_root = 1;
-		ao2_link(active_cdrs_by_channel, cdr);
+		ao2_link(active_cdrs_master, cdr);
 	} else {
 		const char *uniqueid;
 
 		uniqueid = new_snapshot ? new_snapshot->uniqueid : old_snapshot->uniqueid;
-		cdr = ao2_find(active_cdrs_by_channel, uniqueid, OBJ_SEARCH_KEY);
+		cdr = ao2_find(active_cdrs_master, uniqueid, OBJ_SEARCH_KEY);
 	}
 
 	/* Handle Party A */
@@ -2290,7 +2294,7 @@
 		ao2_unlock(cdr);
 
 		cdr_all_unlink(cdr);
-		ao2_unlink(active_cdrs_by_channel, cdr);
+		ao2_unlink(active_cdrs_master, cdr);
 	}
 
 	/* Handle Party B */
@@ -2380,7 +2384,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);
+	cdr = ao2_find(active_cdrs_master, channel->uniqueid, OBJ_SEARCH_KEY);
 	if (!cdr) {
 		ast_log(AST_LOG_WARNING, "No CDR for channel %s\n", channel->name);
 		ast_assert(0);
@@ -2515,7 +2519,7 @@
 	while ((channel_id = ao2_iterator_next(&it_channels))) {
 		struct cdr_object *cand_cdr;
 
-		cand_cdr = ao2_find(active_cdrs_by_channel, channel_id, OBJ_SEARCH_KEY);
+		cand_cdr = ao2_find(active_cdrs_master, channel_id, OBJ_SEARCH_KEY);
 		if (cand_cdr) {
 			bridge_candidate_process(cdr, cand_cdr);
 			ao2_ref(cand_cdr, -1);
@@ -2667,7 +2671,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);
+	cdr = ao2_find(active_cdrs_master, channel->uniqueid, OBJ_SEARCH_KEY);
 	if (!cdr) {
 		ast_log(AST_LOG_WARNING, "No CDR for channel %s\n", channel->name);
 		ast_assert(0);
@@ -2717,7 +2721,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);
+	cdr = ao2_find(active_cdrs_master, channel->uniqueid, OBJ_SEARCH_KEY);
 	if (!cdr) {
 		ast_log(AST_LOG_WARNING, "No CDR for channel %s\n", channel->name);
 		ast_assert(0);
@@ -2890,7 +2894,7 @@
 		return 0;
 	}
 
-	active_count = ao2_container_count(active_cdrs_by_channel);
+	active_count = ao2_container_count(active_cdrs_master);
 
 	if (!match->suspended && active_count != 0) {
 		AST_RWLIST_UNLOCK(&be_list);
@@ -3103,7 +3107,7 @@
 		}
 	}
 
-	it_cdrs = ao2_callback(active_cdrs_by_channel, OBJ_MULTIPLE, cdr_object_select_all_by_name_cb, arg);
+	it_cdrs = ao2_callback(active_cdrs_master, OBJ_MULTIPLE, cdr_object_select_all_by_name_cb, arg);
 	if (!it_cdrs) {
 		ast_log(AST_LOG_ERROR, "Unable to find CDR for channel %s\n", channel_name);
 		return -1;
@@ -3231,7 +3235,7 @@
 	}
 
 	param = ast_strdupa(name);
-	return ao2_callback(active_cdrs_by_channel, 0, cdr_object_get_by_name_cb, param);
+	return ao2_callback(active_cdrs_master, 0, cdr_object_get_by_name_cb, param);
 }
 
 int ast_cdr_getvar(const char *channel_name, const char *name, char *value, size_t length)
@@ -3877,7 +3881,7 @@
 	struct ao2_iterator it_cdrs;
 	struct cdr_object *cdr;
 
-	it_cdrs = ao2_iterator_init(active_cdrs_by_channel, 0);
+	it_cdrs = ao2_iterator_init(active_cdrs_master, 0);
 	while ((cdr = ao2_iterator_next(&it_cdrs))) {
 		if (!strncasecmp(a->word, cdr->party_a.snapshot->name, wordlen) &&
 			(++which > a->n)) {
@@ -3909,7 +3913,7 @@
 	ast_cli(a->fd, "--------------------------------------------------\n");
 	ast_cli(a->fd, TITLE_STRING, "Channel", "Dst. Channel", "LastApp", "Start", "Answer", "End", "Billsec", "Duration");
 
-	it_cdrs = ao2_iterator_init(active_cdrs_by_channel, 0);
+	it_cdrs = ao2_iterator_init(active_cdrs_master, 0);
 	for (; (cdr = ao2_iterator_next(&it_cdrs)); ao2_cleanup(cdr)) {
 		struct cdr_object *it_cdr;
 		struct timeval start_time = { 0, };
@@ -4302,7 +4306,7 @@
 
 	STASIS_MESSAGE_TYPE_CLEANUP(cdr_sync_message_type);
 
-	ao2_callback(active_cdrs_by_channel, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK,
+	ao2_callback(active_cdrs_master, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK,
 		cdr_object_dispatch_all_cb, NULL);
 	finalize_batch_mode();
 	ast_cli_unregister_multiple(cli_commands, ARRAY_LEN(cli_commands));
@@ -4314,9 +4318,9 @@
 	aco_info_destroy(&cfg_info);
 	ao2_global_obj_release(module_configs);
 
-	ao2_container_unregister("cdrs_by_channel");
-	ao2_cleanup(active_cdrs_by_channel);
-	active_cdrs_by_channel = NULL;
+	ao2_container_unregister("cdrs_master");
+	ao2_cleanup(active_cdrs_master);
+	active_cdrs_master = NULL;
 
 	ao2_container_unregister("cdrs_all");
 	ao2_cleanup(active_cdrs_all);
@@ -4345,25 +4349,28 @@
 
 /*!
  * \internal
- * \brief Print channel object key (name).
+ * \brief Print master CDR container object.
  * \since 12.0.0
  *
- * \param v_obj A pointer to the object we want the key printed.
+ * \param v_obj A pointer to the object we want printed.
  * \param where User data needed by prnt to determine where to put output.
  * \param prnt Print output callback function to use.
  *
  * \return Nothing
  */
-static void cdr_container_print_fn(void *v_obj, void *where, ao2_prnt_fn *prnt)
+static void cdr_master_print_fn(void *v_obj, void *where, ao2_prnt_fn *prnt)
 {
 	struct cdr_object *cdr = v_obj;
 	struct cdr_object *it_cdr;
+
 	if (!cdr) {
 		return;
 	}
 	for (it_cdr = cdr; it_cdr; it_cdr = it_cdr->next) {
-		prnt(where, "Party A: %s; Party B: %s; Bridge %s\n", it_cdr->party_a.snapshot->name, it_cdr->party_b.snapshot ? it_cdr->party_b.snapshot->name : "<unknown>",
-				it_cdr->bridge);
+		prnt(where, "Party A: %s; Party B: %s; Bridge %s\n",
+			it_cdr->party_a.snapshot->name,
+			it_cdr->party_b.snapshot ? it_cdr->party_b.snapshot->name : "<unknown>",
+			it_cdr->bridge);
 	}
 }
 
@@ -4450,12 +4457,12 @@
 	stasis_message_router_add(stasis_router, ast_parked_call_type(), handle_parked_call_message, NULL);
 	stasis_message_router_add(stasis_router, cdr_sync_message_type(), handle_cdr_sync_message, NULL);
 
-	active_cdrs_by_channel = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
-		NUM_CDR_BUCKETS, cdr_object_channel_hash_fn, NULL, cdr_object_channel_cmp_fn);
-	if (!active_cdrs_by_channel) {
+	active_cdrs_master = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		NUM_CDR_BUCKETS, cdr_master_hash_fn, NULL, cdr_master_cmp_fn);
+	if (!active_cdrs_master) {
 		return -1;
 	}
-	ao2_container_register("cdrs_by_channel", active_cdrs_by_channel, cdr_container_print_fn);
+	ao2_container_register("cdrs_master", active_cdrs_master, cdr_master_print_fn);
 
 	active_cdrs_all = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
 		NUM_CDR_BUCKETS, cdr_all_hash_fn, NULL, cdr_all_cmp_fn);

-- 
To view, visit https://gerrit.asterisk.org/6766
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I6104bb3edc3a0b7243ce502e45e8832b0cff14f7
Gerrit-Change-Number: 6766
Gerrit-PatchSet: 3
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171017/8a1da7c7/attachment-0001.html>


More information about the asterisk-code-review mailing list