Browse code

mqueue: Add rpc mqueue.sizes

Return sizes for all queues

Alex Hermann authored on 19/04/2018 21:12:01
Showing 4 changed files
... ...
@@ -300,6 +300,24 @@ xlog("L_INFO", "Size of queue is: $var(q_size)\n");
300 300
 ...
301 301
 &kamcmd; mqueue.fetch xyz
302 302
 ...
303
+</programlisting>
304
+	    </example>
305
+	</section>
306
+
307
+	<section id="mqueue.r.get_sizes">
308
+		<title>mqueue.get_sizes</title>
309
+		<para>
310
+			Get the size for all memory queues.
311
+		</para>
312
+		<para>
313
+			Parameters: none
314
+		</para>
315
+		<example>
316
+		<title><function>mqueue.get_sizes</function> usage</title>
317
+		<programlisting format="linespecific">
318
+...
319
+&kamcmd; mqueue.get_sizes
320
+...
303 321
 </programlisting>
304 322
 	    </example>
305 323
 	</section>
... ...
@@ -173,6 +173,9 @@ mq_head_t *mq_head_get(str *name)
173 173
 	mq_head_t *mh = NULL;
174 174
 
175 175
 	mh = _mq_head_list;
176
+	if (!name) {
177
+		return mh;
178
+	}
176 179
 	while(mh!=NULL)
177 180
 	{
178 181
 		if(name->len == mh->name.len
... ...
@@ -77,6 +77,7 @@ int mq_head_add(str *name, int msize);
77 77
 int mq_head_fetch(str *name);
78 78
 void mq_pv_free(str *name);
79 79
 int mq_item_add(str *qname, str *key, str *val);
80
+mq_head_t *mq_head_get(str *name);
80 81
 
81 82
 int _mq_get_csize(str *);
82 83
 int mq_set_dbmode(str *, int dbmode);
... ...
@@ -327,6 +327,34 @@ static const char* mqueue_rpc_get_size_doc[2] = {
327 327
 	0
328 328
 };
329 329
 
330
+static void mqueue_rpc_get_sizes(rpc_t* rpc, void* ctx)
331
+{
332
+	mq_head_t* mh = mq_head_get(NULL);
333
+	void* vh;
334
+	int size;
335
+
336
+	while(mh!=NULL)
337
+	{
338
+		if (rpc->add(ctx, "{", &vh) < 0) {
339
+			rpc->fault(ctx, 500, "Server error");
340
+			return;
341
+		}
342
+		lock_get(&mh->lock);
343
+		size = mh->csize;
344
+		lock_release(&mh->lock);
345
+		rpc->struct_add(vh, "Sd",
346
+				"name", &mh->name,
347
+				"size", size
348
+		);
349
+		mh = mh->next;
350
+	}
351
+}
352
+
353
+static const char* mqueue_rpc_get_sizes_doc[2] = {
354
+	"Get sizes of all mqueues.",
355
+	0
356
+};
357
+
330 358
 static void  mqueue_rpc_fetch(rpc_t* rpc, void* ctx)
331 359
 {
332 360
 	str mqueue_name;
... ...
@@ -392,6 +420,7 @@ static const char* mqueue_rpc_fetch_doc[2] = {
392 420
 
393 421
 rpc_export_t mqueue_rpc[] = {
394 422
 	{"mqueue.get_size", mqueue_rpc_get_size, mqueue_rpc_get_size_doc, 0},
423
+	{"mqueue.get_sizes", mqueue_rpc_get_sizes, mqueue_rpc_get_sizes_doc, RET_ARRAY},
395 424
 	{"mqueue.fetch", mqueue_rpc_fetch, mqueue_rpc_fetch_doc, 0},
396 425
 	{0, 0, 0, 0}
397 426
 };