[asterisk-commits] jrose: branch jrose/call_identifiers r359978 - in /team/jrose/call_identifier...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Mar 20 12:08:07 CDT 2012


Author: jrose
Date: Tue Mar 20 12:08:04 2012
New Revision: 359978

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=359978
Log:
Added callid logging support for async_dial, mixmonitor, and call parking

Modified:
    team/jrose/call_identifiers/apps/app_mixmonitor.c
    team/jrose/call_identifiers/include/asterisk/logger.h
    team/jrose/call_identifiers/main/dial.c
    team/jrose/call_identifiers/main/features.c
    team/jrose/call_identifiers/main/logger.c

Modified: team/jrose/call_identifiers/apps/app_mixmonitor.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/call_identifiers/apps/app_mixmonitor.c?view=diff&rev=359978&r1=359977&r2=359978
==============================================================================
--- team/jrose/call_identifiers/apps/app_mixmonitor.c (original)
+++ team/jrose/call_identifiers/apps/app_mixmonitor.c Tue Mar 20 12:08:04 2012
@@ -240,6 +240,7 @@
 
 struct mixmonitor {
 	struct ast_audiohook audiohook;
+	struct ast_callid *callid;
 	char *filename;
 	char *filename_read;
 	char *filename_write;
@@ -395,6 +396,10 @@
 			ast_free(mixmonitor->name);
 			ast_free(mixmonitor->post_process);
 		}
+
+		if (mixmonitor->callid) {
+			ast_callid_unref(mixmonitor->callid);
+		}
 		ast_free(mixmonitor);
 	}
 }
@@ -440,6 +445,11 @@
 	int errflag = 0;
 	struct ast_format format_slin;
 
+	/* Keep callid association before any log messages */
+	if (mixmonitor->callid) {
+		ast_callid_threadassoc_add(mixmonitor->callid);
+	}
+
 	ast_verb(2, "Begin MixMonitor Recording %s\n", mixmonitor->name);
 
 	fs = &mixmonitor->mixmonitor_ds->fs;
@@ -672,6 +682,11 @@
 		ast_audiohook_destroy(&mixmonitor->audiohook);
 		mixmonitor_free(mixmonitor);
 		return;
+	}
+
+	if ((mixmonitor->callid = ast_read_threadstorage_callid())) {
+		ast_callid_ref(mixmonitor->callid);
+		/* reference be released at mixmonitor destruction */
 	}
 
 	ast_pthread_create_detached_background(&thread, NULL, mixmonitor_thread, mixmonitor);

Modified: team/jrose/call_identifiers/include/asterisk/logger.h
URL: http://svnview.digium.com/svn/asterisk/team/jrose/call_identifiers/include/asterisk/logger.h?view=diff&rev=359978&r1=359977&r2=359978
==============================================================================
--- team/jrose/call_identifiers/include/asterisk/logger.h (original)
+++ team/jrose/call_identifiers/include/asterisk/logger.h Tue Mar 20 12:08:04 2012
@@ -236,12 +236,23 @@
 /*!
  * \brief factory function to create a new uniquely identifying callid.
  *
- * \retval ast_callid struct pointer containing the call id (and other information if that route is taken)
+ * \retval ast_callid struct pointer containing the call id
  *
  * \note The newly created callid will be referenced upon creation and this function should be
  * paired with a call to ast_callid_unref()
  */
 struct ast_callid *ast_create_callid(void);
+
+/*!
+ * \brief extracts the callerid from the thread
+ *
+ * \revtal ast_callid struct pointer containing the call_id related to the thread
+ * \retval NULL if no call_id is present in the thread
+ *
+ * \note this reference is only guaranteed as valid as long as the thread it is pulled from is
+ * alive unless its reference is bumped.
+ */
+struct ast_callid *ast_read_threadstorage_callid(void);
 
 /*!
  * \brief Increase callid reference count

Modified: team/jrose/call_identifiers/main/dial.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/call_identifiers/main/dial.c?view=diff&rev=359978&r1=359977&r2=359978
==============================================================================
--- team/jrose/call_identifiers/main/dial.c (original)
+++ team/jrose/call_identifiers/main/dial.c Tue Mar 20 12:08:04 2012
@@ -50,6 +50,7 @@
 	void *user_data;                                   /*!< Attached user data */
 	AST_LIST_HEAD(, ast_dial_channel) channels; /*!< Channels being dialed */
 	pthread_t thread;                                  /*!< Thread (if running in async) */
+	struct ast_callid *callid;                         /*!< callid pointer (if running in async) */
 	ast_mutex_t lock;                                  /*! Lock to protect the thread information above */
 };
 
