[asterisk-commits] trunk - r7573 /trunk/apps/app_realtime.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Dec 21 09:16:09 CST 2005


Author: tilghman
Date: Wed Dec 21 09:16:08 2005
New Revision: 7573

URL: http://svn.digium.com/view/asterisk?rev=7573&view=rev
Log:
Bug 5734 - add status variables indicating the success or failure of the realtime apps

Modified:
    trunk/apps/app_realtime.c

Modified: trunk/apps/app_realtime.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_realtime.c?rev=7573&r1=7572&r2=7573&view=diff
==============================================================================
--- trunk/apps/app_realtime.c (original)
+++ trunk/apps/app_realtime.c Wed Dec 21 09:16:08 2005
@@ -53,13 +53,18 @@
 static char *usynopsis = "Realtime Data Rewrite";
 static char *USAGE = "RealTime(<family>|<colmatch>|<value>[|<prefix>])";
 static char *UUSAGE = "RealTimeUpdate(<family>|<colmatch>|<value>|<newcol>|<newval>)";
-static char *desc = "Use the RealTime config handler system to read data into channel variables.\n"
+static char *desc =
+"Use the RealTime config handler system to read data into channel variables.\n"
 "RealTime(<family>|<colmatch>|<value>[|<prefix>])\n\n"
-"All unique column names will be set as channel variables with optional prefix to the name.\n"
-"e.g. prefix of 'var_' would make the column 'name' become the variable ${var_name}\n\n";
+"All unique column names will be set as channel variables with optional prefix\n"
+"to the name.  For example, a prefix of 'var_' would make the column 'name'\n"
+"become the variable ${var_name}.  REALTIMECOUNT will be set with the number\n"
+"of values read.\n";
 static char *udesc = "Use the RealTime config handler system to update a value\n"
 "RealTimeUpdate(<family>|<colmatch>|<value>|<newcol>|<newval>)\n\n"
-"The column <newcol> in 'family' matching column <colmatch>=<value> will be updated to <newval>\n";
+"The column <newcol> in 'family' matching column <colmatch>=<value> will be\n"
+"updated to <newval>.  REALTIMECOUNT will be set with the number of rows\n"
+"updated or -1 if an error occurs.\n";
 
 STANDARD_LOCAL_USER;
 LOCAL_USER_DECL;
@@ -130,7 +135,8 @@
 {
 	char *family=NULL, *colmatch=NULL, *value=NULL, *newcol=NULL, *newval=NULL;
 	struct localuser *u;
-	int res = 0;
+	int res = 0, count = 0;
+	char countc[13];
 
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_ERROR,"Invalid input: usage %s\n",UUSAGE);
@@ -156,8 +162,11 @@
 		ast_log(LOG_ERROR,"Invalid input: usage %s\n",UUSAGE);
 		res = -1;
 	} else {
-		ast_update_realtime(family,colmatch,value,newcol,newval,NULL);
-	}
+		count = ast_update_realtime(family,colmatch,value,newcol,newval,NULL);
+	}
+
+	snprintf(countc, sizeof(countc), "%d", count);
+	pbx_builtin_setvar_helper(chan, "REALTIMECOUNT", countc);
 
 	LOCAL_USER_REMOVE(u);
 	
@@ -167,10 +176,11 @@
 
 static int realtime_exec(struct ast_channel *chan, void *data)
 {
-	int res=0;
+	int res=0, count=0;
 	struct localuser *u;
 	struct ast_variable *var, *itt;
 	char *family=NULL, *colmatch=NULL, *value=NULL, *prefix=NULL, *vname=NULL;
+	char countc[13];
 	size_t len;
 		
 	if (ast_strlen_zero(data)) {
@@ -207,11 +217,14 @@
 					vname = itt->name;
 
 				pbx_builtin_setvar_helper(chan, vname, itt->value);
+				count++;
 			}
 			ast_variables_destroy(var);
 		} else if (option_verbose > 3)
 			ast_verbose(VERBOSE_PREFIX_4"No Realtime Matches Found.\n");
 	}
+	snprintf(countc, sizeof(countc), "%d", count);
+	pbx_builtin_setvar_helper(chan, "REALTIMECOUNT", countc);
 	
 	LOCAL_USER_REMOVE(u);
 	return res;



More information about the asterisk-commits mailing list