Asterisk - The Open Source Telephony Project  18.5.0
manager_endpoints.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2013, Digium, Inc.
5  *
6  * Joshua Colp <[email protected]>
7  * David M. Lee, II <[email protected]>
8  *
9  * See http://www.asterisk.org for more information about
10  * the Asterisk project. Please do not directly contact
11  * any of the maintainers of this project for assistance;
12  * the project provides a web site, mailing lists and IRC
13  * channels for your use.
14  *
15  * This program is free software, distributed under the terms of
16  * the GNU General Public License Version 2. See the LICENSE file
17  * at the top of the source tree.
18  */
19 
20 /*! \file
21  *
22  * \brief The Asterisk Management Interface - AMI (endpoint handling)
23  *
24  * \author Joshua Colp <[email protected]>
25  * \author David M. Lee, II <[email protected]>
26  *
27  */
28 
29 #include "asterisk.h"
30 
31 #include "asterisk/callerid.h"
32 #include "asterisk/channel.h"
33 #include "asterisk/manager.h"
35 #include "asterisk/pbx.h"
37 
39 
40 static void manager_endpoints_shutdown(void)
41 {
43  endpoint_router = NULL;
44 }
45 
46 static void endpoint_state_cb(void *data, struct stasis_subscription *sub,
47  struct stasis_message *message)
48 {
50 }
51 
53 {
54  struct stasis_topic *endpoint_topic;
55  int ret = 0;
56 
57  if (endpoint_router) {
58  /* Already initialized */
59  return 0;
60  }
61 
63 
64  endpoint_topic = ast_endpoint_topic_all_cached();
65  if (!endpoint_topic) {
66  return -1;
67  }
68 
69  endpoint_router = stasis_message_router_create(endpoint_topic);
70 
71  if (!endpoint_router) {
72  return -1;
73  }
74 
77 
78  /* If somehow we failed to add any routes, just shut down the whole
79  * thing and fail it.
80  */
81  if (ret) {
83  return -1;
84  }
85 
86  return 0;
87 }
Asterisk main include file. File version handling, generic pbx functions.
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
int stasis_message_router_add(struct stasis_message_router *router, struct stasis_message_type *message_type, stasis_subscription_cb callback, void *data)
Add a route to a message router.
void stasis_message_router_unsubscribe_and_join(struct stasis_message_router *router)
Unsubscribe the router from the upstream topic, blocking until the final message has been processed...
#define NULL
Definition: resample.c:96
static void endpoint_state_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
struct stasis_topic * ast_endpoint_topic_all_cached(void)
Cached topic for all endpoint related messages.
static struct stasis_message_router * endpoint_router
General Asterisk PBX channel definitions.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
Core PBX routines and definitions.
#define stasis_message_router_create(topic)
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
struct stasis_message_type * ast_endpoint_state_type(void)
Message type for endpoint state changes.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic&#39;s subscribers.
Definition: stasis.c:1511
static void manager_endpoints_shutdown(void)
struct stasis_topic * ast_manager_get_topic(void)
Get the Stasis Message Bus API topic for AMI.
Definition: manager.c:1720
struct stasis_forward * sub
Definition: res_corosync.c:240
struct stasis_message_type * ast_endpoint_contact_state_type(void)
Message type for endpoint contact state changes.
int manager_endpoints_init(void)
Initialize support for AMI endpoint events.
Endpoint abstractions.