[asterisk-commits] irroot: branch irroot/asterisk-trunk-quack-queue r345736 - /team/irroot/aster...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Nov 21 10:44:04 CST 2011
Author: irroot
Date: Mon Nov 21 10:44:00 2011
New Revision: 345736
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=345736
Log:
Remove redundant SQL query
Modified:
team/irroot/asterisk-trunk-quack-queue/apps/app_queue.c
Modified: team/irroot/asterisk-trunk-quack-queue/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/team/irroot/asterisk-trunk-quack-queue/apps/app_queue.c?view=diff&rev=345736&r1=345735&r2=345736
==============================================================================
--- team/irroot/asterisk-trunk-quack-queue/apps/app_queue.c (original)
+++ team/irroot/asterisk-trunk-quack-queue/apps/app_queue.c Mon Nov 21 10:44:00 2011
@@ -2651,60 +2651,17 @@
return q;
}
-/*!
- * \brief Reload a single queue via realtime.
+/*
*
- * Check for statically defined queue first, check if deleted RT queue,
- * check for new RT queue, if queue vars are not defined init them with defaults.
- * reload RT queue vars, set RT queue members dead and reload them, return finished queue.
- * \retval the queue,
- * \retval NULL if it doesn't exist.
-*/
-static struct call_queue *load_realtime_queue(const char *queuename, struct ast_flags *mask)
-{
+ */
+static struct call_queue *config_call_queue(struct call_queue *oldq, struct ast_variable *queue_vars, const char *queuename, int reload_members)
+{
+ int prev_weight = 0;
struct ast_variable *v;
+ char *tmp;
const char *tmp_name;
- char *tmp;
char tmpbuf[64]; /* Must be longer than the longest queue param name. */
- int prev_weight = 0;
- struct ast_variable *queue_vars;
- struct call_queue *oldq;
- struct call_queue *q = NULL;
- int reload_queue = (mask) ? ast_test_flag(mask, QUEUE_RELOAD_PARAMETERS) : 0;
- int reload_members = (mask) ? ast_test_flag(mask, QUEUE_RELOAD_MEMBER) : 0;
- int reload_realtime = (mask) ? ast_test_flag(mask, QUEUE_RELOAD_REALTIME) : 0;
-
- /* return if im not realtime or not reloading the queue possibly checking members */
- if ((oldq = ao2_t_find(queues, queuename, OBJ_KEY, "Look for queue in memory first")) &&
- (!oldq->realtime || !(reload_queue || reload_realtime))) {
- if (reload_members) {
- rt_load_member_config(oldq);
- }
- return oldq;
- } else if (!oldq && !(reload_queue || reload_realtime)) {
- ast_debug(1, "Not loading queue %s at this time\n",queuename);
- return NULL;
- }
-
- /* if im reloading realtime (CLI/AMI) i ignore cache timer */
- if (!reload_realtime && oldq && !ast_tvzero(oldq->reload) &&
- (ast_tvcmp(ast_tvnow(), oldq->reload) >= 0)) {
- ast_debug(1, "Not reloading queue %s for next %ld Seconds\n", oldq->name, (long)ast_tvdiff_sec(oldq->reload, ast_tvnow()));
- return oldq;
- }
-
- /* Check if queue is defined in realtime if im reloading */
- if (!(queue_vars = ast_load_realtime("queues", "name", queuename, SENTINEL))) {
- /* Delete queue from in-core list if it has been deleted in realtime.
- * ! \note On DB failure the queue will be removed as i cant distinguish a DB failure
- */
- if (oldq) {
- ast_debug(1, "Queue %s not found in realtime.\n", queuename);
- ao2_t_unlink(queues, oldq, "Unused; removing from container");
- ao2_t_ref(oldq, -1, "Queue is dead; can't return it");
- }
- return NULL;
- }
+ struct call_queue *q;
/* Create a new queue if an in-core entry does not exist yet. */
if (!oldq && !(q = alloc_queue(queuename, 1))) {
@@ -2719,7 +2676,7 @@
/* i could not allocate new structure return the old one*/
ast_log(AST_LOG_WARNING, "Failed to assign new queue object returning unchanged object\n");
ast_variables_destroy(queue_vars);
- return oldq;
+ return NULL;
}
}
@@ -2776,7 +2733,61 @@
} else {
ao2_link(queues, q);
}
+
return q;
+}
+
+/*!
+ * \brief Reload a single queue via realtime.
+ *
+ * Check for statically defined queue first, check if deleted RT queue,
+ * check for new RT queue, if queue vars are not defined init them with defaults.
+ * reload RT queue vars, set RT queue members dead and reload them, return finished queue.
+ * \retval the queue,
+ * \retval NULL if it doesn't exist.
+*/
+static struct call_queue *load_realtime_queue(const char *queuename, struct ast_flags *mask)
+{
+ struct ast_variable *queue_vars;
+ struct call_queue *oldq;
+
+ int reload_queue = (mask) ? ast_test_flag(mask, QUEUE_RELOAD_PARAMETERS) : 0;
+ int reload_members = (mask) ? ast_test_flag(mask, QUEUE_RELOAD_MEMBER) : 0;
+ int reload_realtime = (mask) ? ast_test_flag(mask, QUEUE_RELOAD_REALTIME) : 0;
+
+ /* return if im not realtime or not reloading the queue possibly checking members */
+ if ((oldq = ao2_t_find(queues, queuename, OBJ_KEY, "Look for queue in memory first")) &&
+ (!oldq->realtime || !(reload_queue || reload_realtime))) {
+ if (reload_members) {
+ rt_load_member_config(oldq);
+ }
+ return oldq;
+ } else if (!oldq && !(reload_queue || reload_realtime)) {
+ ast_debug(1, "Not loading queue %s at this time\n",queuename);
+ return NULL;
+ }
+
+ /* if im reloading realtime (CLI/AMI) i ignore cache timer */
+ if (!reload_realtime && oldq && !ast_tvzero(oldq->reload) &&
+ (ast_tvcmp(ast_tvnow(), oldq->reload) < 0)) {
+ ast_debug(1, "Not reloading queue %s for next %ld Seconds\n", oldq->name, (long)ast_tvdiff_sec(oldq->reload, ast_tvnow()));
+ return oldq;
+ }
+
+ /* Check if queue is defined in realtime if im reloading */
+ if (!(queue_vars = ast_load_realtime("queues", "name", queuename, SENTINEL))) {
+ /* Delete queue from in-core list if it has been deleted in realtime.
+ * ! \note On DB failure the queue will be removed as i cant distinguish a DB failure
+ */
+ if (oldq) {
+ ast_debug(1, "Queue %s not found in realtime.\n", queuename);
+ ao2_t_unlink(queues, oldq, "Unused; removing from container");
+ ao2_t_ref(oldq, -1, "Queue is dead; can't return it");
+ }
+ return NULL;
+ }
+
+ return config_call_queue(oldq, queue_vars, queuename, reload_members);
}
static int update_realtime_member_field(struct member *mem, const char *queue_name, const char *field, const char *value)
@@ -2796,18 +2807,23 @@
static void load_all_realtime_queues(struct ast_flags *mask)
{
- char *queuename;
+ const char *queuename;
struct ast_config *cfg;
struct call_queue *queue;
+ struct ast_category *cat;
+ struct ast_variable *var;
/* load realtime queues. */
if ((cfg = ast_load_realtime_multientry("queues", "name LIKE", "%", SENTINEL))) {
for (queuename = ast_category_browse(cfg, NULL);
!ast_strlen_zero(queuename);
queuename = ast_category_browse(cfg, queuename)) {
- if ((queue = load_realtime_queue(queuename, mask))) {
- ao2_ref(queue, -1);
- }
+ cat = ast_category_get(cfg, queuename);
+ var = ast_category_detach_variables(cat);
+ queue = ao2_find(queues, queuename, OBJ_KEY);
+ queue = config_call_queue(queue, var, queuename, 1);
+ ao2_ref(queue, -1);
+
}
ast_config_destroy(cfg);
}
@@ -5663,7 +5679,6 @@
struct member *mem = NULL;
struct ast_config *mcfg;
const char *newm = NULL;
- int found = 0;
if (q && !(mem = ao2_find(q->data->members, interface, OBJ_KEY))) {
/* if no member is found in core lets load this member from realtime */
@@ -5673,12 +5688,9 @@
}
while ((newm = ast_category_browse(mcfg, newm))) {
handle_member_record(q, newm, mcfg, QUEUE_ADD_MEMBER_REALTIME, "REALTIME");
- found ++;
+ mem = ao2_find(q->data->members, (char *)interface, 0);
}
ast_config_destroy(mcfg);
- if (found) {
- mem = ao2_find(q->data->members, (char *)interface, 0);
- }
}
return mem;
}
More information about the asterisk-commits
mailing list