You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

node.c 1.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <assert.h>
  4. #include "../../apis/c/node/node_api.h"
  5. // sleep
  6. #ifdef _WIN32
  7. #include <Windows.h>
  8. #else
  9. #include <unistd.h>
  10. #endif
  11. int main()
  12. {
  13. printf("[c node] Hello World\n");
  14. void *dora_context = init_dora_context_from_env();
  15. if (dora_context == NULL)
  16. {
  17. fprintf(stderr, "failed to init dora context\n");
  18. return -1;
  19. }
  20. printf("[c node] dora context initialized\n");
  21. for (char i = 0; i < 100; i++)
  22. {
  23. printf("[c node] waiting for next input\n");
  24. void *event = dora_next_event(dora_context);
  25. if (event == NULL)
  26. {
  27. printf("[c node] ERROR: unexpected end of event\n");
  28. return -1;
  29. }
  30. enum DoraEventType ty = read_dora_event_type(event);
  31. if (ty == DoraEventType_Input)
  32. {
  33. char *data;
  34. size_t data_len;
  35. read_dora_input_data(event, &data, &data_len);
  36. assert(data_len == 0);
  37. char out_id[] = "counter";
  38. dora_send_output(dora_context, out_id, strlen(out_id), &i, 1);
  39. }
  40. else if (ty == DoraEventType_Stop)
  41. {
  42. printf("[c node] received stop event\n");
  43. }
  44. else
  45. {
  46. printf("[c node] received unexpected event: %d\n", ty);
  47. }
  48. free_dora_event(event);
  49. }
  50. printf("[c node] received 10 events\n");
  51. free_dora_context(dora_context);
  52. printf("[c node] finished successfully\n");
  53. return 0;
  54. }

DORA (Dataflow-Oriented Robotic Architecture) is middleware designed to streamline and simplify the creation of AI-based robotic applications. It offers low latency, composable, and distributed datafl