File size: 1,210 Bytes
b98ffbb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "node_api.h"
// sleep
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
int main()
{
void *dora_context = init_dora_context_from_env();
if (dora_context == NULL)
{
fprintf(stderr, "failed to init dora context\n");
return -1;
}
while (1)
{
void *event = dora_next_event(dora_context);
if (event == NULL)
{
printf("[c node] ERROR: unexpected end of event\n");
return -1;
}
enum DoraEventType ty = read_dora_event_type(event);
if (ty == DoraEventType_Input)
{
char *id;
size_t id_len;
read_dora_input_id(event, &id, &id_len);
char *data;
size_t data_len;
read_dora_input_data(event, &data, &data_len);
char out_id[] = "foo";
char out_data[] = "bar";
dora_send_output(dora_context, out_id, strlen(out_id), out_data, strlen(out_data));
free_dora_event(event); // do not use `id` or `data` pointer after freeing
}
}
free_dora_context(dora_context);
return 0;
}
|