[asterisk-commits] mmichelson: branch group/CCSS_Monitor_Restructure r242977 - /team/group/CCSS_...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jan 25 16:08:50 CST 2010
Author: mmichelson
Date: Mon Jan 25 16:08:46 2010
New Revision: 242977
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=242977
Log:
Update chan_sip to conform to the new restructured monitor.
Next up comes tests. A lot of tests.
Modified:
team/group/CCSS_Monitor_Restructure/channels/chan_sip.c
Modified: team/group/CCSS_Monitor_Restructure/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS_Monitor_Restructure/channels/chan_sip.c?view=diff&rev=242977&r1=242976&r2=242977
==============================================================================
--- team/group/CCSS_Monitor_Restructure/channels/chan_sip.c (original)
+++ team/group/CCSS_Monitor_Restructure/channels/chan_sip.c Mon Jan 25 16:08:46 2010
@@ -3589,8 +3589,8 @@
AST_STRING_FIELD(subscribe_uri);
AST_STRING_FIELD(notify_uri);
AST_STRING_FIELD(peername);
+ AST_STRING_FIELD(device_name);
);
- struct ast_cc_monitor *monitor;
int core_id;
struct sip_pvt *subscription_pvt;
struct sip_epa_entry *suspension_entry;
@@ -3625,13 +3625,10 @@
transmit_publish(monitor_instance->suspension_entry, SIP_PUBLISH_REMOVE ,monitor_instance->notify_uri);
ao2_ref(monitor_instance->suspension_entry, -1);
}
- if (monitor_instance->monitor) {
- ao2_ref(monitor_instance->monitor, -1);
- }
ast_string_field_free_memory(monitor_instance);
}
-static struct sip_monitor_instance *sip_monitor_instance_init(int core_id, const char * const subscribe_uri, const char * const peername)
+static struct sip_monitor_instance *sip_monitor_instance_init(int core_id, const char * const subscribe_uri, const char * const peername, const char * const device_name)
{
struct sip_monitor_instance *monitor_instance = ao2_alloc(sizeof(*monitor_instance), sip_monitor_instance_destructor);
@@ -3646,17 +3643,12 @@
ast_string_field_set(monitor_instance, subscribe_uri, subscribe_uri);
ast_string_field_set(monitor_instance, peername, peername);
+ ast_string_field_set(monitor_instance, device_name, device_name);
monitor_instance->core_id = core_id;
ao2_link(sip_monitor_instances, monitor_instance);
return monitor_instance;
}
-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 find_sip_monitor_instance_by_subscription_pvt(void *obj, void *arg, int flags)
{
struct sip_monitor_instance *monitor_instance = obj;
@@ -3669,37 +3661,27 @@
return monitor_instance->suspension_entry == arg ? CMP_MATCH | CMP_STOP : 0;
}
-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);
-static int sip_cc_monitor_suspend(struct ast_cc_monitor *monitor, const int core_id);
-static int sip_cc_monitor_status_response(struct ast_cc_monitor *monitor, const int core_id, enum ast_device_state devstate);
-static int sip_cc_monitor_unsuspend(struct ast_cc_monitor *monitor, const int core_id);
-static int sip_cc_monitor_cancel_available_timer(struct ast_cc_monitor *monitor, const int core_id, int *sched_id);
-static void sip_cc_monitor_destructor(struct ast_cc_monitor *monitor);
-static void sip_cc_monitor_instance_destructor(const int core_id);
+static int sip_cc_monitor_request_cc(struct ast_cc_monitor *monitor, int *available_timer_id);
+static int sip_cc_monitor_suspend(struct ast_cc_monitor *monitor);
+static int sip_cc_monitor_status_response(struct ast_cc_monitor *monitor, enum ast_device_state devstate);
+static int sip_cc_monitor_unsuspend(struct ast_cc_monitor *monitor);
+static int sip_cc_monitor_cancel_available_timer(struct ast_cc_monitor *monitor, int *sched_id);
+static void sip_cc_monitor_destructor(void *private_data);
static struct ast_cc_monitor_callbacks sip_cc_monitor_callbacks = {
.type = "SIP",
- .init = sip_cc_monitor_init,
.request_cc = sip_cc_monitor_request_cc,
.suspend = sip_cc_monitor_suspend,
.status_response = sip_cc_monitor_status_response,
.unsuspend = sip_cc_monitor_unsuspend,
.cancel_available_timer = sip_cc_monitor_cancel_available_timer,
.destructor = sip_cc_monitor_destructor,
- .instance_destructor = sip_cc_monitor_instance_destructor,
};
-static int sip_cc_monitor_init(struct ast_cc_monitor *monitor, const int core_id)
-{
- /* 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)
-{
- struct sip_monitor_instance *monitor_instance = find_sip_monitor_instance(core_id);
- enum ast_cc_service_type service = parent_link->service;
+static int sip_cc_monitor_request_cc(struct ast_cc_monitor *monitor, int *available_timer_id)
+{
+ struct sip_monitor_instance *monitor_instance = monitor->private_data;
+ enum ast_cc_service_type service = monitor->service_offered;
int when;
if (!monitor_instance) {
@@ -3710,9 +3692,6 @@
return -1;
}
- monitor_instance->monitor = monitor;
- ao2_ref(monitor_instance->monitor, +1);
-
when = service == AST_CC_CCBS ? ast_get_ccbs_available_timer(monitor->interface->config_params) :
ast_get_ccnr_available_timer(monitor->interface->config_params);
@@ -3725,8 +3704,8 @@
transmit_invite(monitor_instance->subscription_pvt, SIP_SUBSCRIBE, FALSE, 2, monitor_instance->subscribe_uri);
sip_pvt_unlock(monitor_instance->subscription_pvt);
- parent_link->child_avail_id = ast_sched_add(sched, when * 1000, ast_cc_available_timer_expire, parent_link);
- ao2_ref(monitor_instance, -1);
+ ao2_t_ref(monitor, +1, "Adding a ref to the monitor for the scheduler");
+ *available_timer_id = ast_sched_add(sched, when * 1000, ast_cc_available_timer_expire, monitor);
return 0;
}
@@ -3751,9 +3730,9 @@
return 0;
}
-static int sip_cc_monitor_suspend(struct ast_cc_monitor *monitor, const int core_id)
-{
- struct sip_monitor_instance *monitor_instance = find_sip_monitor_instance(core_id);
+static int sip_cc_monitor_suspend(struct ast_cc_monitor *monitor)
+{
+ struct sip_monitor_instance *monitor_instance = monitor->private_data;
enum sip_publish_type publish_type;
if (!monitor_instance) {
@@ -3775,11 +3754,10 @@
construct_pidf_body(CC_CLOSED, monitor_instance->suspension_entry->body, sizeof(monitor_instance->suspension_entry->body));
transmit_publish(monitor_instance->suspension_entry, publish_type, monitor_instance->notify_uri);
- ao2_ref(monitor_instance, -1);
return 0;
}
-static int sip_cc_monitor_status_response(struct ast_cc_monitor *monitor, const int core_id, enum ast_device_state devstate)
+static int sip_cc_monitor_status_response(struct ast_cc_monitor *monitor, enum ast_device_state devstate)
{
/* This will never be called because the SIP monitor will never make a status request to
* begin with
@@ -3787,9 +3765,9 @@
return 0;
}
-static int sip_cc_monitor_unsuspend(struct ast_cc_monitor *monitor, const int core_id)
-{
- struct sip_monitor_instance *monitor_instance = find_sip_monitor_instance(core_id);
+static int sip_cc_monitor_unsuspend(struct ast_cc_monitor *monitor)
+{
+ struct sip_monitor_instance *monitor_instance = monitor->private_data;
if (!monitor_instance) {
return -1;
@@ -3800,31 +3778,22 @@
construct_pidf_body(CC_OPEN, monitor_instance->suspension_entry->body, sizeof(monitor_instance->suspension_entry->body));
transmit_publish(monitor_instance->suspension_entry, SIP_PUBLISH_MODIFY, monitor_instance->notify_uri);
- ao2_ref(monitor_instance, -1);
return 0;
}
-static int sip_cc_monitor_cancel_available_timer(struct ast_cc_monitor *monitor, const int core_id, int *sched_id)
+static int sip_cc_monitor_cancel_available_timer(struct ast_cc_monitor *monitor, int *sched_id)
{
if (*sched_id != -1) {
AST_SCHED_DEL(sched, *sched_id);
+ ao2_t_ref(monitor, -1, "Removing scheduler's reference to the monitor");
}
return 0;
}
-static void sip_cc_monitor_destructor(struct ast_cc_monitor *monitor)
-{
- /* Nothing to do here. */
-}
-
-static void sip_cc_monitor_instance_destructor(const int core_id)
-{
- struct sip_monitor_instance *monitor_instance = find_sip_monitor_instance(core_id);
- if (!monitor_instance) {
- return;
- }
+static void sip_cc_monitor_destructor(void *private_data)
+{
+ struct sip_monitor_instance *monitor_instance = private_data;
ao2_unlink(sip_monitor_instances, monitor_instance);
- ao2_ref(monitor_instance, -1);
}
static int sip_get_cc_information(struct sip_request *req, char *subscribe_uri, size_t size, enum ast_cc_service_type *service)
@@ -3916,6 +3885,7 @@
if (monitor_policy == AST_CC_MONITOR_ALWAYS || monitor_policy == AST_CC_MONITOR_NATIVE) {
char subscribe_uri[SIPBUFSIZE];
+ char device_name[AST_CHANNEL_NAME];
enum ast_cc_service_type offered_service;
struct sip_monitor_instance *monitor_instance;
if (sip_get_cc_information(req, subscribe_uri, sizeof(subscribe_uri), &offered_service)) {
@@ -3925,19 +3895,20 @@
*/
goto generic;
}
- if (!(monitor_instance = sip_monitor_instance_init(core_id, subscribe_uri, pvt->peername))) {
+ ast_channel_get_device_name(pvt->owner, device_name, sizeof(device_name));
+ if (!(monitor_instance = sip_monitor_instance_init(core_id, subscribe_uri, pvt->peername, device_name))) {
/* Same deal. We can try using generic still */
goto generic;
}
/* We're all set! */
- ast_queue_cc_frame(pvt->owner, "SIP", interface_name, offered_service);
+ ast_queue_cc_frame(pvt->owner, "SIP", interface_name, offered_service, monitor_instance);
ao2_ref(monitor_instance, -1);
return;
}
generic:
if (monitor_policy == AST_CC_MONITOR_GENERIC || monitor_policy == AST_CC_MONITOR_ALWAYS) {
- ast_queue_cc_frame(pvt->owner, AST_CC_GENERIC_MONITOR_TYPE, interface_name, service);
+ ast_queue_cc_frame(pvt->owner, AST_CC_GENERIC_MONITOR_TYPE, interface_name, service, NULL);
}
}
@@ -6793,7 +6764,6 @@
struct varshead *headp;
struct ast_var_t *current;
const char *referer = NULL; /* SIP referrer */
- struct sip_monitor_instance *monitor_instance = NULL;
int cc_core_id;
char uri[SIPBUFSIZE] = "";
@@ -6803,18 +6773,15 @@
}
if (ast_cc_is_recall(ast, &cc_core_id, "SIP")) {
- /* If this is a CC recall, then we have a particular
- * URI that we are supposed to send the INVITE to. We
- * get this information from the corresponding sip_monitor_instance
- */
- if (!(monitor_instance = find_sip_monitor_instance(cc_core_id))) {
- /* UM... */
- ast_log(LOG_WARNING, "This is a recall, but we can't find an appropriate sip_monitor_instance with core ID %d.\n", cc_core_id);
- /* We'll still try to continue with things. They just may not work as planned... */
- } else {
+ char device_name[AST_CHANNEL_NAME];
+ struct ast_cc_monitor *recall_monitor;
+ struct sip_monitor_instance *monitor_instance;
+ ast_channel_get_device_name(ast, device_name, sizeof(device_name));
+ if ((recall_monitor = ast_cc_get_monitor_by_recall_core_id(cc_core_id, device_name))) {
+ monitor_instance = recall_monitor->private_data;
ast_copy_string(uri, monitor_instance->notify_uri, sizeof(uri));
- ao2_ref(monitor_instance, -1);
- }
+ }
+ ao2_t_ref(recall_monitor, -1, "Got the URI we need so unreffing monitor");
}
/* Check whether there is vxml_url, distinctive ring variables */
@@ -19744,7 +19711,7 @@
}
if (resp != 423) {
- ast_cc_monitor_failed(cc_entry->core_id, monitor_instance->monitor->interface->name,
+ ast_cc_monitor_failed(cc_entry->core_id, monitor_instance->device_name,
"Received error response to our PUBLISH");
ao2_ref(monitor_instance, -1);
return;
@@ -19763,13 +19730,13 @@
pvt->expiry *= 2;
if (pvt->expiry < 0) {
/* You dork! You overflowed! */
- ast_cc_monitor_failed(cc_entry->core_id, monitor_instance->monitor->interface->name,
+ ast_cc_monitor_failed(cc_entry->core_id, monitor_instance->device_name,
"PUBLISH expiry overflowed");
ao2_ref(monitor_instance, -1);
return;
}
} else if (sscanf(min_expires, "%d", &pvt->expiry) != 1) {
- ast_cc_monitor_failed(cc_entry->core_id, monitor_instance->monitor->interface->name,
+ ast_cc_monitor_failed(cc_entry->core_id, monitor_instance->device_name,
"Min-Expires has non-numeric value");
ao2_ref(monitor_instance, -1);
return;
@@ -21389,7 +21356,7 @@
}
ast_string_field_set(monitor_instance, notify_uri, uri);
- ast_cc_monitor_callee_available(monitor_instance->monitor);
+ ast_cc_monitor_callee_available(monitor_instance->core_id);
ao2_ref(monitor_instance, -1);
transmit_response(pvt, "200 OK", req);
More information about the asterisk-commits
mailing list