DHTModuleRegistry.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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/Linker.h"
  27. Linker_require("dht/DHTModuleRegistry.c");
  28. /** State of the registry. */
  29. struct DHTModuleRegistry {
  30. /** Number of members. */
  31. int memberCount;
  32. /** A null terminated list of pointers to members. */
  33. struct DHTModule** members;
  34. /**
  35. * A list of serialized contexts by module name to be
  36. * deserialized when the modules are loaded.
  37. */
  38. Dict* serializedContexts;
  39. /** Means of getting memory for the registry. */
  40. struct Allocator* allocator;
  41. };
  42. /**
  43. * Create a new registry.
  44. *
  45. * @param allocator the means of getting memory to store the registry.
  46. * @return a new (empty) registry.
  47. */
  48. struct DHTModuleRegistry* DHTModuleRegistry_new(struct Allocator* allocator);
  49. /**
  50. * Register an event handler.
  51. *
  52. * @param module the module to register.
  53. * @return 0 if everything went well.
  54. */
  55. int DHTModuleRegistry_register(struct DHTModule* module,
  56. struct DHTModuleRegistry* registry);
  57. /**
  58. * handleIncoming starts by running the last module registered
  59. * and working back. It is assumed that the core modules will
  60. * be registered first and will be the ones to initiate the
  61. * response.
  62. * The last module registered must be the one with access to
  63. * the network.
  64. *
  65. * @see DHTModule->handleIncoming()
  66. */
  67. void DHTModuleRegistry_handleIncoming(struct DHTMessage* message,
  68. const struct DHTModuleRegistry* registry);
  69. /**
  70. * @see DHTModule->handleOutgoing()
  71. */
  72. void DHTModuleRegistry_handleOutgoing(struct DHTMessage* message,
  73. const struct DHTModuleRegistry* registry);
  74. #endif