32#define DEVICE_STATE_SIZE 64
34#define DEVICE_STATE_FAMILY "StasisDeviceState"
36#define DEVICE_STATE_PROVIDER_STASIS "Stasis"
38#define DEVICE_STATE_SCHEME_STASIS "Stasis:"
40#define DEVICE_STATE_SCHEME_SUB "deviceState:"
43#define DEVICE_STATE_BUCKETS 37
46#define DEVICE_STATE_ALL "__AST_DEVICE_STATE_ALL_TOPIC"
197 "type",
"DeviceStateChanged",
198 "application",
sub->app_name,
233 "value '%s'\n",
value);
246 const char *full_name =
name;
317 if (device_state->
eid) {
357 return is_subscribed;
386 ast_debug(3,
"Subscribing to device %s\n",
sub->device_name);
489 .
requires =
"res_stasis",
Persistent data storage (akin to *doze registry)
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
struct ast_db_entry * ast_db_gettree(const char *family, const char *keytree)
Get a list of values within the astdb tree.
void ast_db_freetree(struct ast_db_entry *entry)
Free structure created by ast_db_gettree()
Asterisk main include file. File version handling, generic pbx functions.
@ AO2_ALLOC_OPT_LOCK_MUTEX
#define ao2_callback_data(container, flags, cb_fn, arg, data)
#define ao2_unlink_flags(container, obj, flags)
Remove an object from a container.
#define ao2_link_flags(container, obj, flags)
Add an object to a container.
#define ao2_find(container, arg, flags)
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
@ OBJ_SEARCH_PARTIAL_KEY
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
@ OBJ_SEARCH_OBJECT
The arg parameter is an object of the same type.
@ OBJ_NOLOCK
Assume that the ao2_container is already locked.
@ OBJ_SEARCH_MASK
Search option field mask.
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
#define ao2_alloc(data_size, destructor_fn)
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
struct stasis_message_type * ast_device_state_message_type(void)
Get the Stasis message type for device state messages.
int ast_devstate_prov_del(const char *label)
Remove device state provider.
const char * ast_devstate_str(enum ast_device_state devstate) attribute_pure
Convert device state to text string that is easier to parse.
int ast_devstate_changed(enum ast_device_state state, enum ast_devstate_cache cachable, const char *fmt,...)
Tells Asterisk the State for Device is changed.
struct stasis_topic * ast_device_state_topic_all(void)
Get the Stasis topic for device state messages.
int ast_device_state_clear_cache(const char *device)
Clear the device from the stasis cache.
enum ast_device_state ast_devstate_val(const char *val)
Convert device state from text to integer value.
struct stasis_topic * ast_device_state_topic(const char *device)
Get the Stasis topic for device state messages for a specific device.
int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback)
Add device state provider.
ast_device_state
Device States.
static int array(struct ast_channel *chan, const char *cmd, char *var, const char *value)
struct stasis_message_type * stasis_subscription_change_type(void)
Gets the message type for subscription change notices.
#define ast_debug(level,...)
Log a DEBUG message.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Asterisk module definitions.
@ AST_MODFLAG_GLOBAL_SYMBOLS
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODULE_SUPPORT_CORE
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
const char * app_name(struct ast_app *app)
struct stasis_forward * sub
#define DEVICE_STATE_BUCKETS
enum stasis_device_state_result stasis_app_device_state_update(const char *name, const char *value)
Changes the state of a device controlled by ARI.
static int subscribe_device_state(struct stasis_app *app, void *obj)
enum stasis_device_state_result stasis_app_device_state_delete(const char *name)
Delete a device controlled by ARI.
static void * find_device_state(const struct stasis_app *app, const char *name)
struct ast_json * stasis_app_device_states_to_json(void)
Convert device states to json array.
static struct ao2_container * device_state_subscriptions
static void device_state_subscription_destroy(void *obj)
static struct device_state_subscription * find_device_state_subscription(struct stasis_app *app, const char *name)
struct stasis_app_event_source device_state_event_source
static int is_subscribed_device_state(struct stasis_app *app, const char *name)
#define DEVICE_STATE_SCHEME_STASIS
static struct device_state_subscription * device_state_subscription_create(const struct stasis_app *app, const char *device_name)
#define DEVICE_STATE_SIZE
#define DEVICE_STATE_SCHEME_SUB
static int device_to_json_cb(void *obj, void *arg, void *data, int flags)
static void remove_device_state_subscription(struct device_state_subscription *sub)
static int unsubscribe_device_state(struct stasis_app *app, const char *name)
static void populate_cache(void)
static void send_device_state(struct device_state_subscription *sub, const char *name, enum ast_device_state state)
#define DEVICE_STATE_PROVIDER_STASIS
static void device_state_cb(void *data, struct stasis_subscription *sub, struct stasis_message *msg)
static int device_state_subscriptions_cmp(void *obj, void *arg, int flags)
static int device_state_subscriptions_hash(const void *obj, const int flags)
static int is_subscribed_device_state_lock(struct stasis_app *app, const char *name)
static int load_module(void)
static int unload_module(void)
static enum ast_device_state stasis_device_state_cb(const char *data)
#define DEVICE_STATE_FAMILY
static void devices_to_json(const struct stasis_app *app, struct ast_json *json)
struct ast_json * stasis_app_device_state_to_json(const char *name, enum ast_device_state state)
Convert device state to json.
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
@ STASIS_SUBSCRIPTION_FILTER_SELECTIVE
int stasis_subscription_accept_message_type(struct stasis_subscription *subscription, const struct stasis_message_type *type)
Indicate to a subscription that we are interested in a message type.
int stasis_subscription_set_filter(struct stasis_subscription *subscription, enum stasis_subscription_message_filter filter)
Set the message type filtering level on a subscription.
#define stasis_subscribe_pool(topic, callback, data)
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
int stasis_subscription_final_message(struct stasis_subscription *sub, struct stasis_message *msg)
Determine whether a message is the final message to be received on a subscription.
struct stasis_subscription * stasis_unsubscribe_and_join(struct stasis_subscription *subscription)
Cancel a subscription, blocking until the last message is processed.
int stasis_app_send(const char *app_name, struct ast_json *message)
Send a message to the given Stasis application.
void stasis_app_unregister_event_source(struct stasis_app_event_source *obj)
Unregister an application event source.
void stasis_app_register_event_source(struct stasis_app_event_source *obj)
Register an application event source.
const char * stasis_app_name(const struct stasis_app *app)
Retrieve an application's name.
Stasis Application Device State API. See StasisApplication API" for detailed documentation.
stasis_device_state_result
@ STASIS_DEVICE_STATE_NOT_CONTROLLED
@ STASIS_DEVICE_STATE_MISSING
@ STASIS_DEVICE_STATE_UNKNOWN
Backend API for implementing components of res_stasis.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
The structure that contains device state.
enum ast_device_state state
const struct ast_eid * eid
The EID of the server where this message originated.
Abstract JSON element (object, array, string, int, ...).
Device state subscription object.
struct stasis_subscription * sub
const ast_string_field device_name
const ast_string_field app_name
Event source information and callbacks.
const char * scheme
The scheme to match against on [un]subscribes.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.