[asterisk-dev] New manager command QueueSync - request for comments

Mark Murawski markm-lists at intellasoft.net
Wed Jan 12 10:26:46 CST 2011


Ah... that looks useful.  Is this something you're interested in 
contributing to mainline?  If so... make a mantis account if you haven't 
done so already (issues.asterisk.org) and then head over to the 
reviewboard (reviewboard.asterisk.org) and upload the entire diff.


On 01/12/2011 08:30 AM, Gabriel Ortiz Lour wrote:
> Hi Mark,
>
>    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.
>
>    With this code in I can send an AMI command like this:
>
> Action: QueueSync
> Queues: queue1,queue5,queue7
> Interface: SIP/pa01
> Paused: 0
> MemberName: Agent01
>
>    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.
>
>    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.)
>
> Att,
> Gabriel Ortiz
>
>
> 2011/1/12 Mark Murawski <markm-lists at intellasoft.net
> <mailto:markm-lists at intellasoft.net>>
>
>     On 01/11/2011 03:08 PM, Gabriel Ortiz Lour wrote:
>
>         Hi all,
>
>            I've just finished testing a new function that I wrote that
>         is kind
>         of a QueueAdd mixed with QueueRemove command.
>
>            It receives a comma separated list of queue names and iterate
>         over
>         all the queue. If the queuename being iterated is in the
>         queuenames we
>         received I call the add_to_queue function, else I call the
>         remove_from_queue function.
>
>            The purpose of this email is to see if anyone would have any
>         comments, thoughts or remarks about my code, especially on the
>         way I'm
>         creating an array using ast_calloc, strsep and ast_free.
>
>            Follows the code. Thanks in advance.
>
>         Gabriel Ortiz
>
>
>
>
>
>         static int sync_to_queues(const char *queuenames, const char
>         *interface,
>         const char *membername, int penalty, int paused, int dump, const
>         char
>         *state_interface)
>         {
>              int found, res = RES_OKAY, num_queues = 0, aux_count;
>              struct call_queue *q;
>              struct ao2_iterator queue_iter;
>              char **queue_name = NULL, *buf;
>
>              /* Make an array with the names of the queues we received */
>              if (!ast_strlen_zero(queuenames)) {
>                  num_queues = 1;
>                  aux_count = 1;
>                  do {
>                      if (queuenames[aux_count] == ',') num_queues++;
>                  } while(queuenames[aux_count++] != '\0');
>
>                  aux_count = 0;
>                  queue_name = ast_calloc(num_queues, sizeof(char*));
>                  buf = ast_strdupa(queuenames);
>                  while ((queue_name[aux_count++] = strsep(&buf, ","))) {}
>              }
>
>              ao2_lock(queues);
>              queue_iter = ao2_iterator_init(queues, 0);
>              while ((q = ao2_t_iterator_next(&queue_iter, "Iterate over
>         queues
>         for memver Sync"))) {
>                  found = 0;
>                  if (num_queues > 0) {
>                      for(aux_count=0; aux_count<num_queues; aux_count++) {
>                          if(strcmp(queue_name[aux_count], q->name)) {
>                              found = 1;
>                              break;
>                          }
>                      }
>                  }
>
>                  res = (found) ?
>                          add_to_queue(q->name, interface, membername,
>         penalty,
>         paused, dump, state_interface) :
>                          remove_from_queue(q->name, interface);
>
>                  if(res == RES_OUTOFMEMORY) {
>                      ast_log(LOG_WARNING, "Queue sync RES_OUTOFMEMORY
>         when %s
>         member %s from queue %s\n", (found ? "adding" : "removing"),
>         membername,
>         q->name);
>                      break;
>                  }
>              }
>              ao2_iterator_destroy(&queue_iter);
>              ao2_unlock(queues);
>
>              if (num_queues > 0)
>                  ast_free(queue_name);
>
>              return res;
>         }
>
>
>
>         --
>         _____________________________________________________________________
>         -- Bandwidth and Colocation Provided by
>         http://www.api-digital.com --
>
>         asterisk-dev mailing list
>         To UNSUBSCRIBE or update options visit:
>         http://lists.digium.com/mailman/listinfo/asterisk-dev
>
>
>
>
>     Please also provide some examples of how this code would be used.
>
>
>     --
>     _____________________________________________________________________
>     -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
>     asterisk-dev mailing list
>     To UNSUBSCRIBE or update options visit:
>     http://lists.digium.com/mailman/listinfo/asterisk-dev
>
>
>
>
> --
> _____________________________________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
> asterisk-dev mailing list
> To UNSUBSCRIBE or update options visit:
>     http://lists.digium.com/mailman/listinfo/asterisk-dev




More information about the asterisk-dev mailing list