Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
Endpoint abstractions. More...
#include "asterisk/json.h"
Go to the source code of this file.
Enumerations | |
enum | ast_endpoint_state { AST_ENDPOINT_UNKNOWN , AST_ENDPOINT_OFFLINE , AST_ENDPOINT_ONLINE } |
Valid states for an endpoint. More... | |
Functions | |
int | ast_endpoint_add_channel (struct ast_endpoint *endpoint, struct ast_channel *chan) |
Adds a channel to the given endpoint. More... | |
struct ast_endpoint * | ast_endpoint_create (const char *tech, const char *resource) |
Create an endpoint struct. More... | |
struct ast_endpoint * | ast_endpoint_find_by_id (const char *id) |
Finds the endpoint with the given tech[/resource] id. More... | |
const char * | ast_endpoint_get_id (const struct ast_endpoint *endpoint) |
Gets the tech/resource id of the given endpoint. More... | |
const char * | ast_endpoint_get_resource (const struct ast_endpoint *endpoint) |
Gets the resource name of the given endpoint. More... | |
enum ast_endpoint_state | ast_endpoint_get_state (const struct ast_endpoint *endpoint) |
Gets the state of the given endpoint. More... | |
const char * | ast_endpoint_get_tech (const struct ast_endpoint *endpoint) |
Gets the technology of the given endpoint. More... | |
void | ast_endpoint_set_max_channels (struct ast_endpoint *endpoint, int max_channels) |
Updates the maximum number of channels an endpoint supports. More... | |
void | ast_endpoint_set_state (struct ast_endpoint *endpoint, enum ast_endpoint_state state) |
Updates the state of the given endpoint. More... | |
void | ast_endpoint_shutdown (struct ast_endpoint *endpoint) |
Shutsdown an ast_endpoint. More... | |
const char * | ast_endpoint_state_to_string (enum ast_endpoint_state state) |
Returns a string representation of the given endpoint state. More... | |
Endpoint abstractions.
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 file defines 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.
Definition in file endpoints.h.
enum ast_endpoint_state |
Valid states for an endpoint.
Enumerator | |
---|---|
AST_ENDPOINT_UNKNOWN | The endpoint state is not known. |
AST_ENDPOINT_OFFLINE | The endpoint is not available. |
AST_ENDPOINT_ONLINE | The endpoint is available. |
Definition at line 51 of file endpoints.h.
int ast_endpoint_add_channel | ( | struct ast_endpoint * | endpoint, |
struct ast_channel * | chan | ||
) |
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.
endpoint | |
chan | Channel. |
0 | on success. |
Non-zero | on error. |
Definition at line 164 of file main/endpoints.c.
References ao2_lock, ao2_unlock, ast_assert, ast_channel_forward_endpoint(), ast_channel_uniqueid(), ast_str_container_add(), ast_strlen_zero(), ast_endpoint::channel_ids, endpoint_publish_snapshot(), NULL, and ast_endpoint::resource.
Referenced by __ast_channel_alloc_ap(), and AST_TEST_DEFINE().
struct ast_endpoint * ast_endpoint_create | ( | const char * | tech, |
const char * | resource | ||
) |
Create an endpoint struct.
The endpoint is created with a state of UNKNOWN and max_channels of -1 (unlimited). While ast_endpoint is AO2 managed, you have to shut it down with ast_endpoint_shutdown() to clean up references from subscriptions.
tech | Technology for this endpoint. |
resource | Name of this endpoint. |
NULL | on error. |
Definition at line 319 of file main/endpoints.c.
References ast_log, ast_strlen_zero(), endpoint_internal_create(), LOG_ERROR, NULL, ast_endpoint::resource, and ast_endpoint::tech.
Referenced by AST_TEST_DEFINE(), build_peer(), persistent_endpoint_find_or_create(), and xmpp_client_alloc().
struct ast_endpoint * ast_endpoint_find_by_id | ( | const char * | id | ) |
Finds the endpoint with the given tech[/resource] id.
Endpoints are refcounted, so ao2_cleanup() when you're done.
id | Tech[/resource] id to look for. |
NULL | if not found. |
Definition at line 82 of file main/endpoints.c.
References ao2_find, endpoints, OBJ_KEY, and tech_endpoints.
Referenced by ast_ari_endpoints_list_by_tech(), endpoint_find(), and messaging_app_unsubscribe_endpoint().
const char * ast_endpoint_get_id | ( | const struct ast_endpoint * | endpoint | ) |
Gets the tech/resource id of the given endpoint.
This is unique across all endpoints, and immutable.
endpoint | The endpoint. |
NULL | if endpoint is NULL . |
Definition at line 391 of file main/endpoints.c.
References ast_endpoint::id, and NULL.
Referenced by app_subscribe_endpoint(), forwards_create_endpoint(), get_or_create_subscription(), get_subscription(), messaging_app_subscribe_endpoint(), and messaging_app_unsubscribe_endpoint().
const char * ast_endpoint_get_resource | ( | const struct ast_endpoint * | endpoint | ) |
Gets the resource name of the given endpoint.
This is unique for the endpoint's technology, and immutable.
endpoint | The endpoint. |
NULL | if endpoint is NULL . |
Definition at line 383 of file main/endpoints.c.
References NULL, and ast_endpoint::resource.
Referenced by add_to_regcontext(), ast_sip_get_endpoint_snapshot(), ast_sip_persistent_endpoint_publish_contact_state(), ast_sip_persistent_endpoint_update_state(), AST_TEST_DEFINE(), chan_pjsip_devicestate(), endpoint_deleted_observer(), get_or_create_subscription(), get_subscription(), messaging_app_unsubscribe_endpoint(), persistent_endpoint_cmp(), and persistent_endpoint_hash().
enum ast_endpoint_state ast_endpoint_get_state | ( | const struct ast_endpoint * | endpoint | ) |
Gets the state of the given endpoint.
endpoint | The endpoint. |
AST_ENDPOINT_UNKNOWN | if endpoint is NULL . |
Definition at line 399 of file main/endpoints.c.
References AST_ENDPOINT_UNKNOWN, and ast_endpoint::state.
Referenced by add_to_regcontext(), and ast_sip_persistent_endpoint_update_state().
const char * ast_endpoint_get_tech | ( | const struct ast_endpoint * | endpoint | ) |
Gets the technology of the given endpoint.
This is an immutable string describing the channel provider technology (SIP, IAX2, etc.).
endpoint | The endpoint. |
NULL | if endpoint is NULL . |
Definition at line 375 of file main/endpoints.c.
References NULL, and ast_endpoint::tech.
Referenced by ast_sip_get_endpoint_snapshot(), AST_TEST_DEFINE(), chan_pjsip_devicestate(), and get_subscription().
void ast_endpoint_set_max_channels | ( | struct ast_endpoint * | endpoint, |
int | max_channels | ||
) |
Updates the maximum number of channels an endpoint supports.
Set to -1 for unlimited channels.
endpoint | Endpoint to modify. |
max_channels | Maximum number of concurrent channels this endpoint supports. |
Definition at line 419 of file main/endpoints.c.
References ao2_lock, ao2_unlock, ast_assert, ast_strlen_zero(), endpoint_publish_snapshot(), ast_endpoint::max_channels, NULL, and ast_endpoint::resource.
Referenced by AST_TEST_DEFINE().
void ast_endpoint_set_state | ( | struct ast_endpoint * | endpoint, |
enum ast_endpoint_state | state | ||
) |
Updates the state of the given endpoint.
endpoint | Endpoint to modify. |
state | New state. |
Definition at line 407 of file main/endpoints.c.
References ao2_lock, ao2_unlock, ast_assert, ast_strlen_zero(), endpoint_publish_snapshot(), NULL, ast_endpoint::resource, state, and ast_endpoint::state.
Referenced by __expire_registry(), __iax2_poke_noanswer(), ast_sip_persistent_endpoint_update_state(), AST_TEST_DEFINE(), persistent_endpoint_find_or_create(), socket_process_helper(), update_registry(), and xmpp_client_change_state().
void ast_endpoint_shutdown | ( | struct ast_endpoint * | endpoint | ) |
Shutsdown an ast_endpoint.
endpoint | Endpoint to shut down. |
Definition at line 350 of file main/endpoints.c.
References ao2_cleanup, ao2_ref, ao2_unlink, ast_endpoint_topic(), create_endpoint_snapshot_message(), endpoints, NULL, RAII_VAR, ast_endpoint::router, stasis_cache_clear_create(), stasis_forward_cancel(), stasis_message_router_unsubscribe(), stasis_publish(), and ast_endpoint::tech_forward.
Referenced by AST_TEST_DEFINE(), peer_destructor(), persistent_endpoint_destroy(), and xmpp_client_destructor().
const char * ast_endpoint_state_to_string | ( | enum ast_endpoint_state | state | ) |
Returns a string representation of the given endpoint state.
state | Endpoint state. |
? | if state isn't in ast_endpoint_state. |
Definition at line 109 of file main/endpoints.c.
References AST_ENDPOINT_OFFLINE, AST_ENDPOINT_ONLINE, and AST_ENDPOINT_UNKNOWN.
Referenced by ast_endpoint_snapshot_to_json().