[svn-commits] mmichelson: branch group/CCSS r223324 - /team/group/CCSS/main/ccss.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Oct 9 15:30:16 CDT 2009


Author: mmichelson
Date: Fri Oct  9 15:30:12 2009
New Revision: 223324

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=223324
Log:
Move all ao2_container-related structs, callbacks,
and constants to its own area of the file.


Modified:
    team/group/CCSS/main/ccss.c

Modified: team/group/CCSS/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=223324&r1=223323&r2=223324
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Fri Oct  9 15:30:12 2009
@@ -56,10 +56,128 @@
 	</application>
  ***/
 
-/* Some forward declarations, prototypes, and constants that don't
- * really fit well anywhere else
+/* File scope variables */
+static struct ast_sched_thread *cc_sched_thread;
+static const int CC_CORE_INSTANCES_BUCKETS = 17;
+static struct ao2_container *cc_core_instances;
+
+struct cc_core_instance {
+	/*!
+	 * Unique identifier for this instance of the CC core.
+	 */ 
+	int core_id;
+	/*!
+	 * The current state for this instance of the CC core.
+	 */
+	enum ast_cc_state current_state;
+	/*!
+	 * The CC agent in use for this call
+	 */
+	struct ast_cc_agent *agent;
+	/*!
+	 * Reference to the root of the monitor tree
+	 */
+	struct ast_cc_monitor *monitor;
+};
+
+static int cc_core_instance_hash_fn(const void *obj, const int flags)
+{
+	const struct cc_core_instance *core_instance = obj;
+	return core_instance->core_id;
+}
+
+static int cc_core_instance_cmp_fn(void *obj, void *arg, int flags)
+{
+	struct cc_core_instance *core_instance1 = obj;
+	struct cc_core_instance *core_instance2 = arg;
+
+	return core_instance1->core_id == core_instance2->core_id ? CMP_MATCH | CMP_STOP : 0;
+}
+
+enum match_flags {
+	MATCH_NO_MONITOR = (1 << 0),
+	MATCH_MONITOR = (1 << 1),
+};
+
+/* ao2_callbacks for cc_core_instances */
+
+/*!
+ * \brief find a core instance based on its agent
+ *
+ * The match flags tell whether we wish to find core instances
+ * that have a monitor or core instances that do not. Core instances
+ * with no monitor are core instances for which a caller has not yet
+ * requested CC. Core instances with a monitor are ones for which the
+ * caller has requested CC.
  */
