[asterisk-commits] mmichelson: branch group/CCSS r236181 - /team/group/CCSS/channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Dec 22 17:18:52 CST 2009


Author: mmichelson
Date: Tue Dec 22 17:18:50 2009
New Revision: 236181

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=236181
Log:
Begin filling in some monitor callbacks for SIP CC.


Modified:
    team/group/CCSS/channels/chan_sip.c

Modified: team/group/CCSS/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/channels/chan_sip.c?view=diff&rev=236181&r1=236180&r2=236181
==============================================================================
--- team/group/CCSS/channels/chan_sip.c (original)
+++ team/group/CCSS/channels/chan_sip.c Tue Dec 22 17:18:50 2009
@@ -3570,6 +3570,8 @@
  * generic monitoring is very device-oriented, SIP monitoring is actually very call-oriented.
  */
 
+struct ao2_container *sip_monitor_instances;
+
 struct sip_monitor_instance {
 	struct ast_cc_monitor *monitor;
 	int core_id;
@@ -3578,6 +3580,55 @@
 	char subscribe_uri[SIPBUFSIZE];
 	char notify_uri[SIPBUFSIZE];
 };
+
+static int sip_monitor_instance_hash_fn(const void *obj, const int flags)
+{
+	const struct sip_monitor_instance *monitor_instance = obj;
+	return monitor_instance->core_id;
+}
+
+static int sip_monitor_instance_cmp_fn(void *obj, void *arg, int flags)
+{
+	struct sip_monitor_instance *monitor_instance1 = obj;
+	struct sip_monitor_instance *monitor_instance2 = arg;
+
+	return monitor_instance1->core_id == monitor_instance2->core_id ? CMP_MATCH | CMP_STOP : 0;
+}
+
+static void sip_monitor_instance_destructor(void *data)
+{
+	struct sip_monitor_instance *monitor_instance = data;
+	if (monitor_instance->subscription_pvt) {
+		dialog_unref(monitor_instance->subscription_pvt, "Unref monitor instance ref of subscription pvt");
+	}
+	if (monitor_instance->publish_pvt) {
+		dialog_unref(monitor_instance->publish_pvt, "Unref monitor instance ref of publish pvt");
+	}
+	if (monitor_instance->monitor) {
+		ao2_ref(monitor_instance->monitor, -1);
+	}
+}
+
+static struct sip_monitor_instance *sip_monitor_instance_init(int core_id, const char * const subscribe_uri)
+{
+	struct sip_monitor_instance *monitor_instance = ao2_alloc(sizeof(*monitor_instance), sip_monitor_instance_destructor);
+
+	if (!monitor_instance) {
+		return NULL;
+	}
+
+	ast_copy_string(monitor_instance->subscribe_uri, subscribe_uri, sizeof(monitor_instance->subscribe_uri));
+	monitor_instance->core_id = core_id;
+	ao2_link(sip_monitor_instances, monitor_instance);
+	/* Get rid of ref from allocation */
+	ao2_ref(monitor_instance, -1);
+}
+
+static struct sip_monitor_instance *find_sip_monitor_instance(int core_id)
+{
+	struct sip_monitor_instance finder = { .core_id = core_id };
+	return ao2_find(sip_monitor_instances, &finder, OBJ_POINTER);
+}
 
 static int sip_cc_monitor_init(struct ast_cc_monitor *monitor, const int core_id);
 static int sip_cc_monitor_request_cc(struct ast_cc_monitor *monitor, const int core_id, struct ast_cc_monitor_link *parent_link);
@@ -3602,19 +3653,26 @@
 
 static int sip_cc_monitor_init(struct ast_cc_monitor *monitor, const int core_id)
 {
-	/* We don't really need to do anything here.
-	 */
+	/* Nothing to do here */
 	return 0;
 }
 
 static int sip_cc_monitor_request_cc(struct ast_cc_monitor *monitor, const int core_id, struct ast_cc_monitor_link *parent_link)
 {
 	/* XXX STUB */
+	struct sip_monitor_instance *monitor_instance = find_sip_monitor_instance(core_id);
+
+	if (!monitor_instance) {
+		return -1;
+	}
+
 	/* Find the appropriate sip_monitor_instance based on the given core_id.
+	 * Point the sip_monitor_instance monitor field at the monitor param
 	 * Allocate the sip_monitor_instance subscription_pvt
 	 * Send a SUBSCRIBE to the subscribe_uri
 	 * Start the available timer using information from the parent link. 
 	 */
+	ao2_ref(monitor_instance, -1);
 	return 0;
 }
 
@@ -28565,6 +28623,9 @@
 	if (ast_cc_monitor_register(&sip_cc_monitor_callbacks)) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
+	if (!(sip_monitor_instances = ao2_container_alloc(37, sip_monitor_instance_hash_fn, sip_monitor_instance_cmp_fn))) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
 
 	/* And start the monitor for the first time */
 	restart_monitor();




More information about the asterisk-commits mailing list