gnunet_plugin_lib.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. /**
  18. * @author Christian Grothoff
  19. *
  20. * @file
  21. * Plugin loading and unloading
  22. *
  23. * @defgroup plugin Plugin library
  24. * Plugin loading and unloading
  25. * @{
  26. */
  27. #ifndef GNUNET_PLUGIN_LIB_H
  28. #define GNUNET_PLUGIN_LIB_H
  29. #ifdef __cplusplus
  30. extern "C"
  31. {
  32. #if 0 /* keep Emacsens' auto-indent happy */
  33. }
  34. #endif
  35. #endif
  36. #include "gnunet_common.h"
  37. #include "gnunet_configuration_lib.h"
  38. /**
  39. * Signature of any function exported by a plugin.
  40. *
  41. * @param arg argument to the function (context)
  42. * @return some pointer, NULL if the plugin was
  43. * shutdown or if there was an error, otherwise
  44. * the plugin's API on success
  45. */
  46. typedef void *(*GNUNET_PLUGIN_Callback) (void *arg);
  47. /**
  48. * Test if a plugin exists.
  49. *
  50. * Note that the library must export a symbol called
  51. * "library_name_init" for the test to succeed.
  52. *
  53. * @param library_name name of the plugin to test if it is installed
  54. * @return #GNUNET_YES if the plugin exists, #GNUNET_NO if not
  55. */
  56. int
  57. GNUNET_PLUGIN_test (const char *library_name);
  58. /**
  59. * Setup plugin (runs the "init" callback and returns whatever "init"
  60. * returned). If "init" returns NULL, the plugin is unloaded.
  61. *
  62. * Note that the library must export symbols called
  63. * "library_name_init" and "library_name_done". These will be called
  64. * when the library is loaded and unloaded respectively.
  65. *
  66. * @param library_name name of the plugin to load
  67. * @param arg argument to the plugin initialization function
  68. * @return whatever the initialization function returned, NULL on error
  69. */
  70. void *
  71. GNUNET_PLUGIN_load (const char *library_name, void *arg);
  72. /**
  73. * Signature of a function called by 'GNUNET_PLUGIN_load_all'.
  74. *
  75. * @param cls closure
  76. * @param library_name full name of the library (to be used with
  77. * #GNUNET_PLUGIN_unload)
  78. * @param lib_ret return value from the initialization function
  79. * of the library (same as what #GNUNET_PLUGIN_load would
  80. * have returned for the given library name)
  81. */
  82. typedef void (*GNUNET_PLUGIN_LoaderCallback) (void *cls,
  83. const char *library_name,
  84. void *lib_ret);
  85. /**
  86. * Load all compatible plugins with the given base name.
  87. *
  88. * Note that the library must export symbols called
  89. * "basename_ANYTHING_init" and "basename_ANYTHING__done". These will
  90. * be called when the library is loaded and unloaded respectively.
  91. *
  92. * @param basename basename of the plugins to load
  93. * @param arg argument to the plugin initialization function
  94. * @param cb function to call for each plugin found
  95. * @param cb_cls closure for @a cb
  96. */
  97. void
  98. GNUNET_PLUGIN_load_all (const char *basename, void *arg,
  99. GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls);
  100. /**
  101. * Unload plugin (runs the "done" callback and returns whatever "done"
  102. * returned). The plugin is then unloaded.
  103. *
  104. * @param library_name name of the plugin to unload
  105. * @param arg argument to the plugin shutdown function
  106. * @return whatever the shutdown function returned, typically NULL
  107. * or a "char *" representing the error message
  108. */
  109. void *
  110. GNUNET_PLUGIN_unload (const char *library_name, void *arg);
  111. #if 0 /* keep Emacsens' auto-indent happy */
  112. {
  113. #endif
  114. #ifdef __cplusplus
  115. }
  116. #endif
  117. /* ifndef GNUNET_PLUGIN_LIB_H */
  118. #endif
  119. /** @} */ /* end of group */
  120. /* end of gnunet_plugin_lib.h */