manager_system.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Digium, Inc.
  5. *
  6. * Jason Parker <jparker@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. *
  20. * \brief System AMI event handling
  21. *
  22. * \author Jason Parker <jparker@digium.com>
  23. */
  24. #include "asterisk.h"
  25. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  26. #include "asterisk/stasis.h"
  27. #include "asterisk/stasis_message_router.h"
  28. #include "asterisk/stasis_system.h"
  29. /*! \brief The \ref stasis subscription returned by the forwarding of the system topic
  30. * to the manager topic
  31. */
  32. static struct stasis_forward *topic_forwarder;
  33. static void manager_system_shutdown(void)
  34. {
  35. stasis_forward_cancel(topic_forwarder);
  36. topic_forwarder = NULL;
  37. }
  38. int manager_system_init(void)
  39. {
  40. int ret = 0;
  41. struct stasis_topic *manager_topic;
  42. struct stasis_topic *system_topic;
  43. struct stasis_message_router *message_router;
  44. manager_topic = ast_manager_get_topic();
  45. if (!manager_topic) {
  46. return -1;
  47. }
  48. message_router = ast_manager_get_message_router();
  49. if (!message_router) {
  50. return -1;
  51. }
  52. system_topic = ast_system_topic();
  53. if (!system_topic) {
  54. return -1;
  55. }
  56. topic_forwarder = stasis_forward_all(system_topic, manager_topic);
  57. if (!topic_forwarder) {
  58. return -1;
  59. }
  60. ast_register_cleanup(manager_system_shutdown);
  61. /* If somehow we failed to add any routes, just shut down the whole
  62. * thing and fail it.
  63. */
  64. if (ret) {
  65. manager_system_shutdown();
  66. return -1;
  67. }
  68. return 0;
  69. }