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.

operator.c 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "build/operator_api.h"
  2. #include <assert.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. int dora_init_operator(void **operator_context)
  7. {
  8. void *context = malloc(1);
  9. char *context_char = (char *)context;
  10. *context_char = 0;
  11. *operator_context = context;
  12. return 0;
  13. }
  14. void dora_drop_operator(void *operator_context)
  15. {
  16. free(operator_context);
  17. }
  18. int dora_on_input(
  19. const char *id_start,
  20. size_t id_len,
  21. const char *data_start,
  22. size_t data_len,
  23. const int (*output_fn_raw)(const char *id_start,
  24. size_t id_len,
  25. const char *data_start,
  26. size_t data_len,
  27. const void *output_context),
  28. void *output_context,
  29. const void *operator_context)
  30. {
  31. char *counter = (char *)operator_context;
  32. char id[id_len + 1];
  33. memcpy(id, id_start, id_len);
  34. id[id_len] = 0;
  35. if (strcmp(id, "tick") == 0)
  36. {
  37. char data[data_len + 1];
  38. memcpy(data, data_start, data_len);
  39. data[data_len] = 0;
  40. *counter += 1;
  41. printf("C operator received tick input with data `%s`, counter: %i\n", data, *counter);
  42. char *out_id = "counter";
  43. char out_data[100];
  44. int count = snprintf(out_data, sizeof(out_data), "The current counter value is %d", *counter);
  45. assert(count >= 0 && count < 100);
  46. int res = (output_fn_raw)(out_id, strlen(out_id), out_data, strlen(out_data), output_context);
  47. if (res != 0)
  48. {
  49. printf("C operator failed to send output\n");
  50. }
  51. }
  52. else
  53. {
  54. printf("C operator received unexpected input %s, context: %i\n", id, *counter);
  55. }
  56. return 0;
  57. }

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