@@ -705,6 +706,9 @@
 static void *async_dial(void *data)
 {
 	struct ast_dial *dial = data;
+	if (dial->callid) {
+		ast_callid_threadassoc_add(dial->callid);
+	}
 
 	/* This is really really simple... we basically pass monitor_dial a NULL owner and it changes it's behavior */
 	monitor_dial(dial, NULL);
@@ -738,6 +742,10 @@
 
 	/* If we are running async spawn a thread and send it away... otherwise block here */
 	if (async) {
+		if ((dial->callid = ast_read_threadstorage_callid())) {
+			ast_callid_ref(dial->callid);
+			/* reference be released at dial destruction */
+		}
 		dial->state = AST_DIAL_RESULT_TRYING;
 		/* Try to create a thread */
 		if (ast_pthread_create(&dial->thread, NULL, async_dial, dial)) {
@@ -913,6 +921,11 @@
 	/* Lock be gone! */
 	ast_mutex_destroy(&dial->lock);
 
+	/* Get rid of the reference to the ast_callid */
+	if (dial->callid) {
+		ast_callid_unref(dial->callid);
+	}
+
 	/* Free structure */
 	ast_free(dial);
 

Modified: team/jrose/call_identifiers/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/call_identifiers/main/features.c?view=diff&rev=359978&r1=359977&r2=359978
==============================================================================
--- team/jrose/call_identifiers/main/features.c (original)
+++ team/jrose/call_identifiers/main/features.c Tue Mar 20 12:08:04 2012
@@ -814,6 +814,7 @@
 	struct ast_bridge_config bconfig;
 	struct ast_channel *chan;
 	struct ast_channel *peer;
+	struct ast_callid *callid;                             /*<! callid pointer (Only used to bind thread) */
 	unsigned int return_to_pbx:1;
 };
 
@@ -918,6 +919,12 @@
 {
 	struct ast_bridge_thread_obj *tobj = data;
 	int res;
+
+	if (tobj->callid) {
+		ast_callid_threadassoc_add(tobj->callid);
+		/* Need to deref and set to null since ast_bridge_thread_obj has no common destructor */
+		tobj->callid = ast_callid_unref(tobj->callid);
+	}
 
 	ast_channel_appl_set(tobj->chan, !tobj->return_to_pbx ? "Transferred Call" : "ManagerBridge");
 	ast_channel_data_set(tobj->chan, ast_channel_name(tobj->peer));
@@ -957,11 +964,16 @@
  *
  * Create thread and attributes, call bridge_call_thread
  */
-static void bridge_call_thread_launch(void *data) 
+static void bridge_call_thread_launch(struct ast_bridge_thread_obj *data) 
 {
 	pthread_t thread;
 	pthread_attr_t attr;
 	struct sched_param sched;
+
+	if ((data->callid = ast_read_threadstorage_callid())) {
+		ast_callid_ref(data->callid);
+		/* Needs to be dereffed and set to null immediately after the thread has associated it */
+	}
 
 	pthread_attr_init(&attr);
 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
@@ -8205,3 +8217,4 @@
 
 	return res;
 }
+

Modified: team/jrose/call_identifiers/main/logger.c
URL: http://svnview.digium.com/svn/asterisk/team/jrose/call_identifiers/main/logger.c?view=diff&rev=359978&r1=359977&r2=359978
==============================================================================
--- team/jrose/call_identifiers/main/logger.c (original)
+++ team/jrose/call_identifiers/main/logger.c Tue Mar 20 12:08:04 2012
@@ -1248,6 +1248,18 @@
 	return call;
 }
 
+struct ast_callid *ast_read_threadstorage_callid(void)
+{
+	struct ast_callid **callid;
+	callid = ast_threadstorage_get(&unique_callid, sizeof(struct ast_callid **));
+	if (callid && *callid) {
+		return *callid;
+	}
+
+	return NULL;
+
+}
+
 int ast_callid_threadassoc_add(struct ast_callid *callid)
 {
 	struct ast_callid **pointing;
@@ -1374,19 +1386,13 @@
 
 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
 {
-	struct ast_callid **callid;
+	struct ast_callid *callid;
 	va_list ap;
 
-	callid = ast_threadstorage_get(&unique_callid, sizeof(struct ast_callid **));
-
-	if (callid && *callid) {
-		va_start(ap, fmt);
-		ast_log_full(level, file, line, function, *callid, fmt, ap);
-		return;
-	}
+	callid = ast_read_threadstorage_callid();
 
 	va_start(ap, fmt);
-	ast_log_full(level, file, line, function, NULL, fmt, ap);
+	ast_log_full(level, file, line, function, callid, fmt, ap);
 	va_end(ap);
 }
 




More information about the asterisk-commits mailing list