2013-05-08 13:39:08 +00:00
|
|
|
/*
|
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2013, Digium, Inc.
|
|
|
|
|
*
|
|
|
|
|
* David M. Lee, II <dlee@digium.com>
|
|
|
|
|
*
|
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
|
* channels for your use.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
|
* at the top of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef _ASTERISK_ENDPOINTS_H
|
|
|
|
|
#define _ASTERISK_ENDPOINTS_H
|
|
|
|
|
|
|
|
|
|
/*! \file
|
|
|
|
|
*
|
|
|
|
|
* \brief Endpoint abstractions.
|
|
|
|
|
*
|
|
|
|
|
* \author David M. Lee, II <dlee@digium.com>
|
|
|
|
|
* \since 12
|
|
|
|
|
*
|
|
|
|
|
* 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 \a not a core concept within Asterisk iteself.
|
|
|
|
|
*
|
|
|
|
|
* This file defines \ref ast_endpoint as a seperate 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 updates 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "asterisk/json.h"
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Valid states for an endpoint.
|
|
|
|
|
* \since 12
|
|
|
|
|
*/
|
|
|
|
|
enum ast_endpoint_state {
|
|
|
|
|
/*! The endpoint state is not known. */
|
|
|
|
|
AST_ENDPOINT_UNKNOWN,
|
|
|
|
|
/*! The endpoint is not available. */
|
|
|
|
|
AST_ENDPOINT_OFFLINE,
|
|
|
|
|
/*! The endpoint is available. */
|
|
|
|
|
AST_ENDPOINT_ONLINE,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Returns a string representation of the given endpoint state.
|
|
|
|
|
*
|
|
|
|
|
* \param state Endpoint state.
|
|
|
|
|
* \return String representation of \a state.
|
|
|
|
|
* \return \c "?" if \a state isn't in \ref ast_endpoint_state.
|
|
|
|
|
*/
|
|
|
|
|
const char *ast_endpoint_state_to_string(enum ast_endpoint_state state);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Opaque struct representing an endpoint.
|
|
|
|
|
*
|
|
|
|
|
* An endpoint is an external device/system that may offer/accept channels
|
|
|
|
|
* to/from Asterisk.
|
|
|
|
|
*
|
|
|
|
|
* \since 12
|
|
|
|
|
*/
|
|
|
|
|
struct ast_endpoint;
|
|
|
|
|
|
2013-10-04 16:01:48 +00:00
|
|
|
/*!
|
ARI: Fix endpoint/channel subscription issues; allow for subscriptions to tech
This patch serves two purposes:
(1) It fixes some bugs with endpoint subscriptions not reporting all of the
channel events
(2) It serves as the preliminary work needed for ASTERISK-23692, which allows
for sending/receiving arbitrary out of call text messages through ARI in a
technology agnostic fashion.
The messaging functionality described on ASTERISK-23692 requires two things:
(1) The ability to send/receive messages associated with an endpoint. This is
relatively straight forwards with the endpoint core in Asterisk now.
(2) The ability to send/receive messages associated with a technology and an
arbitrary technology defined URI. This is less straight forward, as
endpoints are formed from a tech + resource pair. We don't have a
mechanism to note that a technology that *may* have endpoints exists.
This patch provides such a mechanism, and fixes a few bugs along the way.
The first major bug this patch fixes is the forwarding of channel messages
to their respective endpoints. Prior to this patch, there were two problems:
(1) Channel caching messages weren't forwarded. Thus, the endpoints missed
most of the interesting bits (such as channel creation, destruction, state
changes, etc.)
(2) Channels weren't associated with their endpoint until after creation.
This resulted in endpoints missing the channel creation message, which
limited the usefulness of the subscription in the first place (a major use
case being 'tell me when this endpoint has a channel'). Unfortunately,
this meant another parameter to ast_channel_alloc. Since not all channel
technologies support an ast_endpoint, this patch makes such a call
optional and opts for a new function, ast_channel_alloc_with_endpoint.
When endpoints are created, they will implicitly create a technology endpoint
for their technology (if one does not already exist). A technology endpoint is
special in that it has no state, cannot have channels created for it, cannot
be created explicitly, and cannot be destroyed except on shutdown. It does,
however, have all messages from other endpoints in its technology forwarded to
it.
Combined with the bug fixes, we now have Stasis messages being properly
forwarded. Consider the following scenario: two PJSIP endpoints (foo and bar),
where bar has a single channel associated with it and foo has two channels
associated with it. The messages would be forwarded as follows:
channel PJSIP/foo-1 --
\
--> endpoint PJSIP/foo --
/ \
channel PJSIP/foo-2 -- \
---- > endpoint PJSIP
/
channel PJSIP/bar-1 -----> endpoint PJSIP/bar --
ARI, through the applications resource, can:
- subscribe to endpoint:PJSIP/foo and get notifications for channels
PJSIP/foo-1,PJSIP/foo-2 and endpoint PJSIP/foo
- subscribe to endpoint:PJSIP/bar and get notifications for channels
PJSIP/bar-1 and endpoint PJSIP/bar
- subscribe to endpoint:PJSIP and get notifications for channels
PJSIP/foo-1,PJSIP/foo-2,PJSIP/bar-1 and endpoints PJSIP/foo,PJSIP/bar
Note that since endpoint PJSIP never changes, it never has events itself. It
merely provides an aggregation point for all other endpoints in its technology
(which in turn aggregate all channel messages associated with that endpoint).
This patch also adds endpoints to res_xmpp and chan_motif, because the actual
messaging work will need it (messaging without XMPP is just sad).
Review: https://reviewboard.asterisk.org/r/3760/
ASTERISK-23692
........
Merged revisions 419196 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419203 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-22 16:20:58 +00:00
|
|
|
* \brief Finds the endpoint with the given tech[/resource] id.
|
2013-10-04 16:01:48 +00:00
|
|
|
*
|
|
|
|
|
* Endpoints are refcounted, so ao2_cleanup() when you're done.
|
|
|
|
|
*
|
ARI: Fix endpoint/channel subscription issues; allow for subscriptions to tech
This patch serves two purposes:
(1) It fixes some bugs with endpoint subscriptions not reporting all of the
channel events
(2) It serves as the preliminary work needed for ASTERISK-23692, which allows
for sending/receiving arbitrary out of call text messages through ARI in a
technology agnostic fashion.
The messaging functionality described on ASTERISK-23692 requires two things:
(1) The ability to send/receive messages associated with an endpoint. This is
relatively straight forwards with the endpoint core in Asterisk now.
(2) The ability to send/receive messages associated with a technology and an
arbitrary technology defined URI. This is less straight forward, as
endpoints are formed from a tech + resource pair. We don't have a
mechanism to note that a technology that *may* have endpoints exists.
This patch provides such a mechanism, and fixes a few bugs along the way.
The first major bug this patch fixes is the forwarding of channel messages
to their respective endpoints. Prior to this patch, there were two problems:
(1) Channel caching messages weren't forwarded. Thus, the endpoints missed
most of the interesting bits (such as channel creation, destruction, state
changes, etc.)
(2) Channels weren't associated with their endpoint until after creation.
This resulted in endpoints missing the channel creation message, which
limited the usefulness of the subscription in the first place (a major use
case being 'tell me when this endpoint has a channel'). Unfortunately,
this meant another parameter to ast_channel_alloc. Since not all channel
technologies support an ast_endpoint, this patch makes such a call
optional and opts for a new function, ast_channel_alloc_with_endpoint.
When endpoints are created, they will implicitly create a technology endpoint
for their technology (if one does not already exist). A technology endpoint is
special in that it has no state, cannot have channels created for it, cannot
be created explicitly, and cannot be destroyed except on shutdown. It does,
however, have all messages from other endpoints in its technology forwarded to
it.
Combined with the bug fixes, we now have Stasis messages being properly
forwarded. Consider the following scenario: two PJSIP endpoints (foo and bar),
where bar has a single channel associated with it and foo has two channels
associated with it. The messages would be forwarded as follows:
channel PJSIP/foo-1 --
\
--> endpoint PJSIP/foo --
/ \
channel PJSIP/foo-2 -- \
---- > endpoint PJSIP
/
channel PJSIP/bar-1 -----> endpoint PJSIP/bar --
ARI, through the applications resource, can:
- subscribe to endpoint:PJSIP/foo and get notifications for channels
PJSIP/foo-1,PJSIP/foo-2 and endpoint PJSIP/foo
- subscribe to endpoint:PJSIP/bar and get notifications for channels
PJSIP/bar-1 and endpoint PJSIP/bar
- subscribe to endpoint:PJSIP and get notifications for channels
PJSIP/foo-1,PJSIP/foo-2,PJSIP/bar-1 and endpoints PJSIP/foo,PJSIP/bar
Note that since endpoint PJSIP never changes, it never has events itself. It
merely provides an aggregation point for all other endpoints in its technology
(which in turn aggregate all channel messages associated with that endpoint).
This patch also adds endpoints to res_xmpp and chan_motif, because the actual
messaging work will need it (messaging without XMPP is just sad).
Review: https://reviewboard.asterisk.org/r/3760/
ASTERISK-23692
........
Merged revisions 419196 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419203 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-22 16:20:58 +00:00
|
|
|
* \note The resource portion of an ID is optional. If not provided,
|
|
|
|
|
* an aggregate endpoint for the entire technology is returned.
|
|
|
|
|
* These endpoints must not be modified, but can be subscribed
|
|
|
|
|
* to in order to receive updates for all endpoints of a given
|
|
|
|
|
* technology.
|
|
|
|
|
*
|
|
|
|
|
* \param id Tech[/resource] id to look for.
|
2013-10-04 16:01:48 +00:00
|
|
|
* \return Associated endpoint.
|
|
|
|
|
* \return \c NULL if not found.
|
|
|
|
|
*
|
|
|
|
|
* \since 12
|
|
|
|
|
*/
|
|
|
|
|
struct ast_endpoint *ast_endpoint_find_by_id(const char *id);
|
|
|
|
|
|
2013-05-08 13:39:08 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief Create an endpoint struct.
|
|
|
|
|
*
|
|
|
|
|
* The endpoint is created with a state of UNKNOWN and max_channels of -1
|
|
|
|
|
* (unlimited). While \ref ast_endpoint is AO2 managed, you have to
|
|
|
|
|
* shut it down with ast_endpoint_shutdown() to clean up references from
|
|
|
|
|
* subscriptions.
|
|
|
|
|
*
|
|
|
|
|
* \param tech Technology for this endpoint.
|
|
|
|
|
* \param resource Name of this endpoint.
|
|
|
|
|
* \return Newly created endpoint.
|
|
|
|
|
* \return \c NULL on error.
|
|
|
|
|
* \since 12
|
|
|
|
|
*/
|
|
|
|
|
struct ast_endpoint *ast_endpoint_create(const char *tech, const char *resource);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Shutsdown an \ref ast_endpoint.
|
|
|
|
|
*
|
|
|
|
|
* \param endpoint Endpoint to shut down.
|
|
|
|
|
* \since 12
|
|
|
|
|
*/
|
|
|
|
|
void ast_endpoint_shutdown(struct ast_endpoint *endpoint);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Gets the technology of the given endpoint.
|
|
|
|
|
*
|
|
|
|
|
* This is an immutable string describing the channel provider technology
|
|
|
|
|
* (SIP, IAX2, etc.).
|
|
|
|
|
*
|
|
|
|
|
* \param endpoint The endpoint.
|
|
|
|
|
* \return Tec of the endpoint.
|
|
|
|
|
* \return \c NULL if endpoint is \c NULL.
|
|
|
|
|
* \since 12
|
|
|
|
|
*/
|
|
|
|
|
const char *ast_endpoint_get_tech(const struct ast_endpoint *endpoint);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Gets the resource name of the given endpoint.
|
|
|
|
|
*
|
|
|
|
|
* This is unique for the endpoint's technology, and immutable.
|
|
|
|
|
*
|
ARI: Fix endpoint/channel subscription issues; allow for subscriptions to tech
This patch serves two purposes:
(1) It fixes some bugs with endpoint subscriptions not reporting all of the
channel events
(2) It serves as the preliminary work needed for ASTERISK-23692, which allows
for sending/receiving arbitrary out of call text messages through ARI in a
technology agnostic fashion.
The messaging functionality described on ASTERISK-23692 requires two things:
(1) The ability to send/receive messages associated with an endpoint. This is
relatively straight forwards with the endpoint core in Asterisk now.
(2) The ability to send/receive messages associated with a technology and an
arbitrary technology defined URI. This is less straight forward, as
endpoints are formed from a tech + resource pair. We don't have a
mechanism to note that a technology that *may* have endpoints exists.
This patch provides such a mechanism, and fixes a few bugs along the way.
The first major bug this patch fixes is the forwarding of channel messages
to their respective endpoints. Prior to this patch, there were two problems:
(1) Channel caching messages weren't forwarded. Thus, the endpoints missed
most of the interesting bits (such as channel creation, destruction, state
changes, etc.)
(2) Channels weren't associated with their endpoint until after creation.
This resulted in endpoints missing the channel creation message, which
limited the usefulness of the subscription in the first place (a major use
case being 'tell me when this endpoint has a channel'). Unfortunately,
this meant another parameter to ast_channel_alloc. Since not all channel
technologies support an ast_endpoint, this patch makes such a call
optional and opts for a new function, ast_channel_alloc_with_endpoint.
When endpoints are created, they will implicitly create a technology endpoint
for their technology (if one does not already exist). A technology endpoint is
special in that it has no state, cannot have channels created for it, cannot
be created explicitly, and cannot be destroyed except on shutdown. It does,
however, have all messages from other endpoints in its technology forwarded to
it.
Combined with the bug fixes, we now have Stasis messages being properly
forwarded. Consider the following scenario: two PJSIP endpoints (foo and bar),
where bar has a single channel associated with it and foo has two channels
associated with it. The messages would be forwarded as follows:
channel PJSIP/foo-1 --
\
--> endpoint PJSIP/foo --
/ \
channel PJSIP/foo-2 -- \
---- > endpoint PJSIP
/
channel PJSIP/bar-1 -----> endpoint PJSIP/bar --
ARI, through the applications resource, can:
- subscribe to endpoint:PJSIP/foo and get notifications for channels
PJSIP/foo-1,PJSIP/foo-2 and endpoint PJSIP/foo
- subscribe to endpoint:PJSIP/bar and get notifications for channels
PJSIP/bar-1 and endpoint PJSIP/bar
- subscribe to endpoint:PJSIP and get notifications for channels
PJSIP/foo-1,PJSIP/foo-2,PJSIP/bar-1 and endpoints PJSIP/foo,PJSIP/bar
Note that since endpoint PJSIP never changes, it never has events itself. It
merely provides an aggregation point for all other endpoints in its technology
(which in turn aggregate all channel messages associated with that endpoint).
This patch also adds endpoints to res_xmpp and chan_motif, because the actual
messaging work will need it (messaging without XMPP is just sad).
Review: https://reviewboard.asterisk.org/r/3760/
ASTERISK-23692
........
Merged revisions 419196 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419203 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-22 16:20:58 +00:00
|
|
|
* \note If the endpoint being queried is a technology aggregate
|
|
|
|
|
* endpoint, this will be an empty string.
|
|
|
|
|
*
|
2013-05-08 13:39:08 +00:00
|
|
|
* \param endpoint The endpoint.
|
|
|
|
|
* \return Resource name of the endpoint.
|
|
|
|
|
* \return \c NULL if endpoint is \c NULL.
|
|
|
|
|
* \since 12
|
|
|
|
|
*/
|
|
|
|
|
const char *ast_endpoint_get_resource(const struct ast_endpoint *endpoint);
|
|
|
|
|
|
2013-10-04 16:01:48 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief Gets the tech/resource id of the given endpoint.
|
|
|
|
|
*
|
|
|
|
|
* This is unique across all endpoints, and immutable.
|
|
|
|
|
*
|
|
|
|
|
* \param endpoint The endpoint.
|
|
|
|
|
* \return Tech/resource id of the endpoint.
|
|
|
|
|
* \return \c NULL if endpoint is \c NULL.
|
|
|
|
|
* \since 12
|
|
|
|
|
*/
|
|
|
|
|
const char *ast_endpoint_get_id(const struct ast_endpoint *endpoint);
|
|
|
|
|
|
2015-04-11 15:56:52 -06:00
|
|
|
/*!
|
|
|
|
|
* \brief Gets the state of the given endpoint.
|
|
|
|
|
*
|
|
|
|
|
* \param endpoint The endpoint.
|
|
|
|
|
* \return state.
|
|
|
|
|
* \return \c AST_ENDPOINT_UNKNOWN if endpoint is \c NULL.
|
|
|
|
|
* \since 13.4
|
|
|
|
|
*/
|
|
|
|
|
enum ast_endpoint_state ast_endpoint_get_state(const struct ast_endpoint *endpoint);
|
|
|
|
|
|
2013-05-08 13:39:08 +00:00
|
|
|
/*!
|
|
|
|
|
* \brief Updates the state of the given endpoint.
|
|
|
|
|
*
|
|
|
|
|
* \param endpoint Endpoint to modify.
|
|
|
|
|
* \param state New state.
|
|
|
|
|
* \since 12
|
|
|
|
|
*/
|
|
|
|
|
void ast_endpoint_set_state(struct ast_endpoint *endpoint,
|
|
|
|
|
enum ast_endpoint_state state);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Updates the maximum number of channels an endpoint supports.
|
|
|
|
|
*
|
|
|
|
|
* Set to -1 for unlimited channels.
|
|
|
|
|
*
|
|
|
|
|
* \param endpoint Endpoint to modify.
|
|
|
|
|
* \param max_channels Maximum number of concurrent channels this endpoint
|
|
|
|
|
* supports.
|
|
|
|
|
*/
|
|
|
|
|
void ast_endpoint_set_max_channels(struct ast_endpoint *endpoint,
|
|
|
|
|
int max_channels);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \since 12
|
|
|
|
|
* \brief Adds a channel to the given endpoint.
|
|
|
|
|
*
|
|
|
|
|
* This updates the endpoint's statistics, as well as forwarding all of the
|
|
|
|
|
* channel's messages to the endpoint's topic.
|
|
|
|
|
*
|
|
|
|
|
* The channel is automagically removed from the endpoint when it is disposed
|
|
|
|
|
* of.
|
|
|
|
|
*
|
|
|
|
|
* \param endpoint
|
|
|
|
|
* \param chan Channel.
|
|
|
|
|
* \retval 0 on success.
|
|
|
|
|
* \retval Non-zero on error.
|
|
|
|
|
*/
|
|
|
|
|
int ast_endpoint_add_channel(struct ast_endpoint *endpoint,
|
|
|
|
|
struct ast_channel *chan);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* _ASTERISK_ENDPOINTS_H */
|