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>
... ...
@@ -155,6 +155,24 @@ mq_pv_free("myq");
155 155
 </programlisting>
156 156
 	    </example>
157 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
+...
173
+</programlisting>
174
+	    </example>
175
+	</section>
158 176
 	
159 177
     </section>
160 178
 	
... ...
@@ -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 73
 		0, ANY_ROUTE},
74 74
 	{"mq_pv_free", (cmd_function)w_mq_pv_free, 1, fixup_spve_null,
75 75
 		0, ANY_ROUTE},
76
+	{"mq_size", (cmd_function) w_mq_size, 1, fixup_spve_null,
77
+		0, ANY_ROUTE},
76 78
 	{"bind_mq", (cmd_function)bind_mq, 1, 0,
77 79
 		0, ANY_ROUTE},
78 80
 	{0, 0, 0, 0, 0, 0}
... ...
@@ -140,6 +143,24 @@ static int w_mq_fetch(struct sip_msg* msg, char* mq, char* str2)
140 140
 	return 1;
141 141
 }
142 142
 
143
+static int w_mq_size(struct sip_msg *msg, char *mq, char *str2) 
144
+{
145
+	int ret;
146
+	str q;
147
+
148
+	if(fixup_get_svalue(msg, (gparam_t *) mq, &q) < 0) {
149
+		LM_ERR("cannot get queue parameter\n");
150
+		return -1;
151
+	}
152
+
153
+	ret = _mq_get_csize(&q);
154
+
155
+	if(ret < 0)
156
+		LM_ERR("mqueue not found\n");
157
+
158
+	return ret;
159
+}
160
+
143 161
 static int w_mq_add(struct sip_msg* msg, char* mq, char* key, char* val)
144 162
 {
145 163
 	str q;