[asterisk-commits] murf: branch group/newcdr r163447 - in /team/group/newcdr: cel/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 12 07:27:02 CST 2008


Author: murf
Date: Fri Dec 12 07:27:01 2008
New Revision: 163447

URL: http://svn.digium.com/view/asterisk?view=rev&rev=163447
Log:
A good place to checkpoint, maybe. A ton of now useless debug. 

I was getting stuck in the taskprocessor task execution, 
because the dummy channel creation needed to init the lock; 
the variable_helper func sets that lock.

And, last night as I was retiring for the night,
I realized that taskprocessor is not an appropriate
mechanism for this sort of usage; but it might
be for others.

But it all proves that taskprocessor works great
with multiple task engines.

The sqlite3 loading was subscribing to events way
too early; fixed that.

I need to correct formatting and get rid of the
debug. Stay tuned.


Modified:
    team/group/newcdr/cel/cel_csv.c
    team/group/newcdr/cel/cel_custom.c
    team/group/newcdr/cel/cel_manager.c
    team/group/newcdr/cel/cel_odbc.c
    team/group/newcdr/cel/cel_pgsql.c
    team/group/newcdr/cel/cel_radius.c
    team/group/newcdr/cel/cel_sqlite.c
    team/group/newcdr/cel/cel_sqlite3_custom.c
    team/group/newcdr/cel/cel_tds.c
    team/group/newcdr/main/cel.c
    team/group/newcdr/main/channel.c
    team/group/newcdr/main/event.c
    team/group/newcdr/main/taskprocessor.c

Modified: team/group/newcdr/cel/cel_csv.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/cel/cel_csv.c?view=diff&rev=163447&r1=163446&r2=163447
==============================================================================
--- team/group/newcdr/cel/cel_csv.c (original)
+++ team/group/newcdr/cel/cel_csv.c Fri Dec 12 07:27:01 2008
@@ -307,7 +307,7 @@
 	const char *cid_ani, *cid_rdnis, *cid_name, *cid_num, *cid_dnid;
 	const char *exten, *context, *channame, *appname, *appdata, *accountcode, *uniqueid, *userfield, *peer, *linkedid;
 	unsigned int amaflag;
-	
+	ast_log(LOG_NOTICE,"CEL csv logging\n");
 	eventtype = (enum ast_cel_eventtype)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TYPE);
 	eventtime.tv_sec = (time_t)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME);
 	eventtime.tv_usec = (time_t)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME_USEC);
@@ -329,7 +329,8 @@
 	amaflag = ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_AMAFLAGS);
 	userfield = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_USERFIELD);
 	peer = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_PEER);
-
+	ast_log(LOG_NOTICE,"About to output CSV record\n");
+	
 	snprintf(csvmaster, sizeof(csvmaster),"%s/%s/%s", ast_config_AST_LOG_DIR, CSV_LOG_DIR, CSV_MASTER);
 	if (build_csv_record(buf, sizeof(buf), eventtype, eventtime,userdefname, 
 						 cid_name, cid_num, cid_ani, cid_rdnis, cid_dnid, exten, context,
@@ -339,7 +340,9 @@
 		/* because of the absolutely unconditional need for the
 		   highest reliability possible in writing billing records,
 		   we open write and close the log file each time */
+		ast_log(LOG_NOTICE,"About to get mf lock\n");
 		ast_mutex_lock(&mf_lock);
+		ast_log(LOG_NOTICE,"Got mf lock\n");
 		mf = fopen(csvmaster, "a");
 		if (!mf) {
 			ast_log(LOG_ERROR, "Unable to re-open master file %s : %s\n", csvmaster, strerror(errno));
@@ -350,11 +353,16 @@
 			mf = NULL;
 		}
 		ast_mutex_unlock(&mf_lock);
+		ast_log(LOG_NOTICE,"released mf lock\n");
 		if (!ast_strlen_zero(accountcode)) {
+			ast_log(LOG_NOTICE,"About to write the accountcode=%s\n", accountcode);
 			if (writefile(buf, accountcode))
 				ast_log(LOG_WARNING, "Unable to write CSV record to account file '%s' : %s\n", accountcode, strerror(errno));
-		}
-	}
+			ast_log(LOG_NOTICE,"wrote the accountcode=%s\n", accountcode);
+		}
+	}
+	ast_log(LOG_NOTICE,"Returning!\n");
+	
 	return;
 }
 

