[asterisk-commits] branch file/func_supertimeout - r7324 /team/file/func_supertimeout/funcs/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Dec 3 22:38:11 CST 2005


Author: file
Date: Sat Dec  3 22:38:10 2005
New Revision: 7324

URL: http://svn.digium.com/view/asterisk?rev=7324&view=rev
Log:
Switch to using name based lookup in channel.c, deprecate cdr-timeout, and deprecate another function.

Modified:
    team/file/func_supertimeout/funcs/func_supertimeout.c

Modified: team/file/func_supertimeout/funcs/func_supertimeout.c
URL: http://svn.digium.com/view/asterisk/team/file/func_supertimeout/funcs/func_supertimeout.c?rev=7324&r1=7323&r2=7324&view=diff
==============================================================================
--- team/file/func_supertimeout/funcs/func_supertimeout.c (original)
+++ team/file/func_supertimeout/funcs/func_supertimeout.c Sat Dec  3 22:38:10 2005
@@ -41,8 +41,6 @@
 #include "asterisk/app.h"
 
 static char *tdesc = "Super Timeout Function";
-static char *cdr_desc = "Timeout CDR Handler";
-static char *cdr_name = "cdr-timeout";
 
 /* Timeout types */
 #define TYPE_ANSWER 1
@@ -52,7 +50,7 @@
 
 /* Structure to represent a channel to timeout */
 struct timeout {
-  char *channel_name; /* Channel name of owner - used for cdr-timeout */
+  char *channel_name; /* Channel name of owner */
   struct ast_channel *channel; /* Channel to timeout */
   time_t start; /* Start time of timeout */
   unsigned int timeout; /* Actual timeout amount */
@@ -97,26 +95,6 @@
 
 }
 
-/* Signal channel owner death to other timeouts */
-static void signal_owner_death(struct ast_channel *chan)
-{
-  struct timeout *timeout = NULL;
-
-  /* This assumes it is locked before calling */
-  timeout = timeouts;
-  while (timeout) {
-    /* Only signal death if they are us... and not already dead */
-    if (timeout->channel == chan && timeout->dead != 1) {
-      /* Get rid of owner channel and signal death... */
-      timeout->channel = NULL;
-      timeout->dead = 1;
-      timeout->type = -1;
-    }
-    timeout = timeout->next;
-  }
-
-}
-
 /* Background timeout thread */
 static void *timeout_proc(void *arg)
 {
@@ -128,21 +106,29 @@
     ast_mutex_lock(&timeout_lock);
     timeout = timeouts;
     while (timeout) {
+      /* Make sure the channel still exists - if not, kill this */
+      if (timeout->type != -1 && timeout->dead != 1) {
+	/* Update the channel based on the name */
+	timeout->channel = ast_get_channel_by_name_locked(timeout->channel_name);
+	if (timeout->channel == NULL)
+	  signal_owner_death_by_name(timeout->channel_name);
+      }
       /* Check the type so we can do different things */
       switch (timeout->type) {
+      case -1:
+	/* Invalid catcher */
+	break;
       case TYPE_ANSWER:
 	if (timeout->active != 1) {
-	  /* We aren't active yet... so see if we were answered so we can switch to active! */
-	  ast_mutex_lock(&timeout->channel->lock);
 	  if (timeout->channel->_state == AST_STATE_UP) {
 	    /* Switch to active state and record time */
 	    timeout->active = 1;
 	    time(&timeout->start);
 	  }
-	  ast_mutex_unlock(&timeout->channel->lock);
 	} else if ((now-timeout->start) >= timeout->timeout) {
 	  timeout->dead = 1;
-	  signal_owner_death(timeout->channel);
+	  ast_mutex_unlock(&timeout->channel->lock);
+	  signal_owner_death_by_name(timeout->channel_name);
 	}
 	break;
       case TYPE_ABSOLUTE:
@@ -153,11 +139,11 @@
 	/* Do standard time check... if positive - switch to dead state */
 	if ((now-timeout->start) >= timeout->timeout) {
 	  timeout->dead = 1;
-	  signal_owner_death(timeout->channel);
+	  ast_mutex_unlock(&timeout->channel->lock);
+	  signal_owner_death_by_name(timeout->channel_name);
 	}
 	break;
       case TYPE_STATE:
-	ast_mutex_lock(&timeout->channel->lock);
 	if (timeout->state != timeout->channel->_state && ((now-timeout->start) < timeout->timeout)) {
 	  /* The state changed within the timeout... so we're okay! */
 	  timeout->dead = 1;
@@ -170,8 +156,6 @@
 	  timeout->dead = 1;
 	  ast_mutex_unlock(&timeout->channel->lock);
 	  timeout->channel = NULL;
-	} else {
-	  ast_mutex_unlock(&timeout->channel->lock);
 	}
 	break;
       case TYPE_SIGSEGV:
@@ -187,6 +171,8 @@
 	/* If we got here we really don't care... */
 	break;
       }
+      if (timeout->channel != NULL)
+	ast_mutex_unlock(&timeout->channel->lock);
       if (timeout->dead == 1) {
 	/* Hangup the channel if applicable */
         if (timeout->channel != NULL) {
@@ -221,17 +207,6 @@
   }
 
   return NULL;
-}
-
-/* CDR handler (essentially we get called whenever the call is hungup */
-static int timeout_cdr(struct ast_cdr *cdr)
-{
-
-  ast_mutex_lock(&timeout_lock);
-  signal_owner_death_by_name(cdr->channel);
-  ast_mutex_unlock(&timeout_lock);
-
-  return 0;
 }
 
 /* Conversion from string to numerical value for timeout types */
@@ -366,7 +341,6 @@
 {
 
   kill_thread_proc();
-  ast_cdr_unregister(cdr_name);
   ast_custom_function_unregister(&group_timeout_function);
   
   STANDARD_HANGUP_LOCALUSERS;
@@ -381,16 +355,9 @@
     ast_log(LOG_ERROR, "Failed to spawn timeout handling thread!\n");
     return -1;
   }
-  /* Register CDR handler so we have some record of hangup */
-  if (ast_cdr_register(cdr_name, cdr_desc, timeout_cdr)) {
-    kill_thread_proc();
-    ast_log(LOG_ERROR, "Failed to register CDR Timeout handler\n");
-    return -1;
-  }
   /* Register the dialplan function */
   if (ast_custom_function_register(&group_timeout_function)) {
     kill_thread_proc();
-    ast_cdr_unregister(cdr_name);
     ast_log(LOG_ERROR, "Failed to register GROUP_TIMEOUT function\n");
     return -1;
   }



More information about the asterisk-commits mailing list