[asterisk-commits] eliel: branch group/data_api_gsoc2009 r253533 - /team/group/data_api_gsoc2009...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Mar 19 12:39:02 CDT 2010
Author: eliel
Date: Fri Mar 19 12:38:59 2010
New Revision: 253533
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=253533
Log:
Cleanup the __queues_show(), don't use the data API here.
Modified:
team/group/data_api_gsoc2009/apps/app_queue.c
Modified: team/group/data_api_gsoc2009/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/team/group/data_api_gsoc2009/apps/app_queue.c?view=diff&rev=253533&r1=253532&r2=253533
==============================================================================
--- team/group/data_api_gsoc2009/apps/app_queue.c (original)
+++ team/group/data_api_gsoc2009/apps/app_queue.c Fri Mar 19 12:38:59 2010
@@ -6530,17 +6530,6 @@
ast_cli(fd, "%s\n", str);
}
-/*! \brief Print that no queues where found. */
-static void do_print_noqueues(struct ast_str *out, struct mansession *s, int fd, const char *queue)
-{
- if (queue) {
- ast_str_set(&out, 0, "No such queue: %s.", queue);
- } else {
- ast_str_set(&out, 0, "No queues.");
- }
- do_print(s, fd, ast_str_buffer(out));
-}
-
/*!
* \brief Show queue(s) status and statistics
*
@@ -6549,152 +6538,129 @@
*/
static char *__queues_show(struct mansession *s, int fd, int argc, const char * const *argv)
{
- struct ast_str *out = ast_str_alloca(240), *search = NULL;
+ struct call_queue *q;
+ struct ast_str *out = ast_str_alloca(240);
+ int found = 0;
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, has_callers, penalty, calls;
- const char *name, *membername, *interface;
- int found = 0;
-
- if (argc != 2 && argc != 3) {
+ struct ao2_iterator queue_iter;
+ struct ao2_iterator mem_iter;
+
+ if (argc != 2 && argc != 3)
return CLI_SHOWUSAGE;
- }
-
- if (argc == 3) { /* specific queue */
- search = ast_str_create(64);
- if (search) {
- ast_str_set(&search, 0, "queues/queue/name=%s", argv[2]);
- query.search = ast_str_buffer(search);
- }
- }
-
- queues = ast_data_get(&query);
-
- if (search) {
- ast_free(search);
- }
-
- if (!queues) {
- return CLI_FAILURE;
- }
-
- iq = ast_data_iterator_init(queues, "queue");
- if (!iq) {
- ast_data_free(queues);
- do_print_noqueues(out, s, fd, (argc == 3 ? argv[2] : NULL));
- }
-
- while ((queue = ast_data_iterator_next(iq))) {
- found++;
-
- /* print queue statistics. */
- name = ast_data_retrieve_string(queue, "name");
-
- ast_str_set(&out, 0, "%-12.12s has %d calls (max ", name,
- ast_data_retrieve_int(queue, "count"));
-
- if (ast_data_retrieve_int(queue, "maxlen")) {
- ast_str_append(&out, 0, "%d", ast_data_retrieve_int(queue, "maxlen"));
- } else {
+
+ if (argc == 3) { /* specific queue */
+ if ((q = load_realtime_queue(argv[2]))) {
+ queue_t_unref(q, "Done with temporary pointer");
+ }
+ } else if (ast_check_realtime("queues")) {
+ /* This block is to find any queues which are defined in realtime but
+ * which have not yet been added to the in-core container
+ */
+ struct ast_config *cfg = ast_load_realtime_multientry("queues", "name LIKE", "%", SENTINEL);
+ char *queuename;
+ if (cfg) {
+ for (queuename = ast_category_browse(cfg, NULL); !ast_strlen_zero(queuename); queuename = ast_category_browse(cfg, queuename)) {
+ if ((q = load_realtime_queue(queuename))) {
+ queue_t_unref(q, "Done with temporary pointer");
+ }
+ }
+ ast_config_destroy(cfg);
+ }
+ }
+
+ queue_iter = ao2_iterator_init(queues, AO2_ITERATOR_DONTLOCK);
+ ao2_lock(queues);
+ while ((q = ao2_t_iterator_next(&queue_iter, "Iterate through queues"))) {
+ float sl;
+ struct call_queue *realtime_queue = NULL;
+
+ ao2_lock(q);
+ /* This check is to make sure we don't print information for realtime
+ * queues which have been deleted from realtime but which have not yet
+ * been deleted from the in-core container
+ */
+ if (q->realtime && !(realtime_queue = load_realtime_queue(q->name))) {
+ ao2_unlock(q);
+ queue_t_unref(q, "Done with iterator");
+ continue;
+ } else if (q->realtime) {
+ queue_t_unref(realtime_queue, "Queue is already in memory");
+ }
+ if (argc == 3 && strcasecmp(q->name, argv[2])) {
+ ao2_unlock(q);
+ queue_t_unref(q, "Done with iterator");
+ continue;
+ }
+ found = 1;
+
+ ast_str_set(&out, 0, "%s has %d calls (max ", q->name, q->count);
+ if (q->maxlen)
+ ast_str_append(&out, 0, "%d", q->maxlen);
+ else
ast_str_append(&out, 0, "unlimited");
- }
-
sl = 0;
- callscompleted = ast_data_retrieve_int(queue, "callscompleted");
- if (callscompleted) {
- sl = 100 * ((float) ast_data_retrieve_int(queue,
- "callscompletedinsl")
- / (float) callscompleted);
- }
- ast_str_append(&out, 0, ") in '%s' strategy (%ds holdtime, %ds talktime),"
- " W:%d, C:%d, A:%d, SL:%2.1f%% within %ds",
- int2strat(ast_data_retrieve_int(queue, "strategy")),
- ast_data_retrieve_int(queue, "holdtime"),
- ast_data_retrieve_int(queue, "talktime"),
- ast_data_retrieve_int(queue, "weight"),
- ast_data_retrieve_int(queue, "callscompleted"),
- ast_data_retrieve_int(queue, "callsabandoned"),
- sl,
- ast_data_retrieve_int(queue, "servicelevel"));
-
+ if (q->callscompleted > 0)
+ sl = 100 * ((float) q->callscompletedinsl / (float) q->callscompleted);
+ ast_str_append(&out, 0, ") in '%s' strategy (%ds holdtime, %ds talktime), W:%d, C:%d, A:%d, SL:%2.1f%% within %ds",
+ int2strat(q->strategy), q->holdtime, q->talktime, q->weight,
+ q->callscompleted, q->callsabandoned,sl,q->servicelevel);
do_print(s, fd, ast_str_buffer(out));
-
- /* print members. */
- has_members = 0;
- im = ast_data_iterator_init(queue, "members/member");
- if (im) {
- while ((member = ast_data_iterator_next(im))) {
- if (!has_members) {
- do_print(s, fd, " Members: ");
+ if (!ao2_container_count(q->members))
+ do_print(s, fd, " No Members");
+ else {
+ struct member *mem;
+
+ do_print(s, fd, " Members: ");
+ mem_iter = ao2_iterator_init(q->members, 0);
+ while ((mem = ao2_iterator_next(&mem_iter))) {
+ ast_str_set(&out, 0, " %s", mem->membername);
+ if (strcasecmp(mem->membername, mem->interface)) {
+ ast_str_append(&out, 0, " (%s)", mem->interface);
}
- 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);
- }
-
+ if (mem->penalty)
+ ast_str_append(&out, 0, " with penalty %d", mem->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) {
+ mem->dynamic ? " (dynamic)" : "",
+ mem->realtime ? " (realtime)" : "",
+ mem->paused ? " (paused)" : "",
+ ast_devstate2str(mem->status));
+ if (mem->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 {
+ mem->calls, (long) (time(NULL) - mem->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) {
+ ao2_ref(mem, -1);
+ }
+ ao2_iterator_destroy(&mem_iter);
+ }
+ if (!q->head)
+ do_print(s, fd, " No Callers");
+ else {
+ struct queue_ent *qe;
+ int pos = 1;
+
do_print(s, fd, " Callers: ");
- while ((caller = ast_data_iterator_next(ic))) {
+ for (qe = q->head; qe; qe = qe->next) {
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"));
+ pos++, qe->chan->name, (long) (now - qe->start) / 60,
+ (long) (now - qe->start) % 60, qe->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);
-
+ }
+ do_print(s, fd, ""); /* blank line between entries */
+ ao2_unlock(q);
+ queue_t_unref(q, "Done with iterator"); /* Unref the iterator's reference */
+ }
+ ao2_iterator_destroy(&queue_iter);
+ ao2_unlock(queues);
if (!found) {
- do_print_noqueues(out, s, fd, (argc == 3 ? argv[2] : NULL));
- }
-
- ast_data_free(queues);
-
+ 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));
+ }
return CLI_SUCCESS;
}
More information about the asterisk-commits
mailing list