static void log_threaded_dest_driver_worker_thread_main(gpointer arg) { LogThrDestDriver *self = (LogThrDestDriver *)arg; iv_init(); msg_debug("Worker thread started", evt_tag_str("driver", self->super.super.id), NULL); log_queue_set_use_backlog(self->queue, TRUE); log_threaded_dest_driver_init_watches(self); log_threaded_dest_driver_start_watches(self); if (self->worker.thread_init) self->worker.thread_init(self); iv_main(); __disconnect(self); if (self->worker.thread_deinit) self->worker.thread_deinit(self); msg_debug("Worker thread finished", evt_tag_str("driver", self->super.super.id), NULL); iv_deinit(); }
static void _disconnect_and_suspend(LogThrDestDriver *self) { self->suspended = TRUE; __disconnect(self); log_queue_reset_parallel_push(self->queue); log_threaded_dest_driver_suspend(self); }
int __handle_not_ok_resp(msg_type resp_type) { char resp_body[sizeof(int)]; int code; __recv(resp_body, sizeof(int)); msg_deserialize_code(resp_body, &code); __disconnect(); switch(resp_type) { case ERR_RESP: //TODO: check! return code; default: //Should never happen printf("Clt: critical error. Cannot recover.\n"); exit(1); return false; } }
int __get_product(product_name name, Product * productp){ char toSend[sizeof(product_name_msg)]; msg_type resp_type; char resp_body[sizeof(product_resp)]; __connect(); msg_serialize_product_name_msg(__get_id(), GET_PRODUCT, name, toSend); __send(toSend, sizeof(product_name_msg)); __recv(&resp_type, sizeof(msg_type)); if (resp_type == OK_RESP) { __recv(resp_body, sizeof(Product)); msg_deserialize_product(resp_body, productp); __disconnect(); return OK; } return __handle_not_ok_resp(resp_type); }
int __write_product(product_name name, int quantity){ char toSend[sizeof(product_msg)]; msg_type resp_type; char resp_body[sizeof(error_resp)]; int code; __connect(); msg_serialize_product_msg(__get_id(), WRITE_PRODUCT, product_new(name, quantity), toSend); __send(toSend, sizeof(product_msg)); __recv(&resp_type, sizeof(msg_type)); if (resp_type == OK_RESP) { __recv(resp_body, sizeof(int)); msg_deserialize_code(resp_body, &code); __disconnect(); return OK; } return __handle_not_ok_resp(resp_type); }