diff options
author | David M. Lee <dlee@digium.com> | 2013-05-08 13:39:08 +0000 |
---|---|---|
committer | David M. Lee <dlee@digium.com> | 2013-05-08 13:39:08 +0000 |
commit | e06e519a908dd7640764778cfb91c29699f3f679 (patch) | |
tree | f85a10cf963caba787a9e506963e0ef4d63c0ff1 /main/channel_internal_api.c | |
parent | efd28c676a4a467f1bb31d3359c43c2f1d70029b (diff) |
Initial support for endpoints.
An endpoint is an external device/system that may offer/accept
channels to/from Asterisk. While this is a very useful concept for end
users, it is surprisingly not a core concept within Asterisk itself.
This patch defines ast_endpoint as a separate object, which channel
drivers may use to expose their concept of an endpoint. As the channel
driver creates channels, it can use ast_endpoint_add_channel() to
associate channels to the endpoint. This updated the endpoint
appropriately, and forwards all of the channel's events to the
endpoint's topic.
In order to avoid excessive locking on the endpoint object itself, the
mutable state is not accessible via getters. Instead, you can create a
snapshot using ast_endpoint_snapshot_create() to get a consistent
snapshot of the internal state.
This patch also includes a set of topics and messages associated with
endpoints, and implementations of the endpoint-related RESTful
API. chan_sip was updated to create endpoints with SIP peers, but the
state of the endpoints is not updated with the state of the peer.
Along for the ride in this patch is a Stasis test API. This is a
stasis_message_sink object, which can be subscribed to a Stasis
topic. It has functions for blocking while waiting for conditions in
the message sink to be fulfilled.
(closes issue ASTERISK-21421)
Review: https://reviewboard.asterisk.org/r/2492/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387932 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/channel_internal_api.c')
-rw-r--r-- | main/channel_internal_api.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c index cb9ed6744..f3293d59b 100644 --- a/main/channel_internal_api.c +++ b/main/channel_internal_api.c @@ -39,11 +39,13 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include <fcntl.h> #include "asterisk/channel.h" -#include "asterisk/stringfields.h" +#include "asterisk/channel_internal.h" #include "asterisk/data.h" +#include "asterisk/endpoints.h" #include "asterisk/indications.h" #include "asterisk/stasis_channels.h" -#include "asterisk/channel_internal.h" +#include "asterisk/stasis_endpoints.h" +#include "asterisk/stringfields.h" #include "asterisk/test.h" /*! @@ -198,6 +200,7 @@ struct ast_channel { struct timeval sending_dtmf_tv; /*!< The time this channel started sending the current digit. (Invalid if sending_dtmf_digit is zero.) */ struct stasis_topic *topic; /*!< Topic for all channel's events */ struct stasis_subscription *forwarder; /*!< Subscription for event forwarding to all topic */ + struct stasis_subscription *endpoint_forward; /*!< Subscription for event forwarding to endpoint's topic */ }; /* AST_DATA definitions, which will probably have to be re-thought since the channel will be opaque */ @@ -1369,6 +1372,7 @@ void ast_channel_internal_cleanup(struct ast_channel *chan) ast_string_field_free_memory(chan); chan->forwarder = stasis_unsubscribe(chan->forwarder); + chan->endpoint_forward = stasis_unsubscribe(chan->endpoint_forward); ao2_cleanup(chan->topic); chan->topic = NULL; @@ -1389,6 +1393,37 @@ struct stasis_topic *ast_channel_topic(struct ast_channel *chan) return chan ? chan->topic : ast_channel_topic_all(); } +int ast_endpoint_add_channel(struct ast_endpoint *endpoint, + struct ast_channel *chan) +{ + RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup); + RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup); + + ast_assert(chan != NULL); + ast_assert(endpoint != NULL); + + snapshot = ast_channel_snapshot_create(chan); + if (!snapshot) { + return -1; + } + + msg = stasis_message_create(ast_channel_snapshot_type(), snapshot); + if (!msg) { + return -1; + } + + chan->endpoint_forward = + stasis_forward_all(chan->topic, ast_endpoint_topic(endpoint)); + + if (chan->endpoint_forward == NULL) { + return -1; + } + + stasis_publish(ast_endpoint_topic(endpoint), msg); + + return 0; +} + void ast_channel_internal_setup_topics(struct ast_channel *chan) { const char *topic_name = chan->uniqueid; |