1
0

DHTModuleRegistry.h 2.5 KB

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