[asterisk-dev] Get Queueholdtime
mbodbg at gmx.net
mbodbg at gmx.net
Fri Jan 26 09:33:30 MST 2007
Hello all,
I need a function to get the holdtime of a queue. For version 1.4 I've
programmed a function according to the QueueAgentCount function which is
already included. Here is the code:
static char *queue_function_qht(struct ast_channel *chan, char *cmd, char
*data, char *buf, size_t len) {
int holdtime = 0;
struct call_queue *q;
struct localuser *u;
LOCAL_USER_ACF_ADD(u);
ast_copy_string(buf, "0", len);
if (ast_strlen_zero(data)) {
ast_log(LOG_ERROR, "QUEUEHOLDTIME requires an argument:
queuename\n");
LOCAL_USER_REMOVE(u);
return buf;
}
ast_mutex_lock(&qlock);
/* Find the right queue */
for (q = queues; q; q = q->next) {
if (!strcasecmp(q->name, data)) {
ast_mutex_lock(&q->lock);
break;
}
}
ast_mutex_unlock(&qlock);
if (q) {
holdtime = q->holdtime;
ast_mutex_unlock(&q->lock);
}
snprintf(buf, len, "%d", holdtime);
LOCAL_USER_REMOVE(u);
return buf;
}
Unfortunately we have an other installation which is still on 1.0.9 that we
cannot upgrade to 1.4 yet. As there are no dialplan functions available in
1.0.9, I had the idea to set a global variable in the recalc_holdtime
function. For each queue there is set a global variable in the syntax
QUEUEHOLDTIME_<queuename>, e.g. in the dialplan I can get the holdtime for
queue TEST by calling _X.,1,NoOP(Holdtime Queue Test:
${QUEUEHOLDTIME_TEST}).
static void recalc_holdtime(struct queue_ent *qe) {
int oldvalue, newvalue;
char buf[AST_MAX_BUF];
char buf2[AST_MAX_BUF];
/* Calculate holdtime using a recursive boxcar filter */
/* Thanks to SRT for this contribution */
/* 2^2 (4) is the filter coefficient; a higher exponent would give
old entries more weight */
newvalue = time(NULL) - qe->start;
ast_mutex_lock(&qe->parent->lock);
if (newvalue <= qe->parent->servicelevel)
qe->parent->callscompletedinsl++;
oldvalue = qe->parent->holdtime;
qe->parent->holdtime = (((oldvalue << 2) - oldvalue) + newvalue) >>
2;
/* Store the Holdtime in the global variable
QUEUEHOLDTIME_<queuename> */
snprintf(buf, sizeof(buf), "%s_%s",QUEUEHOLDTIME, qe->parent->name);
snprintf(buf2, sizeof(buf2), "%d", qe->parent->holdtime);
pbx_builtin_setvar_helper(NULL, buf, buf2);
ast_mutex_unlock(&qe->parent->lock);
}
In general that approach is working fine. Does anyone see issues using that
approach setting global variables? Any Comments would be appreciated
Thanks and Regards
Markus
More information about the asterisk-dev
mailing list