Modified: team/group/newcdr/cel/cel_custom.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/cel/cel_custom.c?view=diff&rev=163447&r1=163446&r2=163447
==============================================================================
--- team/group/newcdr/cel/cel_custom.c (original)
+++ team/group/newcdr/cel/cel_custom.c Fri Dec 12 07:27:01 2008
@@ -114,24 +114,32 @@
 	struct ast_channel *tchan;
 
 	/* Abort if no master file is specified */
-	if (ast_strlen_zero(master))
+	ast_log(LOG_NOTICE,"Logging event to custom interface\n");
+	if (ast_strlen_zero(master)) {
+		ast_log(LOG_NOTICE,"master not defined. Logging aborted.\n");
 		return;
+	}
 
 	tchan = ast_cel_fabricate_channel_from_event(event);
 	if (!tchan) {
 		ast_log(LOG_ERROR, "Unable to fabricate channel from CEL event\n");
 		return;
 	}
+	ast_log(LOG_NOTICE,"fabricated\n");
 
 	memset(buf, 0 , sizeof(buf));
 	pbx_substitute_variables_helper(tchan, format, buf, sizeof(buf) - 1);
+	ast_log(LOG_NOTICE,"vars substituted => %s\n", buf);
 
 	ast_dummy_channel_free(tchan);
+	ast_log(LOG_NOTICE,"dummy channel freed\n");
 
 	/* because of the absolutely unconditional need for the
 	   highest reliability possible in writing billing records,
 	   we open write and close the log file each time */
+	ast_log(LOG_NOTICE,"about to get lock\n");
 	ast_mutex_lock(&mf_lock);
+	ast_log(LOG_NOTICE,"got lock\n");
 	mf = fopen(master, "a");
 	if (!mf) {
 		ast_log(LOG_ERROR, "Unable to re-open master file %s : %s\n", master, strerror(errno));
@@ -142,6 +150,7 @@
 		mf = NULL;
 	}
 	ast_mutex_unlock(&mf_lock);
+	ast_log(LOG_NOTICE,"released lock-- returning\n");
 	return;
 }
 
@@ -161,17 +170,20 @@
 {
 
 	if (!load_config(0)) {
+
 		event_sub = ast_event_subscribe(AST_EVENT_CEL, custom_log, "Custom CSV logging", NULL, AST_EVENT_IE_END);
 
-		if (mf)
-		{
+		if (mf) {
 			fclose(mf);
 			mf = NULL;
 		}
 		if (!event_sub) {
 			ast_log(LOG_ERROR, "Unable to register custom CEL handling\n");
 			return AST_MODULE_LOAD_DECLINE;
+		} else {
+			ast_log(LOG_NOTICE, "Subscribed to CEL events\n");
 		}
+		
 		return 0;
 	} else 
 		return AST_MODULE_LOAD_DECLINE;

Modified: team/group/newcdr/cel/cel_manager.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/cel/cel_manager.c?view=diff&rev=163447&r1=163446&r2=163447
==============================================================================
--- team/group/newcdr/cel/cel_manager.c (original)
+++ team/group/newcdr/cel/cel_manager.c Fri Dec 12 07:27:01 2008
@@ -140,6 +140,7 @@
 
 	if (!enablecel)
 		return;
+	ast_log(LOG_NOTICE,"Logging event to manager interface\n");
 
 	eventtype = (enum ast_cel_eventtype)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TYPE);
 	eventtime.tv_sec = (time_t)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME);

Modified: team/group/newcdr/cel/cel_odbc.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/cel/cel_odbc.c?view=diff&rev=163447&r1=163446&r2=163447
==============================================================================
--- team/group/newcdr/cel/cel_odbc.c (original)
+++ team/group/newcdr/cel/cel_odbc.c Fri Dec 12 07:27:01 2008
@@ -94,6 +94,7 @@
 	const char *exten, *context, *channame, *appname, *appdata, *accountcode, *uniqueid, *linkedid, *userfield, *peer;
 	unsigned int amaflag;
 
+	ast_log(LOG_NOTICE,"Logging event to odbc interface\n");
 	eventtype = (enum ast_cel_eventtype)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TYPE);
 	eventtime.tv_sec = (time_t)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME);
 	eventtime.tv_usec = (time_t)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME_USEC);

