DHTModuleRegistry.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #ifndef DHTModuleRegistry_H
  16. #define DHTModuleRegistry_H
  17. #ifdef SUBNODE
  18. #error "this file should not be included in subnode"
  19. #endif
  20. #include "benc/Dict.h"
  21. #include "dht/DHTMessage.h"
  22. #include "memory/Allocator.h"
  23. #include "io/Reader.h"
  24. #include "io/Writer.h"
  25. #include "benc/Object.h"
  26. #include "util/log/Log.h"
  27. #include "util/Linker.h"
  28. Linker_require("dht/DHTModuleRegistry.c")
  29. /** State of the registry. */
  30. struct DHTModuleRegistry {
  31. /** Number of members. */
  32. int memberCount;
  33. /** A null terminated list of pointers to members. */
  34. struct DHTModule** members;
  35. /**
  36. * A list of serialized contexts by module name to be
  37. * deserialized when the modules are loaded.
  38. */
  39. Dict* serializedContexts;
  40. /** Means of getting memory for the registry. */
  41. struct Allocator* allocator;
  42. struct Log* log;
  43. };
  44. /**
  45. * Create a new registry.
  46. *
  47. * @param allocator the means of getting memory to store the registry.
  48. * @return a new (empty) registry.
  49. */
  50. struct DHTModuleRegistry* DHTModuleRegistry_new(struct Allocator* allocator, struct Log* log);
  51. /**
  52. * Register an event handler.
  53. *
  54. * @param module the module to register.
  55. * @return 0 if everything went well.
  56. */
  57. int DHTModuleRegistry_register(struct DHTModule* module,
  58. struct DHTModuleRegistry* registry);
  59. /**
  60. * handleIncoming starts by running the last module registered
  61. * and working back. It is assumed that the core modules will
  62. * be registered first and will be the ones to initiate the
  63. * response.
  64. * The last module registered must be the one with access to
  65. * the network.
  66. *
  67. * @see DHTModule->handleIncoming()
  68. */
  69. void DHTModuleRegistry_handleIncoming(struct DHTMessage* message,
  70. const struct DHTModuleRegistry* registry);
  71. /**
  72. * @see DHTModule->handleOutgoing()
  73. */
  74. void DHTModuleRegistry_handleOutgoing(struct DHTMessage* message,
  75. const struct DHTModuleRegistry* registry);
  76. #endif