mqueue: Added mq_size() function to get runtime size of mqueue in script.
authorAlex Balashov <abalashov@evaristesys.com>
Tue, 24 Jul 2012 02:23:36 +0000 (22:23 -0400)
committerAlex Balashov <abalashov@evaristesys.com>
Tue, 24 Jul 2012 02:23:36 +0000 (22:23 -0400)
modules/mqueue/doc/mqueue.xml
modules/mqueue/doc/mqueue_admin.xml
modules/mqueue/mqueue_mod.c

index 4ad3797..af880f6 100644 (file)
                <surname>Modroiu</surname>
                    <email>ramona@asipto.com</email>
            </editor>
+           <editor>
+               <firstname>Alex</firstname>
+               <surname>Balashov</surname>
+               <email>abalashov@evaristesys.com</email>
+               <affiliation><orgname>Evariste Systems</orgname></affiliation>
+           </editor>
        </authorgroup>
        <copyright>
            <year>2010</year>
index 1b0363c..3a6ce9e 100644 (file)
@@ -155,6 +155,24 @@ mq_pv_free("myq");
 </programlisting>
            </example>
        </section>
+
+       <section>
+           <title>
+               <function moreinfo="none">mq_size(queue)</function>
+           </title>
+           <para>
+               Returns the current number of elements in the mqueue.
+           </para>
+               <example>
+               <title><function>mq_size</function> usage</title>
+               <programlisting format="linespecific">
+...
+$var(q_size) = mq_size("queue");
+xlog("L_INFO", "Size of queue is: $var(q_size)\n");
+...
+</programlisting>
+           </example>
+       </section>
        
     </section>
        
index 1559c51..3eacf02 100644 (file)
@@ -45,6 +45,7 @@ static int  mod_init(void);
 static void mod_destroy(void);
 
 static int w_mq_fetch(struct sip_msg* msg, char* mq, char* str2);
+static int w_mq_size(struct sip_msg *msg, char *mq, char *str2);
 static int w_mq_add(struct sip_msg* msg, char* mq, char* key, char* val);
 static int w_mq_pv_free(struct sip_msg* msg, char* mq, char* str2);
 int mq_param(modparam_t type, void *val);
@@ -73,6 +74,8 @@ static cmd_export_t cmds[]={
                0, ANY_ROUTE},
        {"mq_pv_free", (cmd_function)w_mq_pv_free, 1, fixup_spve_null,
                0, ANY_ROUTE},
+       {"mq_size", (cmd_function) w_mq_size, 1, fixup_spve_null,
+               0, ANY_ROUTE},
        {"bind_mq", (cmd_function)bind_mq, 1, 0,
                0, ANY_ROUTE},
        {0, 0, 0, 0, 0, 0}
@@ -140,6 +143,24 @@ static int w_mq_fetch(struct sip_msg* msg, char* mq, char* str2)
        return 1;
 }
 
+static int w_mq_size(struct sip_msg *msg, char *mq, char *str2) 
+{
+       int ret;
+       str q;
+
+       if(fixup_get_svalue(msg, (gparam_t *) mq, &q) < 0) {
+               LM_ERR("cannot get queue parameter\n");
+               return -1;
+       }
+
+       ret = _mq_get_csize(&q);
+
+       if(ret < 0)
+               LM_ERR("mqueue not found\n");
+
+       return ret;
+}
+
 static int w_mq_add(struct sip_msg* msg, char* mq, char* key, char* val)
 {
        str q;