// Calls a TSP service // Returns reponse if successful (status code 200), else NULL // static zmsg_t * s_service_call (mdcli_t *session, char *service, zmsg_t **request_p) { zmsg_t *reply = mdcli_send (session, service, request_p); if (reply) { char *status_text = zmsg_pop (reply); int status_code = atoi (status_text); free (status_text); if (status_code == 200) return reply; else if (status_code == 400) { printf ("E: client fatal error, aborting\n"); exit (EXIT_FAILURE); } else if (status_code == 500) { printf ("E: server fatal error, aborting\n"); exit (EXIT_FAILURE); } zmsg_destroy (&reply); } else exit (EXIT_SUCCESS); // Interrupted or failed return NULL; // Didn't succeed, don't care why not }
// Calls a TSP service // Returns response if successful (status code 200 OK), else NULL // static zmsg_t * s_service_call (mdcli_t *session, char *service, zmsg_t **request_p) { zmsg_t *reply = mdcli_send (session, service, request_p); if (reply) { zframe_t *status = zmsg_pop (reply); if (zframe_streq (status, "200")) { zframe_destroy (&status); return reply; } else if (zframe_streq (status, "400")) { printf ("E: client fatal error, aborting\n"); exit (EXIT_FAILURE); } else if (zframe_streq (status, "500")) { printf ("E: server fatal error, aborting\n"); exit (EXIT_FAILURE); } } else exit (EXIT_SUCCESS); // Interrupted or failed zmsg_destroy (&reply); return NULL; // Didn't succeed, don't care why not }
int main (int argc, char *argv []) { int verbose = (argc > 1 && streq (argv [1], "-v")); mdcli_t *session = mdcli_new ("tcp://localhost:5555", verbose); zmsg_t *request; zmsg_t *reply; int count; //for (count = 0; count < 1; count++) { request = zmsg_new (); zmsg_pushstr (request, "KILL"); reply = mdcli_send (session, "echo", &request); if (reply) { zframe_t * lastFrame = zmsg_last(reply); char* msg = zframe_strdup(lastFrame); printf("msg:%s\n", msg); printf("size:%d\n", zmsg_content_size(reply)); //zframe_print(lastFrame,"->"); zmsg_destroy (&reply); } //else // break; // Interrupt or failure //} //printf ("%d requests/replies processed\n", count); mdcli_destroy (&session); return 0; }
void send_trigger(mdcli_t * client, char * target_worker, char * rule_id, int ival, char * user_id) { zclock_log("activating trigger\ntarget=%s\nvalue=%d\nuser=%s", target_worker, ival, user_id); struct timeval tval; gettimeofday(&tval, NULL); // make a messagepack hash msgpack_sbuffer * buffer = msgpack_sbuffer_new(); msgpack_packer* pk = msgpack_packer_new(buffer, msgpack_sbuffer_write); // value chunk msgpack_pack_map(pk, 3); // key msgpack_pack_raw(pk, 5); msgpack_pack_raw_body(pk, "value", 5); // value msgpack_pack_int(pk, ival); //time chunk // key msgpack_pack_raw(pk, 5); msgpack_pack_raw_body(pk, "epoch", 5); // time msgpack_pack_int(pk, tval.tv_sec); msgpack_pack_raw(pk, 6); msgpack_pack_raw_body(pk, "micros", 6); // time msgpack_pack_int(pk, tval.tv_usec); zmsg_t * msg = zmsg_new(); // really, the user_id should be being added by a // gatekeeper, not the block itself, or it's a security // hole. will do for now FIX zmsg_pushstr(msg, user_id); // zmsg_pushmem(msg, &trigger.line_id, sizeof(int)); zmsg_pushmem(msg, buffer->data, buffer->size); zmsg_pushstr(msg, rule_id); zmsg_pushstr(msg, "DoAction"); mdcli_send(client, target_worker, &msg); }