Asterisk - The Open Source Telephony Project GIT-master-8f1982c
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Data Structures | Functions
stasis_endpoints.h File Reference

Endpoint abstractions. More...

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

Go to the source code of this file.

Data Structures

struct  ast_endpoint_blob
 Blob of data associated with an endpoint. More...
 
struct  ast_endpoint_snapshot
 A snapshot of an endpoint's state. More...
 

Functions

struct stasis_messageast_endpoint_blob_create (struct ast_endpoint *endpoint, struct stasis_message_type *type, struct ast_json *blob)
 Creates a ast_endpoint_blob message. More...
 
void ast_endpoint_blob_publish (struct ast_endpoint *endpoint, struct stasis_message_type *type, struct ast_json *blob)
 Creates and publishes a ast_endpoint_blob message. More...
 
struct stasis_cacheast_endpoint_cache (void)
 Backend cache for ast_endpoint_topic_all_cached(). More...
 
struct stasis_cp_allast_endpoint_cache_all (void)
 
struct stasis_message_typeast_endpoint_contact_state_type (void)
 Message type for endpoint contact state changes. More...
 
struct ast_endpoint_snapshotast_endpoint_latest_snapshot (const char *tech, const char *resource)
 Retrieve the most recent snapshot for the endpoint with the given name. More...
 
struct ast_endpoint_snapshotast_endpoint_snapshot_create (struct ast_endpoint *endpoint)
 Create a snapshot of an endpoint. More...
 
struct ast_jsonast_endpoint_snapshot_to_json (const struct ast_endpoint_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
 Build a JSON object from a ast_endpoint_snapshot. More...
 
struct stasis_message_typeast_endpoint_snapshot_type (void)
 Message type for ast_endpoint_snapshot. More...
 
int ast_endpoint_stasis_init (void)
 Initialization function for endpoint stasis support. More...
 
struct stasis_message_typeast_endpoint_state_type (void)
 Message type for endpoint state changes. More...
 
struct stasis_topicast_endpoint_topic (struct ast_endpoint *endpoint)
 Returns the topic for a specific endpoint. More...
 
struct stasis_topicast_endpoint_topic_all (void)
 Topic for all endpoint related messages. More...
 
struct stasis_topicast_endpoint_topic_all_cached (void)
 Cached topic for all endpoint related messages. More...
 
struct stasis_topicast_endpoint_topic_cached (struct ast_endpoint *endpoint)
 Returns the topic for a specific endpoint. More...
 

Detailed Description

Endpoint abstractions.

Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m
Since
12

Definition in file stasis_endpoints.h.

Function Documentation

◆ ast_endpoint_snapshot_to_json()

struct ast_json * ast_endpoint_snapshot_to_json ( const struct ast_endpoint_snapshot snapshot,
const struct stasis_message_sanitizer sanitize 
)

Build a JSON object from a ast_endpoint_snapshot.

Parameters
snapshotEndpoint snapshot.
sanitizeThe message sanitizer to use on the snapshot
Returns
JSON object representing endpoint snapshot.
Return values
NULLon error

Definition at line 404 of file stasis_endpoints.c.

407{
408 struct ast_json *json;
409 struct ast_json *channel_array;
410 int i;
411
412 json = ast_json_pack("{s: s, s: s, s: s, s: []}",
413 "technology", snapshot->tech,
414 "resource", snapshot->resource,
415 "state", ast_endpoint_state_to_string(snapshot->state),
416 "channel_ids");
417
418 if (json == NULL) {
419 return NULL;
420 }
421
422 if (snapshot->max_channels != -1) {
423 int res = ast_json_object_set(json, "max_channels",
425 if (res != 0) {
426 ast_json_unref(json);
427
428 return NULL;
429 }
430 }
431
432 channel_array = ast_json_object_get(json, "channel_ids");
433 ast_assert(channel_array != NULL);
434 for (i = 0; i < snapshot->num_channels; ++i) {
435 int res;
436
437 if (sanitize && sanitize->channel_id
438 && sanitize->channel_id(snapshot->channel_ids[i])) {
439 continue;
440 }
441
442 res = ast_json_array_append(channel_array,
443 ast_json_string_create(snapshot->channel_ids[i]));
444 if (res != 0) {
445 ast_json_unref(json);
446
447 return NULL;
448 }
449 }
450
451 return json;
452}
const char * ast_endpoint_state_to_string(enum ast_endpoint_state state)
Returns a string representation of the given endpoint state.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:278
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
Definition: json.c:378
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
Definition: json.c:327
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition: json.c:414
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:407
#define NULL
Definition: resample.c:96
const ast_string_field tech
enum ast_endpoint_state state
const ast_string_field resource
Abstract JSON element (object, array, string, int, ...).
int(* channel_id)(const char *channel_id)
Callback which determines whether a channel should be sanitized from a message based on the channel's...
Definition: stasis.h:210
#define ast_assert(a)
Definition: utils.h:739

References ast_assert, ast_endpoint_state_to_string(), ast_json_array_append(), ast_json_integer_create(), ast_json_object_get(), ast_json_object_set(), ast_json_pack(), ast_json_string_create(), ast_json_unref(), stasis_message_sanitizer::channel_id, ast_endpoint_snapshot::channel_ids, ast_endpoint_snapshot::max_channels, NULL, ast_endpoint_snapshot::num_channels, ast_endpoint_snapshot::resource, ast_endpoint_snapshot::state, and ast_endpoint_snapshot::tech.

Referenced by ast_ari_endpoints_get(), ast_ari_endpoints_list(), ast_ari_endpoints_list_by_tech(), contactstatus_to_json(), message_received_handler(), multi_user_event_to_json(), peerstatus_to_json(), and simple_endpoint_event().

◆ ast_endpoint_stasis_init()

int ast_endpoint_stasis_init ( void  )

Initialization function for endpoint stasis support.

Returns
0 on success.
non-zero on error.
Since
12

Definition at line 464 of file stasis_endpoints.c.

465{
466 int res = 0;
468
471 if (!endpoint_cache_all) {
472 return -1;
473 }
474
478
479 return res;
480}
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
struct stasis_message_type * ast_endpoint_contact_state_type(void)
Message type for endpoint contact state changes.
struct stasis_message_type * ast_endpoint_snapshot_type(void)
Message type for ast_endpoint_snapshot.
struct stasis_message_type * ast_endpoint_state_type(void)
Message type for endpoint state changes.
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition: stasis.h:1493
struct stasis_cp_all * stasis_cp_all_create(const char *name, snapshot_get_id id_fn)
Create an all instance of the cache pattern.
static const char * endpoint_snapshot_get_id(struct stasis_message *message)
Callback extract a unique identity from a snapshot message.
static void endpoints_stasis_cleanup(void)
static struct stasis_cp_all * endpoint_cache_all

References ast_endpoint_contact_state_type(), ast_endpoint_snapshot_type(), ast_endpoint_state_type(), ast_register_cleanup(), endpoint_cache_all, endpoint_snapshot_get_id(), endpoints_stasis_cleanup(), stasis_cp_all_create(), and STASIS_MESSAGE_TYPE_INIT.

Referenced by asterisk_daemon().