static void error_callback(burrow_st *burrow, burrow_verbose_t err, const char *msg) { app_state_st *state = burrow_get_context(burrow); if (err >= BURROW_VERBOSE_ERROR) state->error = 1; printf("%s: burrow: %s\n", burrow_verbose_name(err), msg); }
static void message_callback(burrow_st *burrow, const char *message_id, const void *body, size_t body_size, const burrow_attributes_st *attributes) { app_state_st *state = burrow_get_context(burrow); (void) attributes; if (state->generator || !body) return; printf("msg received: %s\n", message_id); incoming_st *incoming = malloc(sizeof(incoming_st)); char *data = malloc(body_size + 1); char *id = strdup(message_id); if (!incoming || !data || !id) FATAL("ran out of memory"); memcpy(data, body, body_size); data[body_size] = '\0'; incoming->data = data; incoming->size = body_size; incoming->id = id; incoming->next = state->msg; state->msg = incoming; }
static void _log(burrow_st *burrow, burrow_verbose_t verbose, const char *message) { client_st *client = burrow_get_context(burrow); if (verbose >= BURROW_VERBOSE_ERROR) { printf("Error: %s", message); client->return_code = 1; } }
static void _complete(burrow_st *burrow) { client_st *client = burrow_get_context(burrow); printf("done: %s/%s/%s: %s\n", client->account, client->queue, client->current_message->msg_id, client->current_message->body); client->current_message = client->current_message->next; if (client->current_message == NULL) return; /* Since this only sets next start state, we don't have to worry about recursion. When this callback returns the loop continues with this next message. */ burrow_create_message(burrow, client->account, client->queue, client->current_message->msg_id, client->current_message->body, client->current_message->body_size, NULL); }
static void complete_callback(burrow_st *burrow) { app_state_st *state = burrow_get_context(burrow); incoming_st *incoming; if (!state->msg) return; strncpy(state->last_msg_id, state->msg->id, 128 - 1); while((incoming = state->msg)) { double result = process_equation((char*)incoming->data); printf("result: %f\n", result); free(incoming->data); free(incoming->id); state->msg = incoming->next; free(incoming); } }