浏览代码

mqueue: Added mq_size() function to get runtime size of mqueue in script.

Alex Balashov 13 年之前
父节点
当前提交
f492b41bd1
共有 3 个文件被更改,包括 45 次插入0 次删除
  1. 6 0
      modules/mqueue/doc/mqueue.xml
  2. 18 0
      modules/mqueue/doc/mqueue_admin.xml
  3. 21 0
      modules/mqueue/mqueue_mod.c

+ 6 - 0
modules/mqueue/doc/mqueue.xml

@@ -23,6 +23,12 @@
 		<surname>Modroiu</surname>
 		    <email>[email protected]</email>
 	    </editor>
+	    <editor>
+		<firstname>Alex</firstname>
+		<surname>Balashov</surname>
+		<email>[email protected]</email>
+		<affiliation><orgname>Evariste Systems</orgname></affiliation>
+	    </editor>
 	</authorgroup>
 	<copyright>
 	    <year>2010</year>

+ 18 - 0
modules/mqueue/doc/mqueue_admin.xml

@@ -152,6 +152,24 @@ while(mq_fetch("myq"))
 ...
 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>

+ 21 - 0
modules/mqueue/mqueue_mod.c

@@ -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;