Skip to content

Commit

Permalink
lib: monkey: sync API changes for message queue prototype
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Oct 12, 2017
1 parent 7a65a60 commit 366f863
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 53 deletions.
5 changes: 3 additions & 2 deletions lib/monkey/api/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ static void signal_init()
signal(SIGTERM, &signal_handler);
}

static void cb_queue_message(mk_mq_t *queue, void *data, size_t size)
static void cb_queue_message(mk_mq_t *queue, void *data, size_t size, void *ctx)
{
size_t i;
char *buf;
(void) ctx;
(void) queue;

printf("=== cb queue message === \n");
Expand Down Expand Up @@ -105,7 +106,7 @@ int main()
}

/* Create a message queue and a callback for each message */
qid = mk_mq_create(ctx, "/data", cb_queue_message);
qid = mk_mq_create(ctx, "/data", cb_queue_message, NULL);

mk_config_set(ctx,
"Listen", API_PORT,
Expand Down
44 changes: 0 additions & 44 deletions lib/monkey/include/monkey/mk_core/mk_core_info.h

This file was deleted.

6 changes: 4 additions & 2 deletions lib/monkey/include/monkey/mk_fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ struct mk_fifo_queue {
* message is ready to be processed. This callback is invoked
* from a thread context (pipe read end).
*/
void (*cb_message)(struct mk_fifo_queue *, void *, size_t);
void (*cb_message)(struct mk_fifo_queue *, void *, size_t, void *);
void *data;
};

struct mk_fifo {
Expand All @@ -75,7 +76,8 @@ int mk_fifo_worker_read(void *event);

struct mk_fifo *mk_fifo_create(pthread_key_t *key, void *data);
int mk_fifo_queue_create(struct mk_fifo *ctx, char *name,
void (*cb)(struct mk_fifo_queue *, void *, size_t));
void (*cb)(struct mk_fifo_queue *, void *, size_t),
void *data);
struct mk_fifo_queue *mk_fifo_queue_get(struct mk_fifo *ctx, int id);
int mk_fifo_queue_destroy(struct mk_fifo *ctx, struct mk_fifo_queue *q);
int mk_fifo_queue_id_destroy(struct mk_fifo *ctx, int id);
Expand Down
2 changes: 1 addition & 1 deletion lib/monkey/include/monkey/mk_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ MK_EXPORT int mk_worker_callback(mk_ctx_t *ctx,
void (*cb_func) (void *),
void *data);
//MK_EXPORT int mk_mq_create(mk_ctx_t *ctx, char *name);
MK_EXPORT int mk_mq_create(mk_ctx_t *ctx, char *name, void (*cb));
MK_EXPORT int mk_mq_create(mk_ctx_t *ctx, char *name, void (*cb), void *data);

MK_EXPORT int mk_mq_send(mk_ctx_t *ctx, int qid, void *data, size_t size);

Expand Down
6 changes: 4 additions & 2 deletions lib/monkey/mk_server/mk_fifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ struct mk_fifo *mk_fifo_create(pthread_key_t *key, void *data)
}

int mk_fifo_queue_create(struct mk_fifo *ctx, char *name,
void (*cb)(struct mk_fifo_queue *, void *, size_t))
void (*cb)(struct mk_fifo_queue *, void *, size_t),
void *data)

{
int id = -1;
Expand Down Expand Up @@ -154,6 +155,7 @@ int mk_fifo_queue_create(struct mk_fifo *ctx, char *name,
}
q->id = id;
q->cb_message = cb;
q->data = data;

strncpy(q->name, name, len);
q->name[len] = '\0';
Expand Down Expand Up @@ -392,7 +394,7 @@ int mk_fifo_worker_read(void *event)

/* Trigger callback if any */
if (fq->cb_message) {
fq->cb_message(fq, fm->data, fm->length);
fq->cb_message(fq, fm->data, fm->length, fq->data);
}
fifo_drop_msg(fw);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/monkey/mk_server/mk_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,11 +687,11 @@ int mk_http_done(mk_request_t *req)
}

/* Create a messaging queue end-point */
int mk_mq_create(mk_ctx_t *ctx, char *name, void (*cb))
int mk_mq_create(mk_ctx_t *ctx, char *name, void (*cb), void *data)
{
int id;

id = mk_fifo_queue_create(ctx->fifo, name, cb);
id = mk_fifo_queue_create(ctx->fifo, name, cb, data);
return id;
}

Expand Down

0 comments on commit 366f863

Please sign in to comment.