plugin_nihao.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Unlicense OR CC0-1.0
  5. */
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include "plugins_api.h"
  9. /**
  10. * This is an example function implemented by the plugin.
  11. */
  12. static void plugin_nihao_greet(const char* arg)
  13. {
  14. if (arg == NULL) {
  15. return;
  16. }
  17. printf("你好 %s!\n", arg);
  18. }
  19. /* The code below demonstates both static and dynamic registration approaches. */
  20. /**
  21. * Static registration of this plugin can be achieved by defining the plugin description
  22. * structure and placing it into .plugins_desc section.
  23. * The name of the section and its placement is determined by linker.lf file in 'plugins' component.
  24. */
  25. static const example_plugin_desc_t __attribute__((section(".plugins_desc"),used)) PLUGIN = {
  26. .name = "Nihao",
  27. .greet = &plugin_nihao_greet
  28. };
  29. /**
  30. * Dynamic registration of this plugin can be achieved by calling plugin registration function
  31. * ('example_plugin_register') from a "constructor" function. Constructor function is called automatically
  32. * during application startup.
  33. */
  34. static void __attribute__((constructor)) plugin_nihao_self_register(void)
  35. {
  36. printf("Nihao plugin performing self-registration...\n");
  37. example_plugin_register(&(example_plugin_desc_t){
  38. .name = "Nihao",
  39. .greet = &plugin_nihao_greet
  40. });
  41. }