Asterisk - The Open Source Telephony Project  GIT-master-44aef04
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"

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


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

David M. Lee, II

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.

snapshotEndpoint snapshot.
sanitizeThe message sanitizer to use on the snapshot
JSON object representing endpoint snapshot.
NULL on error

Definition at line 398 of file stasis_endpoints.c.

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

401 {
402  struct ast_json *json;
403  struct ast_json *channel_array;
404  int i;
406  json = ast_json_pack("{s: s, s: s, s: s, s: []}",
407  "technology", snapshot->tech,
408  "resource", snapshot->resource,
409  "state", ast_endpoint_state_to_string(snapshot->state),
410  "channel_ids");
412  if (json == NULL) {
413  return NULL;
414  }
416  if (snapshot->max_channels != -1) {
417  int res = ast_json_object_set(json, "max_channels",
419  if (res != 0) {
420  ast_json_unref(json);
422  return NULL;
423  }
424  }
426  channel_array = ast_json_object_get(json, "channel_ids");
427  ast_assert(channel_array != NULL);
428  for (i = 0; i < snapshot->num_channels; ++i) {
429  int res;
431  if (sanitize && sanitize->channel_id
432  && sanitize->channel_id(snapshot->channel_ids[i])) {
433  continue;
434  }
436  res = ast_json_array_append(channel_array,
437  ast_json_string_create(snapshot->channel_ids[i]));
438  if (res != 0) {
439  ast_json_unref(json);
441  return NULL;
442  }
443  }
445  return json;
446 }
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
int(* channel_id)(const char *channel_id)
Callback which determines whether a channel should be sanitized from a message based on the channel&#39;s...
Definition: stasis.h:210
#define ast_assert(a)
Definition: utils.h:650
#define NULL
Definition: resample.c:96
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:404
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:268
const ast_string_field resource
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
Definition: json.c:368
const ast_string_field tech
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_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:397
Abstract JSON element (object, array, string, int, ...).
enum ast_endpoint_state state
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
Definition: json.c:317

◆ ast_endpoint_stasis_init()

int ast_endpoint_stasis_init ( void  )

Initialization function for endpoint stasis support.

0 on success.
non-zero on error.

Definition at line 458 of file stasis_endpoints.c.

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

Referenced by asterisk_daemon().

459 {
460  int res = 0;
463  endpoint_cache_all = stasis_cp_all_create("endpoint:all",
465  if (!endpoint_cache_all) {
466  return -1;
467  }
473  return res;
474 }
Boiler-plate messaging macro for initializing message types.
Definition: stasis.h:1501
struct stasis_message_type * ast_endpoint_snapshot_type(void)
Message type for ast_endpoint_snapshot.
static const char * endpoint_snapshot_get_id(struct stasis_message *message)
Callback extract a unique identity from a snapshot message.
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_state_type(void)
Message type for endpoint state changes.
static struct stasis_cp_all * endpoint_cache_all
static void endpoints_stasis_cleanup(void)
struct stasis_message_type * ast_endpoint_contact_state_type(void)
Message type for endpoint contact state changes.
struct stasis_cp_all * stasis_cp_all_create(const char *name, snapshot_get_id id_fn)
Create an all instance of the cache pattern.