Browse code

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

Alex Balashov authored on 24/07/2012 02:23:36
Showing 3 changed files
... ...
@@ -23,6 +23,12 @@
23 23
 		<surname>Modroiu</surname>
24 24
 		    <email>ramona@asipto.com</email>
25 25
 	    </editor>
26
+	    <editor>
27
+		<firstname>Alex</firstname>
28
+		<surname>Balashov</surname>
29
+		<email>abalashov@evaristesys.com</email>
30
+		<affiliation><orgname>Evariste Systems</orgname></affiliation>
31
+	    </editor>
26 32
 	</authorgroup>
27 33
 	<copyright>
28 34
 	    <year>2010</year>
... ...
@@ -152,6 +152,24 @@ while(mq_fetch("myq"))
152 152
 ...
153 153
 mq_pv_free("myq");
154 154
 ...
155
+</programlisting>
156
+	    </example>
157
+	</section>
158
+
159
+	<section>
160
+	    <title>
161
+		<function moreinfo="none">mq_size(queue)</function>
162
+	    </title>
163
+	    <para>
164
+		Returns the current number of elements in the mqueue.
165
+	    </para>
166
+		<example>
167
+		<title><function>mq_size</function> usage</title>
168
+		<programlisting format="linespecific">
169
+...
170
+$var(q_size) = mq_size("queue");
171
+xlog("L_INFO", "Size of queue is: $var(q_size)\n");
172
+...
155 173
 </programlisting>
156 174
 	    </example>
157 175
 	</section>
... ...
@@ -45,6 +45,7 @@ static int  mod_init(void);
45 45
 static void mod_destroy(void);
46 46
 
47 47
 static int w_mq_fetch(struct sip_msg* msg, char* mq, char* str2);
48
+static int w_mq_size(struct sip_msg *msg, char *mq, char *str2);
48 49
 static int w_mq_add(struct sip_msg* msg, char* mq, char* key, char* val);
49 50
 static int w_mq_pv_free(struct sip_msg* msg, char* mq, char* str2);
50 51
 int mq_param(modparam_t type, void *val);
... ...
@@ -73,6 +74,8 @@ static cmd_export_t cmds[]={
73 74
 		0, ANY_ROUTE},
74 75
 	{"mq_pv_free", (cmd_function)w_mq_pv_free, 1, fixup_spve_null,
75 76
 		0, ANY_ROUTE},
77
+	{"mq_size", (cmd_function) w_mq_size, 1, fixup_spve_null,
78
+		0, ANY_ROUTE},
76 79
 	{"bind_mq", (cmd_function)bind_mq, 1, 0,
77 80
 		0, ANY_ROUTE},
78 81
 	{0, 0, 0, 0, 0, 0}
... ...
@@ -140,6 +143,24 @@ static int w_mq_fetch(struct sip_msg* msg, char* mq, char* str2)
140 143
 	return 1;
141 144
 }
142 145
 
146
+static int w_mq_size(struct sip_msg *msg, char *mq, char *str2) 
147
+{
148
+	int ret;
149
+	str q;
150
+
151
+	if(fixup_get_svalue(msg, (gparam_t *) mq, &q) < 0) {
152
+		LM_ERR("cannot get queue parameter\n");
153
+		return -1;
154
+	}
155
+
156
+	ret = _mq_get_csize(&q);
157
+
158
+	if(ret < 0)
159
+		LM_ERR("mqueue not found\n");
160
+
161
+	return ret;
162
+}
163
+
143 164
 static int w_mq_add(struct sip_msg* msg, char* mq, char* key, char* val)
144 165
 {
145 166
 	str q;