var_export_example.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-09-02 WillianChan add var_export example code
  9. */
  10. #include <var_export.h>
  11. /* use VAR_EXPOR() to export 10 pieces of data into sections */
  12. VAR_EXPORT(module0, identi0, 0);
  13. VAR_EXPORT(module1, identi1, 1);
  14. VAR_EXPORT(module2, identi2, 2);
  15. VAR_EXPORT(module3, identi3, 3);
  16. VAR_EXPORT(module4, identi4, 4);
  17. VAR_EXPORT(module5, identi5, 5);
  18. VAR_EXPORT(module6, identi6, 6);
  19. VAR_EXPORT(module7, identi7, 7);
  20. VAR_EXPORT(module8, identi8, 8);
  21. VAR_EXPORT(module9, identi9, 9);
  22. void found_by_module(void)
  23. {
  24. ve_iterator_t iter;
  25. const ve_exporter_t* exporter;
  26. ve_module_t module;
  27. rt_base_t value;
  28. /* query all exporters with the same name as module1 */
  29. if (!ve_module_init(&module, "module1"))
  30. /* initialize the iterator */
  31. ve_iter_init(&module, &iter);
  32. else
  33. return;
  34. while (1)
  35. {
  36. /* start iterating */
  37. exporter = ve_iter_next(&iter);
  38. if (exporter == RT_NULL)
  39. break;
  40. else
  41. {
  42. /* checks whether the value exists */
  43. if (ve_value_exist(&module, "identi1") == RT_TRUE)
  44. {
  45. value = ve_value_get(&module, "identi1");
  46. rt_kprintf("[ve_example] value = %dn", value);
  47. return;
  48. }
  49. else
  50. {
  51. rt_kprintf("[ve_example] value not exist.\n");
  52. return;
  53. }
  54. }
  55. }
  56. }
  57. #ifdef RT_USING_FINSH
  58. #include <finsh.h>
  59. MSH_CMD_EXPORT(found_by_module, found by module);
  60. #endif /* RT_USING_FINSH */