Modified: team/group/newcdr/cel/cel_pgsql.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/cel/cel_pgsql.c?view=diff&rev=163447&r1=163446&r2=163447
==============================================================================
--- team/group/newcdr/cel/cel_pgsql.c (original)
+++ team/group/newcdr/cel/cel_pgsql.c Fri Dec 12 07:27:01 2008
@@ -86,6 +86,7 @@
 	const char *exten, *context, *channame, *appname, *appdata, *accountcode, *peeraccount, *uniqueid, *linkedid, *userfield, *peer;
 	unsigned int amaflag;
 
+	ast_log(LOG_NOTICE,"Logging event to pgsql interface\n");
 	eventtype = (enum ast_cel_eventtype)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TYPE);
 	eventtime.tv_sec = (time_t)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME);
 	eventtime.tv_usec = (time_t)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME_USEC);

Modified: team/group/newcdr/cel/cel_radius.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/cel/cel_radius.c?view=diff&rev=163447&r1=163446&r2=163447
==============================================================================
--- team/group/newcdr/cel/cel_radius.c (original)
+++ team/group/newcdr/cel/cel_radius.c Fri Dec 12 07:27:01 2008
@@ -201,6 +201,7 @@
 	const char *exten, *context, *channame, *appname, *appdata, *accountcode, *uniqueid, *linkedid;
 	unsigned int amaflag;
 	
+	ast_log(LOG_NOTICE,"Logging event to radius interface\n");
 	eventtype = (enum ast_cel_eventtype)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TYPE);
 	eventtime.tv_sec = (time_t)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME);
 	eventtime.tv_usec = (time_t)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME_USEC);

Modified: team/group/newcdr/cel/cel_sqlite.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/cel/cel_sqlite.c?view=diff&rev=163447&r1=163446&r2=163447
==============================================================================
--- team/group/newcdr/cel/cel_sqlite.c (original)
+++ team/group/newcdr/cel/cel_sqlite.c Fri Dec 12 07:27:01 2008
@@ -110,6 +110,7 @@
 	const char *exten, *context, *channame, *appname, *appdata, *accountcode, *uniqueid, *userfield, *peer, *linkedid;
 	unsigned int amaflag;
 	
+	ast_log(LOG_NOTICE,"Logging event to sqlite interface\n");
 	eventtype = (enum ast_cel_eventtype)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TYPE);
 	eventtime.tv_sec = (time_t)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME);
 	eventtime.tv_usec = (time_t)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME_USEC);

Modified: team/group/newcdr/cel/cel_sqlite3_custom.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/cel/cel_sqlite3_custom.c?view=diff&rev=163447&r1=163446&r2=163447
==============================================================================
--- team/group/newcdr/cel/cel_sqlite3_custom.c (original)
+++ team/group/newcdr/cel/cel_sqlite3_custom.c Fri Dec 12 07:27:01 2008
@@ -162,6 +162,7 @@
 	struct ast_channel *tchan;
 	int count;
 
+	ast_log(LOG_NOTICE,"Logging event to sqlite3 interface\n");
 	tchan = ast_cel_fabricate_channel_from_event(event);
 	if (!tchan) {
 		ast_log(LOG_ERROR, "Unable to fabricate channel from CEL event\n");
@@ -218,14 +219,9 @@
 	int res;
 	char *sql_cmd;
 
-	if (!load_config(0) == AST_MODULE_LOAD_SUCCESS) {
-		event_sub = ast_event_subscribe(AST_EVENT_CEL, sqlite3_log, "CEL sqlist3_custom backend", NULL, AST_EVENT_IE_END);
-		if (!event_sub) {
-			ast_log(LOG_ERROR, "%s: Unable to register custom SQLite3 CEL handling\n", name);
-			return AST_MODULE_LOAD_DECLINE;
-		}
-	} else
-		return AST_MODULE_LOAD_DECLINE;
+	if (load_config(0) != AST_MODULE_LOAD_SUCCESS) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
 	
 	/* is the database there? */
 	snprintf(fn, sizeof(fn), "%s/master.db", ast_config_AST_LOG_DIR);
@@ -258,6 +254,11 @@
 			return AST_MODULE_LOAD_DECLINE;
 		}
 	}
