Hermes.h 2.8 KB

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