Skip to content

Commit

Permalink
mqueue: Add rpc mqueue.sizes
Browse files Browse the repository at this point in the history
Return sizes for all queues
  • Loading branch information
gaaf committed Oct 19, 2020
1 parent 943f548 commit d8bd982
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/modules/mqueue/doc/mqueue_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,24 @@ xlog("L_INFO", "Size of queue is: $var(q_size)\n");
...
&kamcmd; mqueue.fetch xyz
...
</programlisting>
</example>
</section>

<section id="mqueue.r.get_sizes">
<title>mqueue.get_sizes</title>
<para>
Get the size for all memory queues.
</para>
<para>
Parameters: none
</para>
<example>
<title><function>mqueue.get_sizes</function> usage</title>
<programlisting format="linespecific">
...
&kamcmd; mqueue.get_sizes
...
</programlisting>
</example>
</section>
Expand Down
3 changes: 3 additions & 0 deletions src/modules/mqueue/mqueue_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ mq_head_t *mq_head_get(str *name)
mq_head_t *mh = NULL;

mh = _mq_head_list;
if (!name) {
return mh;
}
while(mh!=NULL)
{
if(name->len == mh->name.len
Expand Down
1 change: 1 addition & 0 deletions src/modules/mqueue/mqueue_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ int mq_head_add(str *name, int msize);
int mq_head_fetch(str *name);
void mq_pv_free(str *name);
int mq_item_add(str *qname, str *key, str *val);
mq_head_t *mq_head_get(str *name);

int _mq_get_csize(str *);
int mq_set_dbmode(str *, int dbmode);
Expand Down
29 changes: 29 additions & 0 deletions src/modules/mqueue/mqueue_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,34 @@ static const char* mqueue_rpc_get_size_doc[2] = {
0
};

static void mqueue_rpc_get_sizes(rpc_t* rpc, void* ctx)
{
mq_head_t* mh = mq_head_get(NULL);
void* vh;
int size;

while(mh!=NULL)
{
if (rpc->add(ctx, "{", &vh) < 0) {
rpc->fault(ctx, 500, "Server error");
return;
}
lock_get(&mh->lock);
size = mh->csize;
lock_release(&mh->lock);
rpc->struct_add(vh, "Sd",
"name", &mh->name,
"size", size
);
mh = mh->next;
}
}

static const char* mqueue_rpc_get_sizes_doc[2] = {
"Get sizes of all mqueues.",
0
};

static void mqueue_rpc_fetch(rpc_t* rpc, void* ctx)
{
str mqueue_name;
Expand Down Expand Up @@ -392,6 +420,7 @@ static const char* mqueue_rpc_fetch_doc[2] = {

rpc_export_t mqueue_rpc[] = {
{"mqueue.get_size", mqueue_rpc_get_size, mqueue_rpc_get_size_doc, 0},
{"mqueue.get_sizes", mqueue_rpc_get_sizes, mqueue_rpc_get_sizes_doc, RET_ARRAY},
{"mqueue.fetch", mqueue_rpc_fetch, mqueue_rpc_fetch_doc, 0},
{0, 0, 0, 0}
};
Expand Down

0 comments on commit d8bd982

Please sign in to comment.