+	event_sub = ast_event_subscribe(AST_EVENT_CEL, sqlite3_log, "CEL sqlist3_custom backend", NULL, AST_EVENT_IE_END);
+	if (!event_sub) {
+		ast_log(LOG_ERROR, "%s: Unable to register custom SQLite3 CEL handling\n", name);
+		return AST_MODULE_LOAD_DECLINE;
+	}
 
 	return AST_MODULE_LOAD_SUCCESS;
 }

Modified: team/group/newcdr/cel/cel_tds.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/cel/cel_tds.c?view=diff&rev=163447&r1=163446&r2=163447
==============================================================================
--- team/group/newcdr/cel/cel_tds.c (original)
+++ team/group/newcdr/cel/cel_tds.c Fri Dec 12 07:27:01 2008
@@ -126,6 +126,7 @@
 	const char *eventname;
 	unsigned int amaflag;
 
+	ast_log(LOG_NOTICE,"Logging event to TDS interface\n");
 	eventtype = (enum ast_cel_eventtype)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TYPE);
 	eventtime.tv_sec = (time_t)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME);
 	eventtime.tv_usec = (time_t)ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME_USEC);

Modified: team/group/newcdr/main/cel.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/main/cel.c?view=diff&rev=163447&r1=163446&r2=163447
==============================================================================
--- team/group/newcdr/main/cel.c (original)
+++ team/group/newcdr/main/cel.c Fri Dec 12 07:27:01 2008
@@ -572,16 +572,16 @@
 							   AST_EVENT_IE_CEL_EVENT_TIME, AST_EVENT_IE_PLTYPE_UINT, eventtime.tv_sec,
 							   AST_EVENT_IE_CEL_EVENT_TIME_USEC, AST_EVENT_IE_PLTYPE_UINT, eventtime.tv_usec,
 							   AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_STR, udef,
-							   AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR, chan->cid.cid_name,
-							   AST_EVENT_IE_CEL_CIDNUM, AST_EVENT_IE_PLTYPE_STR, chan->cid.cid_num,
-							   AST_EVENT_IE_CEL_CIDANI, AST_EVENT_IE_PLTYPE_STR, chan->cid.cid_ani,
-							   AST_EVENT_IE_CEL_CIDRDNIS, AST_EVENT_IE_PLTYPE_STR, chan->cid.cid_rdnis,
-							   AST_EVENT_IE_CEL_CIDDNID, AST_EVENT_IE_PLTYPE_STR, chan->cid.cid_dnid,
+							   AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR, S_OR(chan->cid.cid_name,""),
+							   AST_EVENT_IE_CEL_CIDNUM, AST_EVENT_IE_PLTYPE_STR, S_OR(chan->cid.cid_num,""),
+							   AST_EVENT_IE_CEL_CIDANI, AST_EVENT_IE_PLTYPE_STR, S_OR(chan->cid.cid_ani,""),
+							   AST_EVENT_IE_CEL_CIDRDNIS, AST_EVENT_IE_PLTYPE_STR, S_OR(chan->cid.cid_rdnis,""),
+							   AST_EVENT_IE_CEL_CIDDNID, AST_EVENT_IE_PLTYPE_STR, S_OR(chan->cid.cid_dnid,""),
 							   AST_EVENT_IE_CEL_EXTEN, AST_EVENT_IE_PLTYPE_STR, chan->exten,
 							   AST_EVENT_IE_CEL_CONTEXT, AST_EVENT_IE_PLTYPE_STR, chan->context,
 							   AST_EVENT_IE_CEL_CHANNAME, AST_EVENT_IE_PLTYPE_STR, chan->name,
-							   AST_EVENT_IE_CEL_APPNAME, AST_EVENT_IE_PLTYPE_STR, chan->appl,
-							   AST_EVENT_IE_CEL_APPDATA, AST_EVENT_IE_PLTYPE_STR, chan->data,
+							   AST_EVENT_IE_CEL_APPNAME, AST_EVENT_IE_PLTYPE_STR, S_OR(chan->appl,""),
+							   AST_EVENT_IE_CEL_APPDATA, AST_EVENT_IE_PLTYPE_STR, S_OR(chan->data,""),
 							   AST_EVENT_IE_CEL_AMAFLAGS, AST_EVENT_IE_PLTYPE_UINT, chan->amaflags,
 							   AST_EVENT_IE_CEL_ACCTCODE, AST_EVENT_IE_PLTYPE_STR, chan->accountcode,
 							   AST_EVENT_IE_CEL_PEERACCT, AST_EVENT_IE_PLTYPE_STR, chan->peeraccount,
