ProBInitialResponse prob_init(prob_client_t pc, int is_por) { Debugf("initializing ProB Zocket\n") zmsg_t *request = zmsg_new(); zmsg_addstr(request, "init"); zmsg_addstrf(request, "%d", pc->id_count); zmsg_addstrf(request, "%d", is_por); Debugf("sending message with length %zu, contents are:\n", zmsg_content_size(request)); #ifdef LTSMIN_DEBUG if (log_active(debug)) zmsg_print(request); #endif if (zmsg_send(&request, pc->zocket) != 0) Abort("Could not send message"); zmsg_destroy(&request); zmsg_t *response = zmsg_recv(pc->zocket); if (response == NULL) Abort("Did not receive valid response"); Debugf("received message with length %zu, contents are:\n", zmsg_content_size(response)); #ifdef LTSMIN_DEBUG if (log_active(debug)) zmsg_print(response); #endif ProBInitialResponse resp = prob_get_init_response(response); if (zmsg_size(response) != 0) Abort("Did not receive valid reponse size"); // puts("transition groups:"); // print_chunk_array(resp.transition_groups); // puts("variables"); // print_chunk_array(resp.variables); // for (size_t i = 0; i < resp.variables.size; i++) { // printf("%s (%s)\n", resp.variables.chunks[i].data, resp.variable_types.chunks[i].data); // } // puts("state labels"); // print_chunk_array(resp.state_labels); // // puts("May Write Matrix:"); // print_matrix(resp.may_write); // puts("Must Write Matrix:"); // print_matrix(resp.must_write); // puts("Reads Action Matrix:"); // print_matrix(resp.reads_action); // puts("Reads Guard Matrix:"); // print_matrix(resp.reads_guard); zmsg_destroy(&response); return resp; }
void mdp_client_msg_print (mdp_client_msg_t *self) { assert (self); switch (self->id) { case MDP_CLIENT_MSG_CLIENT_REQUEST: zsys_debug ("MDP_CLIENT_MSG_CLIENT_REQUEST:"); zsys_debug (" version=mdpc02"); zsys_debug (" messageid=1"); if (self->service) zsys_debug (" service='%s'", self->service); else zsys_debug (" service="); zsys_debug (" body="); if (self->body) zmsg_print (self->body); else zsys_debug ("(NULL)"); break; case MDP_CLIENT_MSG_CLIENT_PARTIAL: zsys_debug ("MDP_CLIENT_MSG_CLIENT_PARTIAL:"); zsys_debug (" version=mdpc02"); zsys_debug (" messageid=2"); if (self->service) zsys_debug (" service='%s'", self->service); else zsys_debug (" service="); zsys_debug (" body="); if (self->body) zmsg_print (self->body); else zsys_debug ("(NULL)"); break; case MDP_CLIENT_MSG_CLIENT_FINAL: zsys_debug ("MDP_CLIENT_MSG_CLIENT_FINAL:"); zsys_debug (" version=mdpc02"); zsys_debug (" messageid=3"); if (self->service) zsys_debug (" service='%s'", self->service); else zsys_debug (" service="); zsys_debug (" body="); if (self->body) zmsg_print (self->body); else zsys_debug ("(NULL)"); break; } }
void zyre_event_print (zyre_event_t *self) { zsys_info ("zyre_event:"); zsys_info (" - from name=%s uuid=%s", zyre_event_name(self), zyre_event_sender(self)); switch (self->type) { case ZYRE_EVENT_ENTER: zsys_info (" - type=ENTER"); zsys_info (" - headers=%zu:", zhash_size (self->headers)); zhash_foreach (self->headers, (zhash_foreach_fn *) zyre_event_log_pair, self); zsys_info (" - address=%s", zyre_event_address(self)); break; case ZYRE_EVENT_EXIT: zsys_info (" - type=EXIT"); break; case ZYRE_EVENT_STOP: zsys_info (" - type=STOP"); break; case ZYRE_EVENT_JOIN: zsys_info (" - type=JOIN"); zsys_info (" - group=%s", zyre_event_group(self)); break; case ZYRE_EVENT_LEAVE: zsys_info (" - type=LEAVE"); zsys_info (" - group=%s", zyre_event_group(self)); break; case ZYRE_EVENT_SHOUT: zsys_info (" - type=SHOUT"); zsys_info (" - message:"); zmsg_print (self->msg); break; case ZYRE_EVENT_WHISPER: zsys_info (" - type=WHISPER"); zsys_info (" - message:"); zmsg_print (self->msg); break; case ZYRE_EVENT_EVASIVE: zsys_info (" - type=EVASIVE"); break; default: zsys_info (" - type=UNKNOWN"); break; } }
/* ================ delete_data() ================ */ int delete_data(zsock_t *sock, const char *key) { /* ---------------- Send Message ---------------- */ zmsg_t *delete_msg = create_action_message(MSG_ACTION_DEL); message_add_key_data(delete_msg, key, "", 0); zmsg_send(&delete_msg, sock); /* ---------------- Receive Message ---------------- */ zmsg_t *recv_msg = zmsg_recv(sock); if ( recv_msg == NULL ){ return -2; } zmsg_print(recv_msg); int rc = -1; if (message_check_status(recv_msg, MSG_STATUS_WORKER_NOTFOUND) == 0 ){ warning_log("Not Found. key=%s", key); rc = 0; } else if ( message_check_status(recv_msg, MSG_STATUS_WORKER_ERROR) == 0 ){ error_log("Return MSG_STATUS_WORKER_ERROR. key=%s", key); rc = -1; } zmsg_destroy(&recv_msg); return rc; }
static ssize_t _thsafe_zmq_client_read_generic (smio_t *self, loff_t offs, uint8_t *data, uint32_t size) { assert (self); ssize_t ret_size = -1; zmsg_t *send_msg = zmsg_new (); ASSERT_ALLOC(send_msg, err_msg_alloc); uint32_t opcode; DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Calling _thsafe_read_generic\n"); switch (size) { case THSAFE_READ_16_DSIZE: opcode = THSAFE_READ_16; break; case THSAFE_READ_32_DSIZE: opcode = THSAFE_READ_32; break; case THSAFE_READ_64_DSIZE: opcode = THSAFE_READ_64; break; default: opcode = THSAFE_READ_32; } /* Message is: * frame 0: READ<size> opcode * frame 1: offset */ int zerr = zmsg_addmem (send_msg, &opcode, sizeof (opcode)); ASSERT_TEST(zerr == 0, "Could not add READ opcode in message", err_add_opcode); zerr = zmsg_addmem (send_msg, &offs, sizeof (offs)); ASSERT_TEST(zerr == 0, "Could not add offset in message", err_add_offset); DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Sending message:\n"); #ifdef LOCAL_MSG_DBG zmsg_print (send_msg); #endif zerr = zmsg_send (&send_msg, self->pipe); ASSERT_TEST(zerr == 0, "Could not send message", err_send_msg); /* Message is: * frame 0: reply code * frame 1: return code * frame 2: data */ ret_size = _thsafe_zmq_client_recv_read (self, data, size); err_send_msg: err_add_offset: err_add_opcode: zmsg_destroy (&send_msg); err_msg_alloc: return ret_size; }
int handle_pipe(zloop_t *loop, zsock_t *root, void *arg) { zmsg_t *msg = zmsg_recv (root); if (!msg) return -1; zmsg_print (msg); zmsg_destroy (&msg); return 0; }
void zyre_event_print (zyre_event_t *self) { zsys_info ("zyre_event:"); zsys_info (" - from name=%s uuid=%s", zyre_event_peer_name (self), zyre_event_peer_uuid (self)); zsys_info (" - type=%s", self->type); if (streq (self->type, "ENTER")) { void *item; zsys_info (" - headers=%zu:", zhash_size (self->headers)); for (item = zhash_first (self->headers); item != NULL; item = zhash_next (self->headers)) zyre_event_log_pair (zhash_cursor (self->headers), item, self); zsys_info (" - address=%s", zyre_event_peer_addr (self)); } else if (streq (self->type, "JOIN")) { zsys_info (" - group=%s", zyre_event_group (self)); } else if (streq (self->type, "LEAVE")) { zsys_info (" - group=%s", zyre_event_group (self)); } else if (streq (self->type, "SHOUT")) { zsys_info (" - message:"); zmsg_print (self->msg); } else if (streq (self->type, "WHISPER")) { zsys_info (" - message:"); zmsg_print (self->msg); } else if (streq (self->type, "LEADER")) { zsys_info (" - group=%s", zyre_event_group (self)); } }
static int reader_rep_event(zloop_t *loop, zsock_t *sink, void *arg) { client_proxy_t *self = arg; zmsg_t *request = zmsg_recv(self->rep); char *correlation_id = zmsg_popstr(request); zmsg_t *dup = zmsg_dup(request); if (!request) { return 0; } char *command = zmsg_popstr(request); bool is_ticket_command = streq(command, "PRINT") || streq(command, "GETTICKETINFO") || streq(command, "DETAILREPORT") || streq(command, "REPORT") || streq(command, "SIMPLEREPORT") || streq(command, "SUMMARY") || streq(command,"UNPRINT"); if (self->ticket_store_req != NULL && is_ticket_command) { zmsg_send(&dup, self->ticket_store_req); zmsg_t *resp = zmsg_recv(self->ticket_store_req); zmsg_pushstr(resp, correlation_id); if (self->verbose) { zsys_debug("client proxy: sending response from ticket store for command %s", command); zmsg_print(resp); } zmsg_send(&resp, self->rep); } bool is_printer_store_command = streq(command, "GETPRINTERS") || streq(command, "GETPRINTER") || streq(command, "SCANPRINTERS"); if (self->printer_store_req != NULL && is_printer_store_command) { zmsg_send(&dup, self->printer_store_req); zmsg_t *resp = zmsg_recv(self->printer_store_req); zmsg_pushstr(resp, correlation_id); if (self->verbose) { zsys_debug("client proxy: sending response from printer store"); zmsg_print(resp); } zmsg_send(&resp, self->rep); } zstr_free(&correlation_id); zstr_free(&command); zmsg_destroy(&request); return 0; }
static ProBState * prob_next_x(prob_client_t pc, ProBState s, char *transitiongroup, int *size, char *header) { zmsg_t *request = zmsg_new(); zmsg_addstr(request, header); zmsg_addstrf(request, "%d", pc->id_count); zmsg_addstr(request, transitiongroup); prob_put_state(request, s); Debugf("requesting next-state, contents:\n"); #ifdef LTSMIN_DEBUG if (log_active(debug)) zmsg_print(request); #endif zmsg_send(&request, pc->zocket); zmsg_destroy(&request); zmsg_t *response = zmsg_recv(pc->zocket); Debugf("response for next-state, contents:\n"); #ifdef LTSMIN_DEBUG if (log_active(debug)) zmsg_print(response); #endif drop_frame(response); drop_frame(response); char *nr_of_states_s = zmsg_popstr(response); sscanf(nr_of_states_s, "%d", size); RTfree(nr_of_states_s); ProBState *successors = RTmalloc(sizeof(ProBState) * (*size)); int i; for (i = 0; i < (*size); i++) { successors[i] = prob_get_state(response); } zmsg_destroy(&response); return successors; }
static int reader_internal_sub_event(zloop_t *loop, zsock_t *sub_sock, void *arg) { int ret = 0; client_proxy_t *self = (client_proxy_t *) arg; zmsg_t *request = zmsg_recv(sub_sock); if (!request) { return ret; } if (self->pub) { if (self->verbose) { zsys_debug("client proxy: republishing message."); zmsg_print(request); } zmsg_send(&request, self->pub); } return ret; }
static zmsg_t *_thsafe_zmq_client_recv_confirmation (smio_t *self) { DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Calling _thsafe_zmq_client_recv_confirmation\n"); assert (self); /* Wait for response */ zmsg_t *recv_msg = zmsg_recv (self->pipe); /* Do not pop the message, just set a cursor to it */ zframe_t *reply_frame = zmsg_first (recv_msg); DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Receiving message:\n"); #ifdef LOCAL_MSG_DBG zmsg_print (recv_msg); #endif /* Message is: * frame 0: Reply code */ if (reply_frame == NULL) { /* Interrupted or malformed message */ goto err_recv_data; } /* Check if the frame has the correct number of bytes */ if (zframe_size (reply_frame) != THSAFE_REPLY_SIZE) { goto err_recv_data; } uint8_t *raw_data = (uint8_t *) zframe_data (reply_frame); ASSERT_TEST(raw_data != NULL, "Could not receive confirmation code", err_null_raw_data); uint32_t reply_code = *(uint32_t *) raw_data; /* Check for confirmation */ if (reply_code != THSAFE_OK) { DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Received reply code OK\n"); goto err_reply_code_not_ok; } /* Caller owns the message and is its responsability to destroy it */ return recv_msg; /* TODO: reduce code repetition */ err_reply_code_not_ok: err_null_raw_data: err_recv_data: zmsg_destroy (&recv_msg); return NULL; }
/**** Write data block from device function pointer, size in bytes ****/ ssize_t thsafe_zmq_client_write_block (smio_t *self, loff_t offs, size_t size, const uint32_t *data) { assert (self); ssize_t ret_size = -1; zmsg_t *send_msg = zmsg_new (); ASSERT_ALLOC(send_msg, err_msg_alloc); uint32_t opcode = THSAFE_WRITE_BLOCK; DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Calling thsafe_write_block\n"); /* Message is: * frame 0: WRITE_BLOCK opcode * frame 1: offset * frame 2: data to be written * */ int zerr = zmsg_addmem (send_msg, &opcode, sizeof (opcode)); ASSERT_TEST(zerr == 0, "Could not add WRITE opcode in message", err_add_opcode); zerr = zmsg_addmem (send_msg, &offs, sizeof (offs)); ASSERT_TEST(zerr == 0, "Could not add offset in message", err_add_offset); zerr = zmsg_addmem (send_msg, data, size); ASSERT_TEST(zerr == 0, "Could not add data in message", err_add_data); DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Sending message:\n"); #ifdef LOCAL_MSG_DBG zmsg_print (send_msg); #endif zerr = zmsg_send (&send_msg, self->pipe); ASSERT_TEST(zerr == 0, "Could not send message", err_send_msg); /* Message is: * frame 0: reply code * frame 1: return code */ ret_size = _thsafe_zmq_client_recv_write (self); err_send_msg: err_add_data: err_add_offset: err_add_opcode: zmsg_destroy (&send_msg); err_msg_alloc: return ret_size; }
/**** Read data block from device function pointer, size in bytes ****/ ssize_t thsafe_zmq_client_read_block (smio_t *self, loff_t offs, size_t size, uint32_t *data) { assert (self); ssize_t ret_size = -1; zmsg_t *send_msg = zmsg_new (); ASSERT_ALLOC(send_msg, err_msg_alloc); uint32_t opcode = THSAFE_READ_BLOCK; DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Calling thsafe_read_block\n"); /* Message is: * frame 0: READ_BLOCK opcode * frame 1: offset * frame 2: number of bytes to be read */ int zerr = zmsg_addmem (send_msg, &opcode, sizeof (opcode)); ASSERT_TEST(zerr == 0, "Could not add READ opcode in message", err_add_opcode); zerr = zmsg_addmem (send_msg, &offs, sizeof (offs)); ASSERT_TEST(zerr == 0, "Could not add offset in message", err_add_offset); zerr = zmsg_addmem (send_msg, &size, sizeof (size)); ASSERT_TEST(zerr == 0, "Could not add size in message", err_add_size); DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Sending message:\n"); #ifdef LOCAL_MSG_DBG zmsg_print (send_msg); #endif zerr = zmsg_send (&send_msg, self->pipe); ASSERT_TEST(zerr == 0, "Could not send message", err_send_msg); /* Message is: * frame 0: reply code * frame 1: return code * frame 2: data */ ret_size = _thsafe_zmq_client_recv_read (self, (uint8_t *) data, size); err_send_msg: err_add_size: err_add_offset: err_add_opcode: zmsg_destroy (&send_msg); err_msg_alloc: return ret_size; }
int main(int argc, const char *argv[]) { zsock_t *sock = zsock_new_req("tcp://127.0.0.1:5555"); int count = 10000; zpoller_t *poller = zpoller_new(sock, NULL); while (count--) { zmsg_t *request = zmsg_new(); zmsg_pushstr(request, "HELLO"); zmsg_pushstr(request, "com.tw.echo"); zmsg_pushstr(request, MDPC_CLIENT); zmsg_send(&request, sock); zmsg_t *msg = zmsg_recv(sock); zsys_info("GET RESPONSE: %d ", count); zmsg_print(msg); zmsg_destroy(&msg); } zsock_destroy(&sock); return 0; }
int main(int argc, char** argv) { if (argc != 2) { fprintf (stderr, "Usage: %s name\n", argv[0]); exit (EXIT_FAILURE); } zactor_t *gs = zactor_new (zgossip, argv[1]); zstr_send (zgossip, "VERBOSE"); zstr_sendx (gs, "BIND", "ipc://@/bios-alerts"); /* char buf[1024]; snprintf(buf, 1024, "%d", random()); zsys_debug ("PUBLISH: %s", buf); zstr_sendx (gs, "PUBLISH", "X-BIOS-PATH", buf, NULL); */ while (!zsys_interrupted) { char *method, *key, *value; zmsg_t *msg = zactor_recv (gs); if (!msg) continue; zmsg_print (msg); method = zmsg_popstr (msg); key = zmsg_popstr (msg); value = zmsg_popstr (msg); printf ("method: '%s', key: '%s', value: '%s'\n", method, key, value); zstr_free (&key); zstr_free (&value); zstr_free (&method); zmsg_destroy (&msg); } zactor_destroy (&gs); }
static int twps_create_ticket_printer(twps_server_t *self, zmsg_t *msg) { char *type = zmsg_popstr(msg); char *id = zmsg_popstr(msg); zstr_free(&id); char *path = zmsg_popstr(msg); char *model = zmsg_popstr(msg); wchar_t *manufacture = (wchar_t *) zmsg_popstr(msg); wchar_t *product = (wchar_t *) zmsg_popstr(msg); zactor_t *printer = NULL; if (streq(type, "HID")) { printer = zactor_new(ticket_hid_printer, path); } #ifdef __WIN32__ else if (streq(type, "SERIAL")) { printer = zactor_new(ticket_serial_printer, path); } #endif if (printer != NULL) { if (self->verbose) { zstr_send(printer, "VERBOSE"); } if (self->diagnostic) zstr_sendx(printer, "SETDIAGNOSTIC", NULL); zstr_sendx(printer, "START", TICKET_STORE_REP_ENDPOINT, NULL); zsock_wait(printer); zstr_sendx(printer, "SETPRINTERSTORE", PRINTER_STORE_REP_ENDPOINT, PRINTER_STORE_PUB_ENDPOINT, NULL); zsock_wait(printer); zsys_info("twps server: started ticket printer %s manufacturer|product|model %ls|%ls|%s", type, manufacture, product, model); zlistx_add_end(self->ticket_printers, printer); } else { zsys_warning("twps server: printer not added %s, %s", type, path); zmsg_print(msg); } zstr_free(&type); zstr_free(&path); zstr_free(&model); zstr_free((char **) &manufacture); zstr_free((char **) &product); return 0; }
static int s_stream_engine_handle_command (stream_engine_t *self) { char *method = zstr_recv (self->cmdpipe); if (!method) return -1; // Interrupted; exit zloop if (self->verbose) zsys_debug ("mlm_stream_simple: API command=%s", method); if (streq (method, "VERBOSE")) self->verbose = true; // Start verbose logging else if (streq (method, "$TERM")) self->terminated = true; // Shutdown the engine else if (streq (method, "COMPILE")) { void *client; char *pattern; zsock_recv (self->cmdpipe, "ps", &client, &pattern); s_stream_engine_compile (self, client, pattern); zstr_free (&pattern); } else if (streq (method, "CANCEL")) { void *client; zsock_recv (self->cmdpipe, "p", &client); s_stream_engine_cancel (self, client); } // Cleanup pipe if any argument frames are still waiting to be eaten if (zsock_rcvmore (self->cmdpipe)) { zsys_error ("mlm_stream_simple: trailing API command frames (%s)", method); zmsg_t *more = zmsg_recv (self->cmdpipe); zmsg_print (more); zmsg_destroy (&more); } zstr_free (&method); return self->terminated? -1: 0; }
void xrap_traffic_print (xrap_traffic_t *self) { assert (self); switch (self->id) { case XRAP_TRAFFIC_CONNECTION_OPEN: zsys_debug ("XRAP_TRAFFIC_CONNECTION_OPEN:"); zsys_debug (" protocol=malamute"); zsys_debug (" version=1"); zsys_debug (" address='%s'", self->address); break; case XRAP_TRAFFIC_CONNECTION_PING: zsys_debug ("XRAP_TRAFFIC_CONNECTION_PING:"); break; case XRAP_TRAFFIC_CONNECTION_PONG: zsys_debug ("XRAP_TRAFFIC_CONNECTION_PONG:"); break; case XRAP_TRAFFIC_CONNECTION_CLOSE: zsys_debug ("XRAP_TRAFFIC_CONNECTION_CLOSE:"); break; case XRAP_TRAFFIC_XRAP_SEND: zsys_debug ("XRAP_TRAFFIC_XRAP_SEND:"); zsys_debug (" timeout=%ld", (long) self->timeout); zsys_debug (" content="); if (self->content) zmsg_print (self->content); else zsys_debug ("(NULL)"); break; case XRAP_TRAFFIC_XRAP_OFFER: zsys_debug ("XRAP_TRAFFIC_XRAP_OFFER:"); zsys_debug (" route='%s'", self->route); zsys_debug (" method='%s'", self->method); break; case XRAP_TRAFFIC_XRAP_DELIVER: zsys_debug ("XRAP_TRAFFIC_XRAP_DELIVER:"); zsys_debug (" sender="); if (self->sender) zsys_debug (" %s", zuuid_str_canonical (self->sender)); else zsys_debug (" (NULL)"); zsys_debug (" content="); if (self->content) zmsg_print (self->content); else zsys_debug ("(NULL)"); break; case XRAP_TRAFFIC_OK: zsys_debug ("XRAP_TRAFFIC_OK:"); zsys_debug (" status_code=%ld", (long) self->status_code); zsys_debug (" status_reason='%s'", self->status_reason); break; case XRAP_TRAFFIC_FAIL: zsys_debug ("XRAP_TRAFFIC_FAIL:"); zsys_debug (" status_code=%ld", (long) self->status_code); zsys_debug (" status_reason='%s'", self->status_reason); break; case XRAP_TRAFFIC_ERROR: zsys_debug ("XRAP_TRAFFIC_ERROR:"); zsys_debug (" status_code=%ld", (long) self->status_code); zsys_debug (" status_reason='%s'", self->status_reason); break; } }
int main(int argc, char** argv) { if(argc != 2) { fprintf(stderr, "Usage: %s ups_name\n", argv[0]); exit(1); } char *addr = NULL; zyre_t *n = zyre_new(argv[1]); zyre_start(n); zyre_join(n, "MONITORS"); char *hap_server = NULL; while (!zsys_interrupted) { zmsg_t *zyre_msg = zyre_recv (n); zmsg_print (zyre_msg); char *command = zmsg_popstr (zyre_msg); if (!streq (command, "SHOUT")) continue; char *uuid = zmsg_popstr (zyre_msg); char *name = zmsg_popstr (zyre_msg); char *channel = zmsg_popstr (zyre_msg); hap_server = zmsg_popstr (zyre_msg); free (uuid); free (name); free (channel); free (command); break; } zsys_debug ("initial HAP server: %s", hap_server); addr = hap_server; if(addr == NULL) exit(1); zsock_t * sc = zsock_new(ZMQ_PUB); zsock_connect(sc, "%s", addr); zsys_debug ("socket created, connected."); bool state = random()%2; int timeout = 0; int cummulative = 0; while(!zsys_interrupted) { if(timeout == 0) { state = !state; timeout = 5 + random()%20; } timeout--; if(state) { zstr_sendx(sc, argv[1], "ON", NULL); zsys_debug("UPS %s ON", argv[1]); } else { zstr_sendx(sc, argv[1], "OFF", NULL); zsys_debug("UPS %s OFF", argv[1]); } sleep(1); cummulative++; if (cummulative == 5) { char *new_hap; while (!zsys_interrupted) { zmsg_t *zyre_msg = zyre_recv (n); zmsg_print (zyre_msg); char *command = zmsg_popstr (zyre_msg); if (!streq (command, "SHOUT")) continue; char *uuid = zmsg_popstr (zyre_msg); char *name = zmsg_popstr (zyre_msg); char *channel = zmsg_popstr (zyre_msg); new_hap = zmsg_popstr (zyre_msg); free (uuid); free (name); free (channel); free (command); break; } if (!streq (new_hap, hap_server)) { free (hap_server); hap_server = new_hap; zsock_connect(sc, "%s", addr); } cummulative = 0; } } if (hap_server) free (hap_server); zsock_destroy(&sc); }
Z K1(zmsgprint){PC(x); zmsg_print(VSK(x)); RZ;}
/// // Send message to zsys log sink (may be stdout, or system facility as // configured by zsys_set_logstream). void QmlZmsg::print () { zmsg_print (self); };
int _thsafe_zmq_client_open_release (smio_t *self, llio_endpoint_t *endpoint, uint32_t opcode) { assert (self); int ret = -1; zmsg_t *send_msg = zmsg_new (); ASSERT_ALLOC(send_msg, err_msg_alloc); DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Calling thsafe_release\n"); /* Message is: * frame 0: RELEASE opcode * frame 1: endpopint struct (FIXME?) */ int zerr = zmsg_addmem (send_msg, &opcode, sizeof (opcode)); ASSERT_TEST(zerr == 0, "Could not add OPEN opcode in message", err_add_opcode); zerr = zmsg_addmem (send_msg, endpoint, sizeof (*endpoint)); ASSERT_TEST(zerr == 0, "Could not add endpoint in message", err_add_endpoint); DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Sending message:\n"); #ifdef LOCAL_MSG_DBG zmsg_print (send_msg); #endif zerr = zmsg_send (&send_msg, self->pipe); ASSERT_TEST(zerr == 0, "Could not send message", err_send_msg); /* Message is: * frame 0: reply code * frame 1: return code */ /* Returns NULL if confirmation was not OK or in case of error. * Returns the original message if the confirmation was OK */ zmsg_t *recv_msg = _thsafe_zmq_client_recv_confirmation (self); ASSERT_TEST(recv_msg != NULL, "Could not receive confirmation code", err_null_raw_data); /* If we are here the message got a OK reply code. * Just return the return code */ zframe_t *reply_frame = zmsg_pop (recv_msg); zframe_destroy (&reply_frame); /* Don't do anything with the reply code */ zframe_t *ret_code_frame = zmsg_pop (recv_msg); if (ret_code_frame == NULL) { DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Interrupted or malformed message\n"); /* Interrupted or malformed message */ goto err_recv_data; } /* Check if the frame has the number of bytes requested. * For now, we consider a success only when the number of * bytes requested is the same as the actually read*/ if (zframe_size (ret_code_frame) != THSAFE_REPLY_SIZE) { DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Frame size is wrong\n"); goto err_recv_data_size; } ret = *(THSAFE_REPLY_TYPE *) zframe_data (ret_code_frame); DBE_DEBUG (DBG_MSG | DBG_LVL_TRACE, "[smio_thsafe_client:zmq] Received return code: %08X\n", ret); err_recv_data_size: zframe_destroy (&ret_code_frame); err_recv_data: err_null_raw_data: zmsg_destroy (&recv_msg); err_send_msg: err_add_endpoint: err_add_opcode: zmsg_destroy (&send_msg); err_msg_alloc: return ret; }
int main (int argc, char **argv) { unsigned int count = 0; parse_args(argc, argv); if (!endpoint || !name) { zsys_error("endpoint or name not specified."); usage(); } mlm_client_t *client = mlm_client_new (); assert(client); int rv; rv = mlm_client_connect(client, endpoint, 5000, name); if (rv == -1) { zsys_error("connection failed."); mlm_client_destroy (&client); return -1; } rv = mlm_client_set_producer (client, "stream"); if (rv == -1) { zsys_error("set_producer failed."); mlm_client_destroy (&client); return -2; } zsock_t *pipe = mlm_client_msgpipe (client); if (!pipe) { zsys_error ("mlm_client_msgpipe() failed."); mlm_client_destroy (&client); return -3; } zpoller_t *poller = zpoller_new (pipe, NULL); if (!poller) { zsys_error("zpoller_new() failed."); mlm_client_destroy (&client); return -4; } while ( !zsys_interrupted && ( !num_messages || count < num_messages) ) { zsock_t *which = zpoller_wait (poller, interval); if ( which != NULL ) { // so we have something to receive zmsg_t *recv_msg = mlm_client_recv (client); zmsg_destroy (&recv_msg); } // in any case we are going to send something // zclock_sleep(interval); zmsg_t *msg = zmsg_new(); assert (msg); if ( count % 10 == 0) { zmsg_pushstr (msg, "exit"); } else { zmsg_pushstr (msg, "hello"); } zmsg_print(msg); mlm_client_send (client, "testing message", &msg); zmsg_destroy (&msg); ++count; } mlm_client_destroy(&client); zpoller_destroy(&poller); free(endpoint); free(name); zsys_info ("finished, sent: %u.", count); return 0; }
void zproto_example_print (zproto_example_t *self) { assert (self); switch (self->id) { case ZPROTO_EXAMPLE_LOG: zsys_debug ("ZPROTO_EXAMPLE_LOG:"); zsys_debug (" sequence=%ld", (long) self->sequence); zsys_debug (" version=3"); zsys_debug (" level=%ld", (long) self->level); zsys_debug (" event=%ld", (long) self->event); zsys_debug (" node=%ld", (long) self->node); zsys_debug (" peer=%ld", (long) self->peer); zsys_debug (" time=%ld", (long) self->time); zsys_debug (" host='%s'", self->host); if (self->data) zsys_debug (" data='%s'", self->data); else zsys_debug (" data="); break; case ZPROTO_EXAMPLE_STRUCTURES: zsys_debug ("ZPROTO_EXAMPLE_STRUCTURES:"); zsys_debug (" sequence=%ld", (long) self->sequence); zsys_debug (" aliases="); if (self->aliases) { char *aliases = (char *) zlist_first (self->aliases); while (aliases) { zsys_debug (" '%s'", aliases); aliases = (char *) zlist_next (self->aliases); } } zsys_debug (" headers="); if (self->headers) { char *item = (char *) zhash_first (self->headers); while (item) { zsys_debug (" %s=%s", zhash_cursor (self->headers), item); item = (char *) zhash_next (self->headers); } } else zsys_debug ("(NULL)"); break; case ZPROTO_EXAMPLE_BINARY: zsys_debug ("ZPROTO_EXAMPLE_BINARY:"); zsys_debug (" sequence=%ld", (long) self->sequence); zsys_debug (" flags=[ ... ]"); zsys_debug (" public_key=[ ... ]"); zsys_debug (" identifier="); if (self->identifier) zsys_debug (" %s", zuuid_str_canonical (self->identifier)); else zsys_debug (" (NULL)"); zsys_debug (" address="); if (self->address) zframe_print (self->address, NULL); else zsys_debug ("(NULL)"); zsys_debug (" content="); if (self->content) zmsg_print (self->content); else zsys_debug ("(NULL)"); break; case ZPROTO_EXAMPLE_TYPES: zsys_debug ("ZPROTO_EXAMPLE_TYPES:"); zsys_debug (" sequence=%ld", (long) self->sequence); zsys_debug (" client_forename='%s'", self->client_forename); zsys_debug (" client_surname='%s'", self->client_surname); zsys_debug (" client_mobile='%s'", self->client_mobile); zsys_debug (" client_email='%s'", self->client_email); zsys_debug (" supplier_forename='%s'", self->supplier_forename); zsys_debug (" supplier_surname='%s'", self->supplier_surname); zsys_debug (" supplier_mobile='%s'", self->supplier_mobile); zsys_debug (" supplier_email='%s'", self->supplier_email); break; } }