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" 123 size = strlen(device_name) + strlen(app_name) + 2;
175 for (entry = tree; entry; entry = entry->
next) {
176 const char *
name = strrchr(entry->
key,
'/');
197 "type",
"DeviceStateChanged",
217 ast_debug(3,
"Updating device name = %s, value = %s", name, value);
233 "value '%s'\n", value);
246 const char *full_name =
name;
281 for (entry = tree; entry; entry = entry->
next) {
282 const char *
name = strrchr(entry->
key,
'/');
317 if (device_state->
eid) {
353 ao2_lock(device_state_subscriptions);
357 return is_subscribed;
378 ao2_lock(device_state_subscriptions);
411 ao2_lock(device_state_subscriptions);
429 if (strcmp(sub->
app_name, app_name)) {
467 if (!device_state_subscriptions) {
481 device_state_subscriptions =
NULL;
489 .requires =
"res_stasis",
struct stasis_topic * ast_device_state_topic(const char *device)
Get the Stasis topic for device state messages for a specific device.
static struct ao2_container * device_state_subscriptions
enum sip_cc_notify_state state
Stasis Application Device State API. See StasisApplication API" for detailed documentation.
ast_device_state
Device States.
const ast_string_field app_name
Asterisk main include file. File version handling, generic pbx functions.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
#define DEVICE_STATE_SCHEME_STASIS
The arg parameter is a search key, but is not an object.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
const char * scheme
The scheme to match against on [un]subscribes.
#define DEVICE_STATE_SIZE
Device state subscription object.
const ast_string_field device_name
void ast_db_freetree(struct ast_db_entry *entry)
Free structure created by ast_db_gettree()
stasis_device_state_result
enum ast_device_state state
struct ast_json * stasis_app_device_states_to_json(void)
Convert device states to json array.
int ast_devstate_prov_del(const char *label)
Remove device state provider.
Assume that the ao2_container is already locked.
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
int stasis_subscription_set_filter(struct stasis_subscription *subscription, enum stasis_subscription_message_filter filter)
Set the message type filtering level on a subscription.
int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback)
Add device state provider.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define ao2_link_flags(container, obj, flags)
static void send_device_state(struct device_state_subscription *sub, const char *name, enum ast_device_state state)
static void populate_cache(void)
static struct device_state_subscription * device_state_subscription_create(const struct stasis_app *app, const char *device_name)
static int unsubscribe_device_state(struct stasis_app *app, const char *name)
static void * find_device_state(const struct stasis_app *app, const char *name)
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
int ast_device_state_clear_cache(const char *device)
Clear the device from the stasis cache.
#define ast_strlen_zero(foo)
static int subscribe_device_state(struct stasis_app *app, void *obj)
struct stasis_app_event_source device_state_event_source
static int load_module(void)
struct stasis_message_type * ast_device_state_message_type(void)
Get the Stasis message type for device state messages.
#define ast_debug(level,...)
Log a DEBUG message.
struct ast_db_entry * next
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
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.
enum ast_device_state ast_devstate_val(const char *val)
Convert device state from text to integer value.
static void device_state_cb(void *data, struct stasis_subscription *sub, struct stasis_message *msg)
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
const struct ast_eid * eid
The EID of the server where this message originated.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Event source information and callbacks.
#define AST_STRING_FIELD(name)
Declare a string field.
const char * stasis_app_name(const struct stasis_app *app)
Retrieve an application's name.
#define ao2_ref(o, delta)
static int is_subscribed_device_state_lock(struct stasis_app *app, const char *name)
static enum ast_device_state stasis_device_state_cb(const char *data)
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
static int unload_module(void)
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
static int is_subscribed_device_state(struct stasis_app *app, const char *name)
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
#define DEVICE_STATE_PROVIDER_STASIS
void stasis_app_unregister_event_source(struct stasis_app_event_source *obj)
Unregister an application event source.
const char * ast_devstate_str(enum ast_device_state devstate) attribute_pure
Convert device state to text string that is easier to parse.
Backend API for implementing components of res_stasis.
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
#define DEVICE_STATE_SCHEME_SUB
struct ast_db_entry * ast_db_gettree(const char *family, const char *keytree)
Get a list of values within the astdb tree.
static int array(struct ast_channel *chan, const char *cmd, char *var, const char *value)
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
static void remove_device_state_subscription(struct device_state_subscription *sub)
#define ao2_callback_data(container, flags, cb_fn, arg, data)
#define stasis_subscribe_pool(topic, callback, data)
static struct device_state_subscription * find_device_state_subscription(struct stasis_app *app, const char *name)
static int device_state_subscriptions_hash(const void *obj, const int flags)
#define ao2_alloc(data_size, destructor_fn)
struct stasis_topic * ast_device_state_topic_all(void)
Get the Stasis topic for device state messages.
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.
int stasis_app_send(const char *app_name, struct ast_json *message)
Send a message to the given Stasis application.
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.
struct stasis_subscription * stasis_unsubscribe_and_join(struct stasis_subscription *subscription)
Cancel a subscription, blocking until the last message is processed.
Module has failed to load, may be in an inconsistent state.
#define ao2_find(container, arg, flags)
int ast_db_get(const char *family, const char *key, char *value, int valuelen)
Get key value specified by family/key.
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
struct ast_json * stasis_app_device_state_to_json(const char *name, enum ast_device_state state)
Convert device state to json.
static void devices_to_json(const struct stasis_app *app, struct ast_json *json)
#define DEVICE_STATE_FAMILY
struct stasis_subscription * sub
The arg parameter is an object of the same type.
#define DEVICE_STATE_BUCKETS
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
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.
#define ao2_unlink_flags(container, obj, flags)
static void device_state_subscription_destroy(void *obj)
Abstract JSON element (object, array, string, int, ...).
enum stasis_device_state_result stasis_app_device_state_delete(const char *name)
Delete a device controlled by ARI.
The structure that contains device state.
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
struct stasis_message_type * stasis_subscription_change_type(void)
Gets the message type for subscription change notices.
Search option field mask.
static int device_state_subscriptions_cmp(void *obj, void *arg, int flags)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
Persistant data storage (akin to *doze registry)
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
static int device_to_json_cb(void *obj, void *arg, void *data, int flags)
void stasis_app_register_event_source(struct stasis_app_event_source *obj)
Register an application event source.
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.