From 2cf06c7aa878baafe955ebf9b0f21e45b44838e5 Mon Sep 17 00:00:00 2001 From: markster Date: Fri, 12 Nov 2004 03:50:19 +0000 Subject: [PATCH] Make status available on agent channels git-svn-id: http://svn.digium.com/svn/asterisk/trunk@4220 f38db490-d61c-443f-a65b-d21fe96a405b --- channels/chan_agent.c | 52 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/channels/chan_agent.c b/channels/chan_agent.c index b81a6d85c..a000caa1e 100755 --- a/channels/chan_agent.c +++ b/channels/chan_agent.c @@ -1720,10 +1720,60 @@ static int agentmonitoroutgoing_exec(struct ast_channel *chan, void *data) return 0; } +/*--- sip_devicestate: Part of PBX channel interface ---*/ +static int agent_devicestate(void *data) +{ + struct agent_pvt *p; + char *s; + unsigned int groupmatch; + int waitforagent=0; + int res = AST_DEVICE_INVALID; + + s = data; + if ((s[0] == '@') && (sscanf(s + 1, "%d", &groupmatch) == 1)) { + groupmatch = (1 << groupmatch); + } else if ((s[0] == ':') && (sscanf(s + 1, "%d", &groupmatch) == 1)) { + groupmatch = (1 << groupmatch); + waitforagent = 1; + } else { + groupmatch = 0; + } + + /* Check actual logged in agents first */ + ast_mutex_lock(&agentlock); + p = agents; + while(p) { + ast_mutex_lock(&p->lock); + if (!p->pending && ((groupmatch && (p->group & groupmatch)) || !strcmp(data, p->agent))) { + res = AST_DEVICE_UNKNOWN; + if (p->owner) { + if (res != AST_DEVICE_INUSE) + res = AST_DEVICE_BUSY; + } else { + if (res == AST_DEVICE_BUSY) + res = AST_DEVICE_INUSE; + if (p->chan || !ast_strlen_zero(p->loginchan)) { + if (res == AST_DEVICE_INVALID) + res = AST_DEVICE_UNKNOWN; + } else if (res == AST_DEVICE_INVALID) + res = AST_DEVICE_UNAVAILABLE; + } + if (!strcmp(data, p->agent)) { + ast_mutex_unlock(&p->lock); + break; + } + } + ast_mutex_unlock(&p->lock); + p = p->next; + } + ast_mutex_unlock(&agentlock); + return res; +} + int load_module() { /* Make sure we can register our sip channel type */ - if (ast_channel_register(type, tdesc, capability, agent_request)) { + if (ast_channel_register_ex(type, tdesc, capability, agent_request, agent_devicestate)) { ast_log(LOG_ERROR, "Unable to register channel class %s\n", type); return -1; }