Commit 579bebc2 authored by Lucas Russo's avatar Lucas Russo

dev_io/dev_io_core.c: add $REGISTER_SM command to pipe handling

This will allow DEVIO clients to register SMIOs
by sending messages to its pipe.
parent 074bf433
...@@ -676,31 +676,48 @@ static int _devio_handle_pipe (zloop_t *loop, zsock_t *reader, void *args) ...@@ -676,31 +676,48 @@ static int _devio_handle_pipe (zloop_t *loop, zsock_t *reader, void *args)
{ {
(void) loop; (void) loop;
char *command = NULL;
/* We expect a devio instance e as reference */ /* We expect a devio instance e as reference */
devio_t *devio = (devio_t *) args; devio_t *devio = (devio_t *) args;
(void) devio; char *command = NULL;
uint32_t smio_id;
uint64_t base;
uint32_t inst_id;
/* Receive message */ /* This command expects one of the following */
zmsg_t *recv_msg = zmsg_recv (reader); /* Command: (string) $REGISTER_SMIO
if (recv_msg == NULL) { * Arg1: (uint32_t) smio_id
* Arg2: (uint64_t) base
* Arg3: (uint32_t) inst_id
*
* Command: (string) $TERM
*
* Either way, the following zsock_recv is able to handle both cases. In
* case of the received message is shorter than the first command, the
* additional pointers are zeroed.
* */
int zerr = zsock_recv (reader, "s484", &command, &smio_id, &base, &inst_id);
if (zerr == -1) {
return -1; /* Interrupted */ return -1; /* Interrupted */
} }
command = zmsg_popstr (recv_msg);
if (streq (command, "$TERM")) { if (streq (command, "$TERM")) {
/* Shutdown the engine */ /* Shutdown the engine */
free (command); free (command);
zmsg_destroy (&recv_msg); zmsg_destroy (&recv_msg);
return -1; return -1;
} }
else if (streq (command, "$REGISTER_SMIO")) {
/* Register new SMIO */
devio_register_sm (devio, smio_id, base, inst_id);
}
else { else {
/* Invalid message received. Discard message and continue normally */ /* Invalid message received. Discard message and continue normally */
DBE_DEBUG (DBG_SM_IO | DBG_LVL_WARN, "[dev_io_core:_devio_handle_pipe] PIPE " DBE_DEBUG (DBG_SM_IO | DBG_LVL_WARN, "[dev_io_core:_devio_handle_pipe] PIPE "
"received an invalid command\n"); "received an invalid command\n");
} }
zmsg_destroy (&recv_msg); free (command);
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment