Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Enumerations | Functions
endpoints.h File Reference

Endpoint abstractions. More...

#include "asterisk/json.h"
Include dependency graph for endpoints.h:
This graph shows which files directly or indirectly include this file:

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.
 
struct ast_endpointast_endpoint_create (const char *tech, const char *resource)
 Create an endpoint struct.
 
struct ast_endpointast_endpoint_find_by_id (const char *id)
 Finds the endpoint with the given tech[/resource] id.
 
const char * ast_endpoint_get_id (const struct ast_endpoint *endpoint)
 Gets the tech/resource id of the given endpoint.
 
const char * ast_endpoint_get_resource (const struct ast_endpoint *endpoint)
 Gets the resource name of the given endpoint.
 
enum ast_endpoint_state ast_endpoint_get_state (const struct ast_endpoint *endpoint)
 Gets the state of the given endpoint.
 
const char * ast_endpoint_get_tech (const struct ast_endpoint *endpoint)
 Gets the technology of the given endpoint.
 
int ast_endpoint_remove_channel (struct ast_endpoint *endpoint, struct ast_channel *chan)
 Removes a channel from the given endpoint.
 
void ast_endpoint_set_max_channels (struct ast_endpoint *endpoint, int max_channels)
 Updates the maximum number of channels an endpoint supports.
 
void ast_endpoint_set_state (struct ast_endpoint *endpoint, enum ast_endpoint_state state)
 Updates the state of the given endpoint.
 
void ast_endpoint_shutdown (struct ast_endpoint *endpoint)
 Shutsdown an ast_endpoint.
 
const char * ast_endpoint_state_to_string (enum ast_endpoint_state state)
 Returns a string representation of the given endpoint state.
 

Detailed Description

Endpoint abstractions.

Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m
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 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.

Enumeration Type Documentation

◆ ast_endpoint_state

Valid states for an endpoint.

Since
12
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.

51 {
52 /*! The endpoint state is not known. */
54 /*! The endpoint is not available. */
56 /*! The endpoint is available. */
58};
@ AST_ENDPOINT_OFFLINE
Definition endpoints.h:55
@ AST_ENDPOINT_ONLINE
Definition endpoints.h:57
@ AST_ENDPOINT_UNKNOWN
Definition endpoints.h:53

Function Documentation

◆ ast_endpoint_add_channel()

int ast_endpoint_add_channel ( struct ast_endpoint endpoint,
struct ast_channel chan 
)

Adds a channel to the given endpoint.

Since
12

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.

Parameters
endpoint
chanChannel.
Return values
0on success.
Non-zeroon error.

Definition at line 156 of file main/endpoints.c.

158{
159 ast_assert(chan != NULL);
160 ast_assert(endpoint != NULL);
162
163 ast_channel_forward_endpoint(chan, endpoint);
164
165 ao2_lock(endpoint);
167 ao2_unlock(endpoint);
168
170
171 return 0;
172}
#define ao2_unlock(a)
Definition astobj2.h:729
#define ao2_lock(a)
Definition astobj2.h:717
const char * ast_channel_uniqueid(const struct ast_channel *chan)
int ast_channel_forward_endpoint(struct ast_channel *chan, struct ast_endpoint *endpoint)
Forward channel stasis messages to the given endpoint.
static void endpoint_publish_snapshot(struct ast_endpoint *endpoint)
#define NULL
Definition resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
int ast_str_container_add(struct ao2_container *str_container, const char *add)
Adds a string to a string container allocated by ast_str_container_alloc.
Definition strings.c:205
struct ao2_container * channel_ids
const ast_string_field resource
#define ast_assert(a)
Definition utils.h:779

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_endpoint_set(), and AST_TEST_DEFINE().

◆ ast_endpoint_create()

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.

Parameters
techTechnology for this endpoint.
resourceName of this endpoint.
Returns
Newly created endpoint.
Return values
NULLon error.
Since
12

Definition at line 280 of file main/endpoints.c.

281{
282 if (ast_strlen_zero(tech)) {
283 ast_log(LOG_ERROR, "Endpoint tech cannot be empty\n");
284 return NULL;
285 }
286
287 if (ast_strlen_zero(resource)) {
288 ast_log(LOG_ERROR, "Endpoint resource cannot be empty\n");
289 return NULL;
290 }
291
292 return endpoint_internal_create(tech, resource);
293}
#define ast_log
Definition astobj2.c:42
#define LOG_ERROR
static struct ast_endpoint * endpoint_internal_create(const char *tech, const char *resource)

