|
|
|
@@ -27,6 +27,8 @@ OnEventResult_t dora_on_event( |
|
|
|
const SendOutput_t *send_output, |
|
|
|
void *operator_context) |
|
|
|
{ |
|
|
|
OnEventResult_t result = {.status = DORA_STATUS_CONTINUE}; |
|
|
|
|
|
|
|
char *counter = (char *)operator_context; |
|
|
|
|
|
|
|
if (event->input != NULL) |
|
|
|
@@ -34,18 +36,17 @@ OnEventResult_t dora_on_event( |
|
|
|
// input event |
|
|
|
Input_t *input = event->input; |
|
|
|
|
|
|
|
char id[input->id.len + 1]; |
|
|
|
memcpy(id, input->id.ptr, input->id.len); |
|
|
|
id[input->id.len] = 0; |
|
|
|
char *id = dora_read_input_id(input); |
|
|
|
|
|
|
|
if (strcmp(id, "message") == 0) |
|
|
|
{ |
|
|
|
char data[input->data.len + 1]; |
|
|
|
memcpy(data, input->data.ptr, input->data.len); |
|
|
|
data[input->data.len] = 0; |
|
|
|
printf("message event\n"); |
|
|
|
|
|
|
|
Vec_uint8_t data = dora_read_data(input); |
|
|
|
assert(data.ptr != NULL); |
|
|
|
|
|
|
|
*counter += 1; |
|
|
|
printf("C operator received message `%s`, counter: %i\n", data, *counter); |
|
|
|
printf("C operator received message `%.*s`, counter: %i\n", (int)data.len, data.ptr, *counter); |
|
|
|
|
|
|
|
char *out_id = "counter"; |
|
|
|
char *out_id_heap = strdup(out_id); |
|
|
|
@@ -55,27 +56,22 @@ OnEventResult_t dora_on_event( |
|
|
|
int count = snprintf(out_data, data_alloc_size, "The current counter value is %d", *counter); |
|
|
|
assert(count >= 0 && count < 100); |
|
|
|
|
|
|
|
Output_t output = {.id = { |
|
|
|
.ptr = (uint8_t *)out_id_heap, |
|
|
|
.len = strlen(out_id_heap), |
|
|
|
.cap = strlen(out_id_heap) + 1, |
|
|
|
}, |
|
|
|
.data = {.ptr = (uint8_t *)out_data, .len = strlen(out_data), .cap = data_alloc_size}}; |
|
|
|
DoraResult_t res = (send_output->send_output.call)(send_output->send_output.env_ptr, output); |
|
|
|
DoraResult_t res = dora_send_output(send_output, out_id_heap, (uint8_t *)out_data, strlen(out_data)); |
|
|
|
result.result = res; |
|
|
|
|
|
|
|
OnEventResult_t result = {.result = res, .status = DORA_STATUS_CONTINUE}; |
|
|
|
return result; |
|
|
|
dora_free_data(data); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
printf("C operator received unexpected input %s, context: %i\n", id, *counter); |
|
|
|
} |
|
|
|
|
|
|
|
dora_free_input_id(id); |
|
|
|
} |
|
|
|
if (event->stop) |
|
|
|
{ |
|
|
|
printf("C operator received stop event\n"); |
|
|
|
} |
|
|
|
|
|
|
|
OnEventResult_t result = {.status = DORA_STATUS_CONTINUE}; |
|
|
|
return result; |
|
|
|
} |