-static struct ast_sched_thread *cc_sched_thread;
+static int match_agent(void *obj, void *arg, void *data, int flags)
+{
+	struct cc_core_instance *core_instance = obj;
+	const char *name = arg;
+	unsigned long match_flags = *(unsigned long *)data;
+	int possible_match = 0;
+
+	ast_log(LOG_NOTICE, "Iterating on %s, monitor is %p, and flags is %lu\n",
+			core_instance->agent->interface, core_instance->monitor, match_flags);
+	ast_log(LOG_NOTICE, "Oh and I'm searching for %s\n", name);
+
+	if ((match_flags & MATCH_NO_MONITOR) && !core_instance->monitor) {
+		possible_match = 1;
+	}
+
+	if ((match_flags & MATCH_MONITOR) && core_instance->monitor) {
+		possible_match = 1;
+	}
+
+	if (!possible_match) {
+		return 0;
+	}
+
+	if (!strcmp(core_instance->agent->interface, name)) {
+		return CMP_MATCH | CMP_STOP;
+	}
+	return 0;
+}
+
+/*!
+ * \brief Count the number of agents a specific interface is using
+ *
+ * We're only concerned with the number of agents that have requested
+ * CC, so we restrict our search to core instances which have a non-NULL
+ * monitor pointer
+ */
+static int count_agents_cb(void *obj, void *arg, void *data, int flags)
+{
+	struct cc_core_instance *core_instance = obj;
+	const char *name = arg;
+	long *count = data;
+
+	if (core_instance->monitor && !strcmp(core_instance->agent->interface, name)) {
+		(*count)++;
+	}
+	return 0;
+}
+
+static struct ao2_container *cc_monitors;
+
+static int cc_monitor_cmp_fn(void *obj, void *arg, int flags)
+{
+	struct ast_cc_monitor *monitor1 = obj;
+	struct ast_cc_monitor *monitor2 = arg;
+
+	if (!strcmp(monitor1->interface->name, monitor2->interface->name) &&
+			!strcmp(monitor1->interface->monitor_type, monitor2->interface->monitor_type)) {
+		return CMP_MATCH | CMP_STOP;
+	}
+	return 0;
+}
+
+static int cc_monitor_hash_fn(const void *obj, int flags)
+{
+	const struct ast_cc_monitor *monitor = obj;
+	return ast_str_hash_add(monitor->interface->monitor_type, ast_str_hash(monitor->interface->name));
+}
+
 /*!
  * \since 1.6.4
  * \brief A structure for holding the configuration parameters 
@@ -1249,94 +1367,6 @@
 	return 0;
 }
 
-struct ao2_container *cc_core_instances;
-struct ao2_container *cc_monitors;
-
-static const int CC_CORE_INSTANCES_BUCKETS = 17;
-
-static int cc_monitor_cmp_fn(void *obj, void *arg, int flags)
-{
-	struct ast_cc_monitor *monitor1 = obj;
-	struct ast_cc_monitor *monitor2 = arg;
-
-	if (!strcmp(monitor1->interface->name, monitor2->interface->name) &&
-			!strcmp(monitor1->interface->monitor_type, monitor2->interface->monitor_type)) {
-		return CMP_MATCH | CMP_STOP;
-	}
-	return 0;
-}
-
-static int cc_monitor_hash_fn(const void *obj, int flags)
-{
-	const struct ast_cc_monitor *monitor = obj;
-	return ast_str_hash_add(monitor->interface->monitor_type, ast_str_hash(monitor->interface->name));
-}
-
-struct cc_core_instance {
-	/*!
-	 * Unique identifier for this instance of the CC core.
-	 */ 
-	int core_id;
-	/*!
-	 * The current state for this instance of the CC core.
-	 */
-	enum ast_cc_state current_state;
-	/*!
-	 * The CC agent in use for this call
-	 */
-	struct ast_cc_agent *agent;
-	/*!
-	 * Reference to the root of the monitor tree
-	 */
-	struct ast_cc_monitor *monitor;
-};
-
-enum match_flags {
-	MATCH_NO_MONITOR = (1 << 0),
-	MATCH_MONITOR = (1 << 1),
-};
-
-static int match_agent(void *obj, void *arg, void *data, int flags)
-{
-	struct cc_core_instance *core_instance = obj;
-	const char *name = arg;
-	unsigned long match_flags = *(unsigned long *)data;
-	int possible_match = 0;
-
-	ast_log(LOG_NOTICE, "Iterating on %s, monitor is %p, and flags is %lu\n",
-			core_instance->agent->interface, core_instance->monitor, match_flags);
-	ast_log(LOG_NOTICE, "Oh and I'm searching for %s\n", name);
-
-	if ((match_flags & MATCH_NO_MONITOR) && !core_instance->monitor) {
-		possible_match = 1;
-	}
-
-	if ((match_flags & MATCH_MONITOR) && core_instance->monitor) {
-		possible_match = 1;
-	}
-
-	if (!possible_match) {
-		return 0;
-	}
-
-	if (!strcmp(core_instance->agent->interface, name)) {
-		return CMP_MATCH | CMP_STOP;
-	}
-	return 0;
-}
-
-static int count_agents_cb(void *obj, void *arg, void *data, int flags)
-{
-	struct cc_core_instance *core_instance = obj;
-	const char *name = arg;
-	long *count = data;
-
-	if (core_instance->monitor && !strcmp(core_instance->agent->interface, name)) {
-		(*count)++;
-	}
-	return 0;
-}
-
 static long count_agents(const char * const caller)
 {
 	long agent_count = 0;
@@ -1412,20 +1442,6 @@
 	if (core_instance->monitor) {
 		prune_links(core_instance->monitor, core_instance->core_id, NULL);
 	}
-}
-
-static int cc_core_instance_hash_fn(const void *obj, const int flags)
-{
-	const struct cc_core_instance *core_instance = obj;
-	return core_instance->core_id;
-}
-
-static int cc_core_instance_cmp_fn(void *obj, void *arg, int flags)
-{
-	struct cc_core_instance *core_instance1 = obj;
-	struct cc_core_instance *core_instance2 = arg;
-
-	return core_instance1->core_id == core_instance2->core_id ? CMP_MATCH | CMP_STOP : 0;
 }
 
 int ast_cc_core_init_instance(struct ast_channel *caller_chan, 




More information about the svn-commits mailing list