References ast_log, ast_strlen_zero(), endpoint_internal_create(), LOG_ERROR, NULL, ast_endpoint::resource, and ast_endpoint::tech.

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), build_peer(), persistent_endpoint_find_or_create(), and xmpp_client_alloc().

◆ ast_endpoint_find_by_id()

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.

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.
Parameters
idTech[/resource] id to look for.
Returns
Associated endpoint.
Return values
NULLif not found.
Since
12

Definition at line 79 of file main/endpoints.c.

80{
81 struct ast_endpoint *endpoint = ao2_find(endpoints, id, OBJ_KEY);
82
83 if (!endpoint) {
84 endpoint = ao2_find(tech_endpoints, id, OBJ_KEY);
85 }
86
87 return endpoint;
88}
#define OBJ_KEY
Definition astobj2.h:1151
#define ao2_find(container, arg, flags)
Definition astobj2.h:1736
static struct ao2_container * tech_endpoints
static struct ao2_container * endpoints

References ao2_find, endpoints, OBJ_KEY, and tech_endpoints.

Referenced by ast_ari_endpoints_list_by_tech(), endpoint_find(), and messaging_app_unsubscribe_endpoint().

◆ ast_endpoint_get_id()

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.

Parameters
endpointThe endpoint.
Returns
Tech/resource id of the endpoint.
Return values
NULLif endpoint is NULL.
Since
12

Definition at line 348 of file main/endpoints.c.

349{
350 if (!endpoint) {
351 return NULL;
352 }
353 return endpoint->id;
354}
const ast_string_field id

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().

◆ ast_endpoint_get_resource()

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.

Note
If the endpoint being queried is a technology aggregate endpoint, this will be an empty string.
Parameters
endpointThe endpoint.
Returns
Resource name of the endpoint.
Return values
NULLif endpoint is NULL.
Since
12

Definition at line 340 of file main/endpoints.c.

341{
342 if (!endpoint) {
343 return NULL;
344 }
345 return endpoint->resource;
346}

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().

◆ ast_endpoint_get_state()

enum ast_endpoint_state ast_endpoint_get_state ( const struct ast_endpoint endpoint)

Gets the state of the given endpoint.

Parameters
endpointThe endpoint.
Returns
state.
Return values
AST_ENDPOINT_UNKNOWNif endpoint is NULL.
Since
13.4

Definition at line 356 of file main/endpoints.c.

357{
358 if (!endpoint) {
360 }
361 return endpoint->state;
362}
enum ast_endpoint_state state

References AST_ENDPOINT_UNKNOWN, and ast_endpoint::state.

Referenced by add_to_regcontext(), and ast_sip_persistent_endpoint_update_state().

◆ ast_endpoint_get_tech()

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.).

Parameters
endpointThe endpoint.
Returns
Tec of the endpoint.
Return values
NULLif endpoint is NULL.
Since
12

Definition at line 332 of file main/endpoints.c.

333{
334 if (!endpoint) {
335 return NULL;
336 }
337 return endpoint->tech;
338}
const ast_string_field tech

References NULL, and ast_endpoint::tech.

Referenced by ast_sip_get_endpoint_snapshot(), AST_TEST_DEFINE(), chan_pjsip_devicestate(), and get_subscription().

◆ ast_endpoint_remove_channel()

int ast_endpoint_remove_channel ( struct ast_endpoint endpoint,
struct ast_channel chan 
)

Removes a channel from the given endpoint.

Since
23.1.0
22.7.0
20.17.0
Parameters
endpoint
chanChannel.
Return values
0on success.
Non-zeroon error.

Definition at line 174 of file main/endpoints.c.

176{
177 ast_assert(chan != NULL);
178 ast_assert(endpoint != NULL);
180
181 ao2_lock(endpoint);
183 ao2_unlock(endpoint);
184
186
187 return 0;
188}
void ast_str_container_remove(struct ao2_container *str_container, const char *remove)
Removes a string from a string container allocated by ast_str_container_alloc.
Definition strings.c:221

