| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#include "asterisk.h" |
| 30 |
|
| 31 |
#include "asterisk/callerid.h" |
| 32 |
#include "asterisk/channel.h" |
| 33 |
#include "asterisk/manager.h" |
| 34 |
#include "asterisk/stasis_message_router.h" |
| 35 |
#include "asterisk/pbx.h" |
| 36 |
#include "asterisk/stasis_endpoints.h" |
| 37 |
|
| 38 |
static struct stasis_message_router *endpoint_router; |
| 39 |
|
| 40 |
static void manager_endpoints_shutdown(void) |
| 41 |
{ |
| 42 |
stasis_message_router_unsubscribe_and_join(endpoint_router); |
| 43 |
endpoint_router = NULL; |
| 44 |
} |
| 45 |
|
| 46 |
static void endpoint_state_cb(void *data, struct stasis_subscription *sub, |
| 47 |
struct stasis_message *message) |
| 48 |
{ |
| 49 |
stasis_publish(ast_manager_get_topic(), message); |
| 50 |
} |
| 51 |
|
| 52 |
int manager_endpoints_init(void) |
| 53 |
{ |
| 54 |
struct stasis_topic *endpoint_topic; |
| 55 |
int ret = 0; |
| 56 |
|
| 57 |
if (endpoint_router) { |
| 58 |
|
| 59 |
return 0; |
| 60 |
} |
| 61 |
|
| 62 |
ast_register_cleanup(manager_endpoints_shutdown); |
| 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 |
|
| 75 |
ret |= stasis_message_router_add(endpoint_router, ast_endpoint_state_type(), endpoint_state_cb, NULL); |
| 76 |
ret |= stasis_message_router_add(endpoint_router, ast_endpoint_contact_state_type(), endpoint_state_cb, NULL); |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
if (ret) { |
| 82 |
manager_endpoints_shutdown(); |
| 83 |
return -1; |
| 84 |
} |
| 85 |
|
| 86 |
return 0; |
| 87 |
} |