Hermes.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 Hermes_H
  16. #define Hermes_H
  17. #include "benc/Dict.h"
  18. #include "memory/Allocator.h"
  19. #include "exception/Except.h"
  20. #include "interface/Interface.h"
  21. #include "util/log/Log.h"
  22. #include "util/events/EventBase.h"
  23. #include "util/Linker.h"
  24. Linker_require("admin/angel/Hermes.c")
  25. /**
  26. * Hermes is the god of transitions and boundaries, moving freely between
  27. * the worlds of the mortal and divine, as messenger of the gods.
  28. * IE: The communications pipeline between the core and the angel.
  29. * Hermes is used by the core to make admin API calls against the angel.
  30. */
  31. struct Hermes;
  32. typedef void (* Hermes_onResponse)(Dict* responseMessage, void* context);
  33. /**
  34. * Make a call to the angel and get the response.
  35. *
  36. * @param message the message to send, the txid key is reserved and will
  37. * be overwritten.
  38. * @param onResponse a callback which will be called with the response
  39. * from the angel. This callback will also be called if
  40. * there is no response and the request times out.
  41. * @param onResponseContext a pointer which will be provided to onResponse.
  42. * @param alloc an allocator for the request, if this allocator is freed
  43. * before the response happens, the onResponse will not be
  44. * called, this prevents a race condition when the structure
  45. * pointed to be context is freed after a call. The allocator
  46. * need not be freed after the request is complete.
  47. * @param eh an exception handler.
  48. * @param hermes the Hermes.
  49. */
  50. void Hermes_callAngel(Dict* message,
  51. Hermes_onResponse onResponse,
  52. void* onResponseContext,
  53. struct Allocator* alloc,
  54. struct Except* eh,
  55. struct Hermes* hermes);
  56. struct Hermes* Hermes_new(struct Interface* angelIface,
  57. struct EventBase* eventBase,
  58. struct Log* logger,
  59. struct Allocator* alloc);
  60. #endif