References ao2_lock, ao2_unlock, ast_assert, ast_channel_uniqueid(), ast_str_container_remove(), ast_strlen_zero(), ast_endpoint::channel_ids, endpoint_publish_snapshot(), NULL, and ast_endpoint::resource.

Referenced by ast_channel_endpoint_set(), and AST_TEST_DEFINE().

◆ ast_endpoint_set_max_channels()

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.

Parameters
endpointEndpoint to modify.
max_channelsMaximum number of concurrent channels this endpoint supports.

Definition at line 376 of file main/endpoints.c.

378{
379 ast_assert(endpoint != NULL);
381
382 ao2_lock(endpoint);
383 endpoint->max_channels = max_channels;
384 ao2_unlock(endpoint);
386}
int max_channels
Max channels for this endpoint. -1 means unlimited or unknown.

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(), and AST_TEST_DEFINE().

◆ ast_endpoint_set_state()

void ast_endpoint_set_state ( struct ast_endpoint endpoint,
enum ast_endpoint_state  state 
)

Updates the state of the given endpoint.

Parameters
endpointEndpoint to modify.
stateNew state.
Since
12

Definition at line 364 of file main/endpoints.c.

366{
367 ast_assert(endpoint != NULL);
369
370 ao2_lock(endpoint);
371 endpoint->state = state;
372 ao2_unlock(endpoint);
374}

References ao2_lock, ao2_unlock, ast_assert, ast_strlen_zero(), endpoint_publish_snapshot(), NULL, ast_endpoint::resource, and ast_endpoint::state.

Referenced by __expire_registry(), __iax2_poke_noanswer(), ast_sip_persistent_endpoint_update_state(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), persistent_endpoint_find_or_create(), socket_process_helper(), update_registry(), and xmpp_client_change_state().

◆ ast_endpoint_shutdown()

void ast_endpoint_shutdown ( struct ast_endpoint endpoint)

Shutsdown an ast_endpoint.

Parameters
endpointEndpoint to shut down.
Since
12

Definition at line 311 of file main/endpoints.c.

312{
313 RAII_VAR(struct stasis_message *, clear_msg, NULL, ao2_cleanup);
314
315 if (endpoint == NULL) {
316 return;
317 }
318
319 ao2_unlink(endpoints, endpoint);
320 endpoint->tech_forward = stasis_forward_cancel(endpoint->tech_forward);
321
322 clear_msg = create_endpoint_snapshot_message(endpoint);
323 if (clear_msg) {
326 if (message) {
328 }
329 }
330}
#define ao2_cleanup(obj)
Definition astobj2.h:1934
#define ao2_unlink(container, obj)
Remove an object from a container.
Definition astobj2.h:1578
struct stasis_topic * ast_endpoint_topic(struct ast_endpoint *endpoint)
Returns the topic for a specific endpoint.
static struct stasis_message * create_endpoint_snapshot_message(struct ast_endpoint *endpoint)
struct stasis_message * stasis_cache_clear_create(struct stasis_message *message)
A message which instructs the caching topic to remove an entry from its cache.
struct stasis_forward * stasis_forward_cancel(struct stasis_forward *forward)
Definition stasis.c:1615
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
Definition stasis.c:1578
struct stasis_forward * tech_forward
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition utils.h:981

References ao2_cleanup, ao2_unlink, ast_endpoint_topic(), create_endpoint_snapshot_message(), endpoints, NULL, RAII_VAR, stasis_cache_clear_create(), stasis_forward_cancel(), stasis_publish(), and ast_endpoint::tech_forward.

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), peer_destructor(), persistent_endpoint_destroy(), and xmpp_client_destructor().

◆ ast_endpoint_state_to_string()

const char * ast_endpoint_state_to_string ( enum ast_endpoint_state  state)

Returns a string representation of the given endpoint state.

Parameters
stateEndpoint state.
Returns
String representation of state.
Return values
?if state isn't in ast_endpoint_state.

Definition at line 106 of file main/endpoints.c.

107{
108 switch (state) {
110 return "unknown";
112 return "offline";
114 return "online";
115 }
116 return "?";
117}

References AST_ENDPOINT_OFFLINE, AST_ENDPOINT_ONLINE, and AST_ENDPOINT_UNKNOWN.

Referenced by ast_endpoint_snapshot_to_json().