[asterisk-commits] file: branch file/groupcountv2 r61803 - in /team/file/groupcountv2: ./ apps/ ...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Apr 25 11:38:15 MST 2007


Author: file
Date: Wed Apr 25 13:38:14 2007
New Revision: 61803

URL: http://svn.digium.com/view/asterisk?view=rev&rev=61803
Log:
Return the use of group show channels, GROUP, and GROUP_LIST.

Modified:
    team/file/groupcountv2/app.c
    team/file/groupcountv2/apps/app_groupcount.c
    team/file/groupcountv2/funcs/func_groupcount.c
    team/file/groupcountv2/include/asterisk/app.h

Modified: team/file/groupcountv2/app.c
URL: http://svn.digium.com/view/asterisk/team/file/groupcountv2/app.c?view=diff&rev=61803&r1=61802&r2=61803
==============================================================================
--- team/file/groupcountv2/app.c (original)
+++ team/file/groupcountv2/app.c Wed Apr 25 13:38:14 2007
@@ -51,13 +51,6 @@
 #include "asterisk/linkedlists.h"
 
 #define MAX_OTHER_FORMATS 10
-
-struct ast_group_info {
-	struct ast_channel *chan;
-	char *category;
-	char *group;
-	AST_LIST_ENTRY(ast_group_info) list;
-};
 
 static AST_LIST_HEAD_STATIC(groups, ast_group_info);
 
@@ -1135,6 +1128,21 @@
 	AST_LIST_UNLOCK(&groups);
 
 	return 0;
+}
+
+int ast_app_group_list_lock(void)
+{
+	return AST_LIST_LOCK(&groups);
+}
+
+struct ast_group_info *ast_app_group_list_head(void)
+{
+	return AST_LIST_FIRST(&groups);
+}
+
+int ast_app_group_list_unlock(void)
+{
+	return AST_LIST_UNLOCK(&groups);
 }
 
 unsigned int ast_app_separate_args(char *buf, char delim, char **array, int arraylen)

Modified: team/file/groupcountv2/apps/app_groupcount.c
URL: http://svn.digium.com/view/asterisk/team/file/groupcountv2/apps/app_groupcount.c?view=diff&rev=61803&r1=61802&r2=61803
==============================================================================
--- team/file/groupcountv2/apps/app_groupcount.c (original)
+++ team/file/groupcountv2/apps/app_groupcount.c Wed Apr 25 13:38:14 2007
@@ -201,10 +201,8 @@
 {
 #define FORMAT_STRING  "%-25s  %-20s  %-20s\n"
 
-	struct ast_channel *c = NULL;
 	int numchans = 0;
-	struct ast_var_t *current;
-	struct varshead *headp;
+	struct ast_group_info *gi = NULL;
 	regex_t regexbuf;
 	int havepattern = 0;
 
@@ -218,6 +216,19 @@
 	}
 
 	ast_cli(fd, FORMAT_STRING, "Channel", "Group", "Category");
+
+	ast_app_group_list_lock();
+
+	gi = ast_app_group_list_head();
+	while (gi) {
+		if (!havepattern || !regexec(&regexbuf, gi->group, 0, NULL, 0)) {
+			ast_cli(fd, FORMAT_STRING, gi->chan->name, gi->group, (ast_strlen_zero(gi->category) ? "(default)" : gi->category));
+			numchans++;
+		}
+		gi = AST_LIST_NEXT(gi, list);
+	}
+
+	ast_app_group_list_unlock();
 
 	if (havepattern)
 		regfree(&regexbuf);

Modified: team/file/groupcountv2/funcs/func_groupcount.c
URL: http://svn.digium.com/view/asterisk/team/file/groupcountv2/funcs/func_groupcount.c?view=diff&rev=61803&r1=61802&r2=61803
==============================================================================
--- team/file/groupcountv2/funcs/func_groupcount.c (original)
+++ team/file/groupcountv2/funcs/func_groupcount.c Wed Apr 25 13:38:14 2007
@@ -93,6 +93,26 @@
 
 static char *group_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
 {
+        struct ast_group_info *gi = NULL;
+
+        ast_app_group_list_lock();
+
+        gi = ast_app_group_list_head();
+        while (gi) {
+                if (gi->chan != chan)
+                        continue;
+                if (ast_strlen_zero(data))
+                        break;
+                if (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, data))
+                        break;
+                gi = AST_LIST_NEXT(gi, list);
+        }
+
+        if (gi)
+                ast_copy_string(buf, gi->group, len);
+
+        ast_app_group_list_unlock();
+
 	return buf;
 }
 
@@ -124,6 +144,35 @@
 
 static char *group_list_function_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
 {
+        struct ast_group_info *gi = NULL;
+        char tmp1[1024] = "";
+        char tmp2[1024] = "";
+
+        ast_app_group_list_lock();
+
+        gi = ast_app_group_list_head();
+        while (gi) {
+                if (gi->chan != chan)
+                        continue;
+                if (!ast_strlen_zero(tmp1)) {
+                        ast_copy_string(tmp2, tmp1, sizeof(tmp2));
+                        if (!ast_strlen_zero(gi->category))
+                                snprintf(tmp1, sizeof(tmp1), "%s %s@%s", tmp2, gi->group, gi->category);
+                        else
+                                snprintf(tmp1, sizeof(tmp1), "%s %s", tmp2, gi->group);
+                } else {
+                        if (!ast_strlen_zero(gi->category))
+                                snprintf(tmp1, sizeof(tmp1), "%s@%s", gi->group, gi->category);
+                        else
+                                snprintf(tmp1, sizeof(tmp1), "%s", gi->group);
+                }
+                gi = AST_LIST_NEXT(gi, list);
+        }
+
+        ast_app_group_list_unlock();
+
+        ast_copy_string(buf, tmp1, len);
+
 	return buf;
 }
 

Modified: team/file/groupcountv2/include/asterisk/app.h
URL: http://svn.digium.com/view/asterisk/team/file/groupcountv2/include/asterisk/app.h?view=diff&rev=61803&r1=61802&r2=61803
==============================================================================
--- team/file/groupcountv2/include/asterisk/app.h (original)
+++ team/file/groupcountv2/include/asterisk/app.h Wed Apr 25 13:38:14 2007
@@ -166,6 +166,13 @@
 /*! Read a file into asterisk*/
 char *ast_read_textfile(const char *file);
 
+struct ast_group_info {
+	struct ast_channel *chan;
+	char *category;
+	char *group;
+	AST_LIST_ENTRY(ast_group_info) list;
+};
+
 /*! Split a group string into group and category, returning a default category if none is provided. */
 int ast_app_group_split_group(char *data, char *group, int group_max, char *category, int category_max);
 
@@ -180,6 +187,15 @@
 
 /*! Discard all group counting for a channel */
 int ast_app_group_discard(struct ast_channel *chan);
+
+/*! Lock the group count list */
+int ast_app_group_list_lock(void);
+
+/*! Get the head of the group count list */
+struct ast_group_info *ast_app_group_list_head(void);
+
+/*! Unlock the group count list */
+int ast_app_group_list_unlock(void);
 
 /*!
   \brief Define an application argument



More information about the asterisk-commits mailing list