@@ -592,6 +592,7 @@
 							   AST_EVENT_IE_CEL_PEER, AST_EVENT_IE_PLTYPE_STR, peername,
 							   AST_EVENT_IE_END);
 			if (!ev) {
+				ast_log(LOG_NOTICE,"NULL event returned\n");
 				return;
 			}
 			ast_event_queue(ev); /* a lot of stuff happens here */

Modified: team/group/newcdr/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/main/channel.c?view=diff&rev=163447&r1=163446&r2=163447
==============================================================================
--- team/group/newcdr/main/channel.c (original)
+++ team/group/newcdr/main/channel.c Fri Dec 12 07:27:01 2008
@@ -978,6 +978,7 @@
 	ast_string_field_init(chan, 128);
 	headp = &chan->varshead;
 	AST_LIST_HEAD_INIT_NOLOCK(headp);
+	ast_mutex_init(&chan->lock_dont_use); /* for the sake of var_helper */
 
 	return chan;
 }
@@ -1447,6 +1448,7 @@
 		free((char*)chan->appl);
 	if (chan->data)
 		free((char*)chan->data);
+	ast_mutex_destroy(&chan->lock_dont_use);
 	
 	free(chan);
 }

Modified: team/group/newcdr/main/event.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/main/event.c?view=diff&rev=163447&r1=163446&r2=163447
==============================================================================
--- team/group/newcdr/main/event.c (original)
+++ team/group/newcdr/main/event.c Fri Dec 12 07:27:01 2008
@@ -1119,6 +1119,7 @@
 	if (ast_event_check_subscriber(host_event_type, AST_EVENT_IE_END) 
 		== AST_EVENT_SUB_NONE) {
 		ast_event_destroy(event);
+		ast_log(LOG_NOTICE, "Event destroyed, no subscriber\n");
 		return 0;
 	}
 

Modified: team/group/newcdr/main/taskprocessor.c
URL: http://svn.digium.com/view/asterisk/team/group/newcdr/main/taskprocessor.c?view=diff&rev=163447&r1=163446&r2=163447
==============================================================================
--- team/group/newcdr/main/taskprocessor.c (original)
+++ team/group/newcdr/main/taskprocessor.c Fri Dec 12 07:27:01 2008
@@ -284,11 +284,13 @@
 	}
 
 	while (i->poll_thread_run) {
+		ast_log(LOG_NOTICE,"task loop begun\n");
  		ast_mutex_lock(&i->taskprocessor_lock);
  		if (!i->poll_thread_run) {
   			ast_mutex_unlock(&i->taskprocessor_lock);
  			break;
   		}
+		ast_log(LOG_NOTICE,"loop 2\n");
  		if (!(size = tps_taskprocessor_depth(i))) {
  			ast_cond_wait(&i->poll_cond, &i->taskprocessor_lock);
   			if (!i->poll_thread_run) {
@@ -296,19 +298,23 @@
 	  			break;
 			}
   		}
+		ast_log(LOG_NOTICE,"loop 3\n");
   		ast_mutex_unlock(&i->taskprocessor_lock);
  		/* stuff is in the queue */
  		if (!(t = tps_taskprocessor_pop(i))) {
  			ast_log(LOG_ERROR, "Wtf?? %d tasks in the queue, but we're popping blanks!\n", size);
  			continue;
  		}
+		ast_log(LOG_NOTICE,"loop 4\n");
  		if (!t->execute) {
  			ast_log(LOG_WARNING, "Task is missing a function to execute!\n");
  			tps_task_free(t);
  			continue;
  		}
+		ast_log(LOG_NOTICE,"loop 5\n");
  		t->execute(t->datap);
- 
+		ast_log(LOG_NOTICE,"Task returns\n");
+		
  		ast_mutex_lock(&i->taskprocessor_lock);
  		if (i->stats) {
  			i->stats->_tasks_processed_count++;
@@ -317,8 +323,10 @@
  			}
  		}
  		ast_mutex_unlock(&i->taskprocessor_lock);
+		ast_log(LOG_NOTICE,"stats tweaked\n");
  
  		tps_task_free(t);
+		ast_log(LOG_NOTICE,"task destroyed\n");
   	}
 	while ((t = tps_taskprocessor_pop(i))) {
 		tps_task_free(t);




More information about the asterisk-commits mailing list