DHTModuleRegistry.h 2.4 KB

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