format
This commit is contained in:
@@ -152,11 +152,9 @@ typedef struct {
|
|||||||
|
|
||||||
char *strdup(const char *);
|
char *strdup(const char *);
|
||||||
void mapping_zactor_worker(char *name, zactor_t *worker, zactor_worker_map **map, size_t mapper_size) {
|
void mapping_zactor_worker(char *name, zactor_t *worker, zactor_worker_map **map, size_t mapper_size) {
|
||||||
|
|
||||||
map[mapper_size - 1] = malloc(sizeof(zactor_worker_map));
|
map[mapper_size - 1] = malloc(sizeof(zactor_worker_map));
|
||||||
(*map[mapper_size - 1]).name = strdup(name);
|
(*map[mapper_size - 1]).name = strdup(name);
|
||||||
(*map[mapper_size - 1]).worker = worker;
|
(*map[mapper_size - 1]).worker = worker;
|
||||||
//printf("Registering inside mapper %s :: %p\n", name, worker);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,8 +162,7 @@ zactor_t * zactor_worker_lookup(char *name, zactor_worker_map **map, size_t mapp
|
|||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (i = 0; i < mapper_size; i++) {
|
for (i = 0; i < mapper_size; i++) {
|
||||||
if (strcmp((*map[i]).name, name) == 0) {
|
if (strcmp((*map[i]).name, name) == 0) {
|
||||||
//printf("found %p\n", map[i]->worker);
|
return map[i]->worker;
|
||||||
return map[i]->worker;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -202,7 +199,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
// Setup ZMQ routers
|
// Setup ZMQ routers
|
||||||
zsock_t *frontend = zsock_new(ZMQ_ROUTER);
|
zsock_t *frontend = zsock_new(ZMQ_ROUTER);
|
||||||
zsock_bind(frontend, ep);
|
zsock_bind(frontend, "%s", ep);
|
||||||
free(ep);
|
free(ep);
|
||||||
|
|
||||||
zsock_t *backend = zsock_new(ZMQ_ROUTER);
|
zsock_t *backend = zsock_new(ZMQ_ROUTER);
|
||||||
@@ -220,47 +217,47 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sock == frontend) {
|
if (sock == frontend) {
|
||||||
printf("Frontend message:\n");
|
printf("Frontend message:\n");
|
||||||
zmsg_t *msg = zmsg_recv(frontend);
|
zmsg_t *msg = zmsg_recv(frontend);
|
||||||
zmsg_print(msg);
|
zmsg_print(msg);
|
||||||
// reply id
|
// reply id
|
||||||
zframe_t *identity = zmsg_pop(msg);
|
zframe_t *identity = zmsg_pop(msg);
|
||||||
// Null frame
|
// Null frame
|
||||||
zmsg_pop(msg);
|
zmsg_pop(msg);
|
||||||
|
|
||||||
struct guestfs_inpsect_command *c = guestfs_inspect_zmsg_to_command(msg);
|
struct guestfs_inpsect_command *c = guestfs_inspect_zmsg_to_command(msg);
|
||||||
if (c == NULL) {
|
if (c == NULL) {
|
||||||
printf("Error creating inspect command\n");
|
printf("Error creating inspect command\n");
|
||||||
zmsg_destroy(&msg);
|
zmsg_destroy(&msg);
|
||||||
zframe_destroy(&identity);
|
zframe_destroy(&identity);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
zactor_t *zactor_tmp = zactor_worker_lookup(c->name, worker_map, worker_map_size);
|
zactor_t *zactor_tmp = zactor_worker_lookup(c->name, worker_map, worker_map_size);
|
||||||
if (zactor_tmp != NULL) {
|
if (zactor_tmp != NULL) {
|
||||||
// send request to worker
|
// send request to worker
|
||||||
zmsg_prepend(msg, &identity);
|
zmsg_prepend(msg, &identity);
|
||||||
zactor_send(zactor_tmp, &msg);
|
zactor_send(zactor_tmp, &msg);
|
||||||
} else {
|
} else {
|
||||||
// add failure responce
|
// add failure responce
|
||||||
}
|
}
|
||||||
|
|
||||||
zactor_tmp = NULL;
|
zactor_tmp = NULL;
|
||||||
guestfs_inspect_command_destroy(&c);
|
guestfs_inspect_command_destroy(&c);
|
||||||
zmsg_destroy(&msg);
|
zmsg_destroy(&msg);
|
||||||
zframe_destroy(&identity);
|
zframe_destroy(&identity);
|
||||||
} else if (sock == backend) {
|
} else if (sock == backend) {
|
||||||
zmsg_t *msg = zmsg_recv(backend);
|
zmsg_t *msg = zmsg_recv(backend);
|
||||||
zmsg_pop(msg); // Removing backend id
|
zmsg_pop(msg); // Removing backend id
|
||||||
zmsg_send(&msg, frontend);
|
zmsg_send(&msg, frontend);
|
||||||
zmsg_destroy(&msg);
|
zmsg_destroy(&msg);
|
||||||
} else {
|
} else {
|
||||||
printf("Recieved unknown message\n");
|
printf("Recieved unknown message\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
for (int i = 0; i < worker_map_size; i++) {
|
for (size_t i = 0; i < worker_map_size; i++) {
|
||||||
zactor_destroy(&worker_map[i]->worker);
|
zactor_destroy(&worker_map[i]->worker);
|
||||||
free(worker_map[i]);
|
free(worker_map[i]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user