PJPROJECT logging: Made easier to get available logging levels.
[asterisk/asterisk.git] / main / manager_system.c
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
19 /*! \file
20  *
21  * \brief System AMI event handling
22  *
23  * \author Jason Parker <jparker@digium.com>
24  */
25
26 #include "asterisk.h"
27
28 #include "asterisk/stasis.h"
29 #include "asterisk/stasis_message_router.h"
30 #include "asterisk/stasis_system.h"
31
32 /*! \brief The \ref stasis subscription returned by the forwarding of the system topic
33  * to the manager topic
34  */
35 static struct stasis_forward *topic_forwarder;
36
37 static void manager_system_shutdown(void)
38 {
39         stasis_forward_cancel(topic_forwarder);
40         topic_forwarder = NULL;
41 }
42
43 int manager_system_init(void)
44 {
45         int ret = 0;
46         struct stasis_topic *manager_topic;
47         struct stasis_topic *system_topic;
48         struct stasis_message_router *message_router;
49
50         manager_topic = ast_manager_get_topic();
51         if (!manager_topic) {
52                 return -1;
53         }
54         message_router = ast_manager_get_message_router();
55         if (!message_router) {
56                 return -1;
57         }
58         system_topic = ast_system_topic();
59         if (!system_topic) {
60                 return -1;
61         }
62
63         topic_forwarder = stasis_forward_all(system_topic, manager_topic);
64         if (!topic_forwarder) {
65                 return -1;
66         }
67
68         ast_register_cleanup(manager_system_shutdown);
69
70         /* If somehow we failed to add any routes, just shut down the whole
71          * thing and fail it.
72          */
73         if (ret) {
74                 manager_system_shutdown();
75                 return -1;
76         }
77
78         return 0;
79 }