Add DeviceStateChanged and PresenceStateChanged AMI events.
[asterisk/asterisk.git] / res / res_manager_devicestate.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2014, Digium, Inc.
5  *
6  * Mark Michelson <mmichelson@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 #include "asterisk.h"
20 #include "asterisk/module.h"
21 #include "asterisk/stasis.h"
22 #include "asterisk/devicestate.h"
23
24 static struct stasis_forward *topic_forwarder;
25
26 static int unload_module(void)
27 {
28         topic_forwarder = stasis_forward_cancel(topic_forwarder);
29         return 0;
30 }
31
32 static int load_module(void)
33 {
34         struct stasis_topic *manager_topic;
35
36         manager_topic = ast_manager_get_topic();
37         if (!manager_topic) {
38                 return AST_MODULE_LOAD_DECLINE;
39         }
40
41         topic_forwarder = stasis_forward_all(ast_device_state_topic_all(), manager_topic);
42
43         return AST_MODULE_LOAD_SUCCESS;
44 }
45
46 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Manager Device State Topic Forwarder",
47                 .load = load_module,
48                 .unload = unload_module,
49                 .load_pri = AST_MODPRI_DEVSTATE_CONSUMER,
50         );