[asterisk-commits] eliel: branch group/data_api_gsoc2009 r207215 - in /team/group/data_api_gsoc2...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 17 15:32:18 CDT 2009


Author: eliel
Date: Fri Jul 17 15:32:14 2009
New Revision: 207215

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=207215
Log:
Complete the CLI command 'queue show' with the callers.


Modified:
    team/group/data_api_gsoc2009/apps/app_queue.c
    team/group/data_api_gsoc2009/include/asterisk/channel.h
    team/group/data_api_gsoc2009/include/asterisk/data.h
    team/group/data_api_gsoc2009/main/channel.c
    team/group/data_api_gsoc2009/main/data.c

Modified: team/group/data_api_gsoc2009/apps/app_queue.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/apps/app_queue.c?view=diff&rev=207215&r1=207214&r2=207215
==============================================================================
--- team/group/data_api_gsoc2009/apps/app_queue.c (original)
+++ team/group/data_api_gsoc2009/apps/app_queue.c Fri Jul 17 15:32:14 2009
@@ -6316,15 +6316,14 @@
 static char *__queues_show(struct mansession *s, int fd, int argc, const char * const *argv)
 {
 	struct ast_str *out = ast_str_alloca(240);
-	//int found = 0;
-	//time_t now = time(NULL);
-	struct ast_data *queues, *queue, *member;
-	struct ast_data_iterator *iq, *im;
+	time_t now = time(NULL);
+	struct ast_data *queues, *queue, *member, *caller;
+	struct ast_data_iterator *iq, *im, *ic;
 	struct ast_data_query query = {
 		.path = "asterisk/application/app_queue/queues",
 	};
 	float sl;
-	int callscompleted, has_members = 0, penalty, calls;
+	int callscompleted, has_members, has_callers, penalty, calls;
 	const char *name, *membername, *interface;
 
 	if (argc != 2 && argc != 3) {
@@ -6342,10 +6341,16 @@
 	iq = ast_data_iterator_init(queues, "queue");
 	if (!iq) {
 		ast_data_free(queues);
-		return CLI_FAILURE;
+		if (argc == 3) {
+			ast_str_set(&out, 0, "No such queue: %s.", argv[2]);
+		} else {
+			ast_str_set(&out, 0, "No queues.");
+		}
+		do_print(s, fd, ast_str_buffer(out));
 	}
 
 	while ((queue = ast_data_iterator_next(iq))) {
+		/* print queue statistics. */
 		name = ast_data_retrieve_string(queue, "name");
 		if (argc == 3 && strcasecmp(name, argv[2])) {
 			continue;
@@ -6379,53 +6384,71 @@
 
 		do_print(s, fd, ast_str_buffer(out));
 
+		/* print members. */
 		has_members = 0;
 		im  = ast_data_iterator_init(queue, "members/member");
-		while ((member = ast_data_iterator_next(im))) {
-			if (!has_members) {
-				do_print(s, fd, "   Members: ");
-			}
-			has_members++;
-			membername = ast_data_retrieve_string(member, "membername");
-			ast_str_set(&out, 0, "      %s", membername); 
-			interface = ast_data_retrieve_string(member, "interface");
-
-			if (strcasecmp(membername, interface)) {
-				ast_str_append(&out, 0, " (%s)", interface);
-			}
-
-			penalty = ast_data_retrieve_int(member, "penalty");
-			if (penalty) {
-				ast_str_append(&out, 0, " with penalty %d", penalty);
-			}
-
-			ast_str_append(&out, 0, "%s%s%s (%s)",
-				ast_data_retrieve_int(member, "dynamic") ? " (dynamic)" : "",
-				ast_data_retrieve_int(member, "realtime") ? " (realtime)" : "",
-				ast_data_retrieve_int(member, "paused") ? " (paused)" : "",
-				ast_devstate2str(ast_data_retrieve_int(member, "status")));
-			calls = ast_data_retrieve_int(member, "calls");
-
-			if (calls) {
-				ast_str_append(&out, 0, " has taken %d calls (last was %ld secs ago)",
-					calls, (long) (time(NULL) -
-					ast_data_retrieve_int(member, "lastcall")));
-			} else {
-				ast_str_append(&out, 0, " has taken no calls yet");
-			}
-			do_print(s, fd, ast_str_buffer(out));
-		}
-		ast_data_iterator_end(im);
-		if (!has_members) {
+		if (im) {
+			while ((member = ast_data_iterator_next(im))) {
+				if (!has_members) {
+					do_print(s, fd, "   Members: ");
+				}
+				has_members++;
+				membername = ast_data_retrieve_string(member, "membername");
+				ast_str_set(&out, 0, "      %s", membername); 
+				interface = ast_data_retrieve_string(member, "interface");
+
+				if (strcasecmp(membername, interface)) {
+					ast_str_append(&out, 0, " (%s)", interface);
+				}
+
+				penalty = ast_data_retrieve_int(member, "penalty");
+				if (penalty) {
+					ast_str_append(&out, 0, " with penalty %d", penalty);
+				}
+
+				ast_str_append(&out, 0, "%s%s%s (%s)",
+						ast_data_retrieve_int(member, "dynamic") ? " (dynamic)" : "",
+						ast_data_retrieve_int(member, "realtime") ? " (realtime)" : "",
+						ast_data_retrieve_int(member, "paused") ? " (paused)" : "",
+						ast_devstate2str(ast_data_retrieve_int(member, "status")));
+				calls = ast_data_retrieve_int(member, "calls");
+
+				if (calls) {
+					ast_str_append(&out, 0, " has taken %d calls (last was %ld secs ago)",
+							calls, (long) (time(NULL) -
+								ast_data_retrieve_int(member, "lastcall")));
+				} else {
+					ast_str_append(&out, 0, " has taken no calls yet");
+				}
+				do_print(s, fd, ast_str_buffer(out));
+			}
+			ast_data_iterator_end(im);
+		} else {
 			do_print(s, fd, "   No Members");
 		}
+
+		/* print callers */
+		has_callers = 0;
+		ic = ast_data_iterator_init(queue, "callers/caller");
+		if (ic) {
+			do_print(s, fd, "   Callers: ");
+			while ((caller = ast_data_iterator_next(ic))) {
+				ast_str_set(&out, 0, "      %d. %s (wait: %ld:%2.2ld, prio: %d)",
+						ast_data_retrieve_int(caller, "pos"),
+						ast_data_retrieve_string(caller, "channel/name"),
+						(long) (now - ast_data_retrieve_int(caller, "start")) / 60,
+						(long) (now - ast_data_retrieve_int(caller, "start")) % 60,
+						ast_data_retrieve_int(caller, "prio"));
+				do_print(s, fd, ast_str_buffer(out));
+			}
+			ast_data_iterator_end(ic);
+		} else {
+			do_print(s, fd, "   No Callers");
+		}
 	}
 	ast_data_iterator_end(iq);
 
 #if 0
-		if (!q->head)
-			do_print(s, fd, "   No Callers");
-		else {
 			struct queue_ent *qe;
 			int pos = 1;
 
@@ -7525,7 +7548,7 @@
 	struct member *member;
 	struct queue_ent *qe;
 	struct ast_data *data_queue = NULL, *data_members = NULL;
-	struct ast_data *data_member, *data_callers = NULL, *data_caller;
+	struct ast_data *data_member, *data_callers = NULL, *data_caller, *data_caller_channel;
 
 	/* compare the search pattern. */
 	if (ast_data_search_cmp_structure(search, call_queue, queue, "queues/queue")) {
@@ -7592,12 +7615,19 @@
 				}
 			}
 
-			data_caller = ast_data_add_node(data_queue, "caller");
+			data_caller = ast_data_add_node(data_callers, "caller");
 			if (!data_caller) {
 				continue;
 			}
 
 			ast_data_add_structure(queue_ent, data_caller, qe);
+
+			data_caller_channel = ast_data_add_node(data_caller, "channel");
+			if (!data_caller_channel) {
+				continue;
+			}
+
+			ast_channel_data_add_structure(data_caller_channel, qe->chan);
 		}
 	}
 

Modified: team/group/data_api_gsoc2009/include/asterisk/channel.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/include/asterisk/channel.h?view=diff&rev=207215&r1=207214&r2=207215
==============================================================================
--- team/group/data_api_gsoc2009/include/asterisk/channel.h (original)
+++ team/group/data_api_gsoc2009/include/asterisk/channel.h Fri Jul 17 15:32:14 2009
@@ -148,6 +148,7 @@
 #include "asterisk/linkedlists.h"
 #include "asterisk/stringfields.h"
 #include "asterisk/datastore.h"
+#include "asterisk/data.h"
 
 #define DATASTORE_INHERIT_FOREVER	INT_MAX
 
@@ -2640,6 +2641,16 @@
  * 	'0'
  */
 int ast_channel_connected_line_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *connected_info, int caller, int frame);
+
+/*!
+ * \brief Insert into an astdata tree, the channel structure.
+ * \param[in] tree The ast data tree.
+ * \param[in] chan The channel structure to add to tree.
+ * \retval <0 on error.
+ * \retval 0 on success.
+ */
+int ast_channel_data_add_structure(struct ast_data *tree, struct ast_channel *chan);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/group/data_api_gsoc2009/include/asterisk/data.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/include/asterisk/data.h?view=diff&rev=207215&r1=207214&r2=207215
==============================================================================
--- team/group/data_api_gsoc2009/include/asterisk/data.h (original)
+++ team/group/data_api_gsoc2009/include/asterisk/data.h Fri Jul 17 15:32:14 2009
@@ -567,7 +567,10 @@
 int ast_data_retrieve(struct ast_data *tree, const char *path, struct ast_data_retrieve *content); 
 
 /*!
- * \brief
+ * \brief Retrieve the integer value of a node.
+ * \param[in] tree The tree from where to get the value.
+ * \param[in] path The node name or path.
+ * \returns The value of the node. 
  */
 static inline int ast_data_retrieve_int(struct ast_data *tree, const char *path)
 {
@@ -578,6 +581,12 @@
 	return ret.value.AST_DATA_INTEGER;
 }
 
+/*!
+ * \brief Retrieve the boolean value of a node.
+ * \param[in] tree The tree from where to get the value.
+ * \param[in] path The node name or path.
+ * \returns The value of the node. 
+ */
 static inline unsigned int ast_data_retrieve_bool(struct ast_data *tree, const char *path)
 {
 	struct ast_data_retrieve ret;
@@ -587,6 +596,12 @@
 	return ret.value.AST_DATA_BOOLEAN;
 }
 
+/*!
+ * \brief Retrieve the unsigned integer value of a node.
+ * \param[in] tree The tree from where to get the value.
+ * \param[in] path The node name or path.
+ * \returns The value of the node. 
+ */
 static inline unsigned int ast_data_retrieve_uint(struct ast_data *tree, const char *path)
 {
 	struct ast_data_retrieve ret;
@@ -596,6 +611,12 @@
 	return ret.value.AST_DATA_UNSIGNED_INTEGER;
 }
 
+/*!
+ * \brief Retrieve the string value of a node.
+ * \param[in] tree The tree from where to get the value.
+ * \param[in] path The node name or path.
+ * \returns The value of the node. 
+ */
 static inline const char *ast_data_retrieve_string(struct ast_data *tree, const char *path)
 {
 	struct ast_data_retrieve ret;
@@ -605,6 +626,12 @@
 	return ret.value.AST_DATA_STRING;
 }
 
+/*!
+ * \brief Retrieve the ptr value of a node.
+ * \param[in] tree The tree from where to get the value.
+ * \param[in] path The node name or path.
+ * \returns The value of the node. 
+ */
 static inline void *ast_data_retrieve_ptr(struct ast_data *tree, const char *path)
 {
 	struct ast_data_retrieve ret;
@@ -614,6 +641,27 @@
 	return ret.value.AST_DATA_POINTER;
 }
 
+/*!
+ * \brief Retrieve the double value of a node.
+ * \param[in] tree The tree from where to get the value.
+ * \param[in] path The node name or path.
+ * \returns The value of the node. 
+ */
+static inline double ast_data_retrieve_dbl(struct ast_data *tree, const char *path)
+{
+	struct ast_data_retrieve ret;
+
+	ast_data_retrieve(tree, path, &ret);
+
+	return ret.value.AST_DATA_DOUBLE;
+}
+
+/*!
+ * \brief Retrieve the ipv4 address value of a node.
+ * \param[in] tree The tree from where to get the value.
+ * \param[in] path The node name or path.
+ * \returns The value of the node. 
+ */
 static inline struct in_addr ast_data_retrieve_ipaddr(struct ast_data *tree, const char *path)
 {
 	struct ast_data_retrieve ret;

Modified: team/group/data_api_gsoc2009/main/channel.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/main/channel.c?view=diff&rev=207215&r1=207214&r2=207215
==============================================================================
--- team/group/data_api_gsoc2009/main/channel.c (original)
+++ team/group/data_api_gsoc2009/main/channel.c Fri Jul 17 15:32:14 2009
@@ -64,6 +64,7 @@
 #include "asterisk/timing.h"
 #include "asterisk/autochan.h"
 #include "asterisk/stringfields.h"
+#include "asterisk/data.h"
 
 #ifdef HAVE_EPOLL
 #include <sys/epoll.h>
@@ -131,6 +132,52 @@
 #else
 #define NUM_CHANNEL_BUCKETS 1567
 #endif
+
+#define DATA_EXPORT_CHANNEL(MEMBER)						\
+	MEMBER(ast_channel, blockproc, AST_DATA_STRING)				\
+	MEMBER(ast_channel, appl, AST_DATA_STRING)				\
+	MEMBER(ast_channel, data, AST_DATA_STRING)				\
+	MEMBER(ast_channel, name, AST_DATA_STRING)				\
+	MEMBER(ast_channel, language, AST_DATA_STRING)				\
+	MEMBER(ast_channel, musicclass, AST_DATA_STRING)			\
+	MEMBER(ast_channel, accountcode, AST_DATA_STRING)			\
+	MEMBER(ast_channel, peeraccount, AST_DATA_STRING)			\
+	MEMBER(ast_channel, userfield, AST_DATA_STRING)				\
+	MEMBER(ast_channel, call_forward, AST_DATA_STRING)			\
+	MEMBER(ast_channel, uniqueid, AST_DATA_STRING)				\
+	MEMBER(ast_channel, linkedid, AST_DATA_STRING)				\
+	MEMBER(ast_channel, parkinglot, AST_DATA_STRING)			\
+	MEMBER(ast_channel, hangupsource, AST_DATA_STRING)			\
+	MEMBER(ast_channel, dialcontext, AST_DATA_STRING)			\
+	MEMBER(ast_channel, _softhangup, AST_DATA_INTEGER)			\
+	MEMBER(ast_channel, streamid, AST_DATA_INTEGER)				\
+	MEMBER(ast_channel, vstreamid, AST_DATA_INTEGER)			\
+	MEMBER(ast_channel, oldwriteformat, AST_DATA_INTEGER)			\
+	MEMBER(ast_channel, _state, AST_DATA_INTEGER)				\
+	MEMBER(ast_channel, rings, AST_DATA_INTEGER)				\
+	MEMBER(ast_channel, priority, AST_DATA_INTEGER)				\
+	MEMBER(ast_channel, macropriority, AST_DATA_INTEGER)			\
+	MEMBER(ast_channel, amaflags, AST_DATA_INTEGER)				\
+	MEMBER(ast_channel, adsicpe, AST_DATA_INTEGER)				\
+	MEMBER(ast_channel, fin, AST_DATA_UNSIGNED_INTEGER)			\
+	MEMBER(ast_channel, fout, AST_DATA_UNSIGNED_INTEGER)			\
+	MEMBER(ast_channel, hangupcause, AST_DATA_INTEGER)			\
+	MEMBER(ast_channel, flags, AST_DATA_UNSIGNED_INTEGER)			\
+	MEMBER(ast_channel, nativeformats, AST_DATA_INTEGER)			\
+	MEMBER(ast_channel, readformat, AST_DATA_INTEGER)			\
+	MEMBER(ast_channel, writeformat, AST_DATA_INTEGER)			\
+	MEMBER(ast_channel, rawreadformat, AST_DATA_INTEGER)			\
+	MEMBER(ast_channel, rawwriteformat, AST_DATA_INTEGER)			\
+	MEMBER(ast_channel, emulate_dtmf_duration, AST_DATA_UNSIGNED_INTEGER)	\
+	MEMBER(ast_channel, visible_indication, AST_DATA_INTEGER)		\
+	MEMBER(ast_channel, transfercapability, AST_DATA_INTEGER)		\
+	MEMBER(ast_channel, context, AST_DATA_STRING)				\
+	MEMBER(ast_channel, exten, AST_DATA_STRING)				\
+	MEMBER(ast_channel, macrocontext, AST_DATA_STRING)			\
+	MEMBER(ast_channel, macroexten, AST_DATA_STRING)
+
+AST_DATA_STRUCTURE(ast_channel, DATA_EXPORT_CHANNEL);
+
 
 /*! \brief All active channels on the system */
 static struct ao2_container *channels;
@@ -208,6 +255,11 @@
 	AST_RWLIST_UNLOCK(&backends);
 
 	return var;
+}
+
+int ast_channel_data_add_structure(struct ast_data *tree, struct ast_channel *chan)
+{
+	return ast_data_add_structure(ast_channel, tree, chan);
 }
 
 /*! \brief Show channel types - CLI command */

Modified: team/group/data_api_gsoc2009/main/data.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/data_api_gsoc2009/main/data.c?view=diff&rev=207215&r1=207214&r2=207215
==============================================================================
--- team/group/data_api_gsoc2009/main/data.c (original)
+++ team/group/data_api_gsoc2009/main/data.c Fri Jul 17 15:32:14 2009
@@ -1343,8 +1343,6 @@
 
 	child = data_result_find_child(node, next_node_name(&savepath));
 	if (!child) {
-		ast_log(LOG_ERROR, "Unable to find node '%s' inside '%s'\n",
-				path, node->name);
 		return NULL;
 	}
 




More information about the asterisk-commits mailing list