Hi Mark,<br><br> I've had some problems with the time that took to login agents via AMI, since I had to first make sure they're removed from all queues first, and then I've QueueAdd them to the Queues they belong.<br>
<br> With this code in I can send an AMI command like this:<br><br>Action: QueueSync<br>Queues: queue1,queue5,queue7<br>Interface: SIP/pa01<br>Paused: 0<br>MemberName: Agent01<br><br> And that will make sure that Agent01 gets added to the queues listed (queue1,queue5,queue7) AND removed from all the other queues, with just one AMI command.<br>
<br> It will silently ignore errors such as "Already There", thus the only possible error that it can cause is an RES_OUTOFMEMORY error. (I've already made some changes on the code I posted above for this, when I'm finished I'll be adding the code to the reviewboard as suggested.)<br>
<br>Att,<br>Gabriel Ortiz<br><br><br><div class="gmail_quote">2011/1/12 Mark Murawski <span dir="ltr"><<a href="mailto:markm-lists@intellasoft.net">markm-lists@intellasoft.net</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div><div class="h5">On 01/11/2011 03:08 PM, Gabriel Ortiz Lour wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div></div><div class="h5">
Hi all,<br>
<br>
I've just finished testing a new function that I wrote that is kind<br>
of a QueueAdd mixed with QueueRemove command.<br>
<br>
It receives a comma separated list of queue names and iterate over<br>
all the queue. If the queuename being iterated is in the queuenames we<br>
received I call the add_to_queue function, else I call the<br>
remove_from_queue function.<br>
<br>
The purpose of this email is to see if anyone would have any<br>
comments, thoughts or remarks about my code, especially on the way I'm<br>
creating an array using ast_calloc, strsep and ast_free.<br>
<br>
Follows the code. Thanks in advance.<br>
<br>
Gabriel Ortiz<br>
<br>
<br>
<br>
<br>
<br>
static int sync_to_queues(const char *queuenames, const char *interface,<br>
const char *membername, int penalty, int paused, int dump, const char<br>
*state_interface)<br>
{<br>
int found, res = RES_OKAY, num_queues = 0, aux_count;<br>
struct call_queue *q;<br>
struct ao2_iterator queue_iter;<br>
char **queue_name = NULL, *buf;<br>
<br>
/* Make an array with the names of the queues we received */<br>
if (!ast_strlen_zero(queuenames)) {<br>
num_queues = 1;<br>
aux_count = 1;<br>
do {<br>
if (queuenames[aux_count] == ',') num_queues++;<br>
} while(queuenames[aux_count++] != '\0');<br>
<br>
aux_count = 0;<br>
queue_name = ast_calloc(num_queues, sizeof(char*));<br>
buf = ast_strdupa(queuenames);<br>
while ((queue_name[aux_count++] = strsep(&buf, ","))) {}<br>
}<br>
<br>
ao2_lock(queues);<br>
queue_iter = ao2_iterator_init(queues, 0);<br>
while ((q = ao2_t_iterator_next(&queue_iter, "Iterate over queues<br>
for memver Sync"))) {<br>
found = 0;<br>
if (num_queues > 0) {<br>
for(aux_count=0; aux_count<num_queues; aux_count++) {<br>
if(strcmp(queue_name[aux_count], q->name)) {<br>
found = 1;<br>
break;<br>
}<br>
}<br>
}<br>
<br>
res = (found) ?<br>
add_to_queue(q->name, interface, membername, penalty,<br>
paused, dump, state_interface) :<br>
remove_from_queue(q->name, interface);<br>
<br>
if(res == RES_OUTOFMEMORY) {<br>
ast_log(LOG_WARNING, "Queue sync RES_OUTOFMEMORY when %s<br>
member %s from queue %s\n", (found ? "adding" : "removing"), membername,<br>
q->name);<br>
break;<br>
}<br>
}<br>
ao2_iterator_destroy(&queue_iter);<br>
ao2_unlock(queues);<br>
<br>
if (num_queues > 0)<br>
ast_free(queue_name);<br>
<br>
return res;<br>
}<br>
<br>
<br>
<br></div></div><div class="im">
--<br>
_____________________________________________________________________<br>
-- Bandwidth and Colocation Provided by <a href="http://www.api-digital.com" target="_blank">http://www.api-digital.com</a> --<br>
<br>
asterisk-dev mailing list<br>
To UNSUBSCRIBE or update options visit:<br>
<a href="http://lists.digium.com/mailman/listinfo/asterisk-dev" target="_blank">http://lists.digium.com/mailman/listinfo/asterisk-dev</a><br>
</div></blockquote>
<br>
<br>
<br>
Please also provide some examples of how this code would be used.<div><div></div><div class="h5"><br>
<br>
--<br>
_____________________________________________________________________<br>
-- Bandwidth and Colocation Provided by <a href="http://www.api-digital.com" target="_blank">http://www.api-digital.com</a> --<br>
<br>
asterisk-dev mailing list<br>
To UNSUBSCRIBE or update options visit:<br>
<a href="http://lists.digium.com/mailman/listinfo/asterisk-dev" target="_blank">http://lists.digium.com/mailman/listinfo/asterisk-dev</a><br>
</div></div></blockquote></div><br>