Asterisk - The Open Source Telephony Project GIT-master-b023714
|
#include "asterisk.h"
#include "asterisk/astdb.h"
#include "asterisk/astobj2.h"
#include "asterisk/module.h"
#include "asterisk/stasis_app_impl.h"
#include "asterisk/stasis_app_device_state.h"
Go to the source code of this file.
Data Structures | |
struct | device_state_subscription |
Device state subscription object. More... | |
Macros | |
#define | DEVICE_STATE_ALL "__AST_DEVICE_STATE_ALL_TOPIC" |
#define | DEVICE_STATE_BUCKETS 37 |
#define | DEVICE_STATE_FAMILY "StasisDeviceState" |
#define | DEVICE_STATE_PROVIDER_STASIS "Stasis" |
#define | DEVICE_STATE_SCHEME_STASIS "Stasis:" |
#define | DEVICE_STATE_SCHEME_SUB "deviceState:" |
#define | DEVICE_STATE_SIZE 64 |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
static void | device_state_cb (void *data, struct stasis_subscription *sub, struct stasis_message *msg) |
static struct device_state_subscription * | device_state_subscription_create (const struct stasis_app *app, const char *device_name) |
static void | device_state_subscription_destroy (void *obj) |
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 | device_to_json_cb (void *obj, void *arg, void *data, int flags) |
static void | devices_to_json (const struct stasis_app *app, struct ast_json *json) |
static void * | find_device_state (const struct stasis_app *app, const char *name) |
static struct device_state_subscription * | find_device_state_subscription (struct stasis_app *app, const char *name) |
static int | is_subscribed_device_state (struct stasis_app *app, const char *name) |
static int | is_subscribed_device_state_lock (struct stasis_app *app, const char *name) |
static int | load_module (void) |
static void | populate_cache (void) |
static void | remove_device_state_subscription (struct device_state_subscription *sub) |
static void | send_device_state (struct device_state_subscription *sub, const char *name, enum ast_device_state state) |
enum stasis_device_state_result | stasis_app_device_state_delete (const char *name) |
Delete a device controlled by ARI. | |
struct ast_json * | stasis_app_device_state_to_json (const char *name, enum ast_device_state state) |
Convert device state to json. | |
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 ast_json * | stasis_app_device_states_to_json (void) |
Convert device states to json array. | |
static enum ast_device_state | stasis_device_state_cb (const char *data) |
static int | subscribe_device_state (struct stasis_app *app, void *obj) |
static int | unload_module (void) |
static int | unsubscribe_device_state (struct stasis_app *app, const char *name) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS , .description = "Stasis application device state support" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_stasis", } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
struct stasis_app_event_source | device_state_event_source |
static struct ao2_container * | device_state_subscriptions |
#define DEVICE_STATE_ALL "__AST_DEVICE_STATE_ALL_TOPIC" |
The key used for tracking a subscription to all device states
Definition at line 46 of file res_stasis_device_state.c.
#define DEVICE_STATE_BUCKETS 37 |
Number of hash buckets for device state subscriptions
Definition at line 43 of file res_stasis_device_state.c.
#define DEVICE_STATE_FAMILY "StasisDeviceState" |
astdb family name
Definition at line 34 of file res_stasis_device_state.c.
#define DEVICE_STATE_PROVIDER_STASIS "Stasis" |
Stasis device state provider
Definition at line 36 of file res_stasis_device_state.c.
#define DEVICE_STATE_SCHEME_STASIS "Stasis:" |
Scheme for custom device states
Definition at line 38 of file res_stasis_device_state.c.
#define DEVICE_STATE_SCHEME_SUB "deviceState:" |
Scheme for device state subscriptions
Definition at line 40 of file res_stasis_device_state.c.
#define DEVICE_STATE_SIZE 64 |
Definition at line 32 of file res_stasis_device_state.c.
|
static |
Definition at line 490 of file res_stasis_device_state.c.
|
static |
Definition at line 490 of file res_stasis_device_state.c.
struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 490 of file res_stasis_device_state.c.
|
static |
Definition at line 301 of file res_stasis_device_state.c.
References ao2_ref, ast_device_state_message_type(), ast_device_state_message::device, ast_device_state_message::eid, send_device_state(), stasis_message_data(), stasis_subscription_final_message(), ast_device_state_message::state, and sub.
Referenced by subscribe_device_state().
|
static |
Definition at line 112 of file res_stasis_device_state.c.
References ao2_alloc, ao2_ref, app, app_name(), ast_string_field_init, ast_string_field_set, ast_strlen_zero(), device_state_subscription::device_name, DEVICE_STATE_ALL, device_state_subscription_destroy(), NULL, stasis_app_name(), and sub.
Referenced by find_device_state(), and subscribe_device_state().
|
static |
Definition at line 106 of file res_stasis_device_state.c.
References ast_string_field_free_memory, and sub.
Referenced by device_state_subscription_create().
|
static |
Definition at line 79 of file res_stasis_device_state.c.
References device_state_subscription::app_name, ast_assert, CMP_MATCH, CMP_STOP, device_state_subscription::device_name, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.
Referenced by load_module().
|
static |
Definition at line 63 of file res_stasis_device_state.c.
References ast_assert, ast_str_hash(), device_state_subscription::device_name, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, and OBJ_SEARCH_OBJECT.
Referenced by load_module().
|
static |
Definition at line 423 of file res_stasis_device_state.c.
References app_name(), array(), ast_json_array_append(), ast_json_string_create(), and sub.
Referenced by devices_to_json().
|
static |
Definition at line 439 of file res_stasis_device_state.c.
References ao2_callback_data, app, array(), ast_json_array_create(), ast_json_object_set(), device_state_subscriptions, device_to_json_cb(), OBJ_NODATA, and stasis_app_name().
|
static |
Definition at line 325 of file res_stasis_device_state.c.
References app, device_state_subscription_create(), and name.
|
static |
Definition at line 140 of file res_stasis_device_state.c.
References ao2_find, app, device_state_subscription::app_name, device_state_subscriptions, name, OBJ_NOLOCK, OBJ_SEARCH_OBJECT, and stasis_app_name().
Referenced by is_subscribed_device_state(), and unsubscribe_device_state().
|
static |
Definition at line 330 of file res_stasis_device_state.c.
References ao2_ref, app, DEVICE_STATE_ALL, find_device_state_subscription(), name, and sub.
Referenced by is_subscribed_device_state_lock(), and subscribe_device_state().
|
static |
Definition at line 349 of file res_stasis_device_state.c.
References ao2_lock, ao2_unlock, app, DEVICE_STATE_ALL, device_state_subscriptions, is_subscribed_device_state(), name, and S_OR.
|
static |
Definition at line 456 of file res_stasis_device_state.c.
References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ast_devstate_prov_add(), ast_devstate_prov_del(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, DEVICE_STATE_BUCKETS, device_state_event_source, DEVICE_STATE_PROVIDER_STASIS, device_state_subscriptions, device_state_subscriptions_cmp(), device_state_subscriptions_hash(), NULL, populate_cache(), stasis_app_register_event_source(), and stasis_device_state_cb().
|
static |
Definition at line 275 of file res_stasis_device_state.c.
References ast_db_freetree(), ast_db_gettree(), AST_DEVSTATE_CACHABLE, ast_devstate_changed(), ast_devstate_val(), ast_strlen_zero(), ast_db_entry::data, DEVICE_STATE_FAMILY, DEVICE_STATE_SCHEME_STASIS, ast_db_entry::key, name, ast_db_entry::next, NULL, and RAII_VAR.
Referenced by load_module().
|
static |
Definition at line 151 of file res_stasis_device_state.c.
References ao2_unlink_flags, device_state_subscriptions, OBJ_NOLOCK, stasis_unsubscribe_and_join(), and sub.
Referenced by unsubscribe_device_state().
|
static |
Definition at line 191 of file res_stasis_device_state.c.
References ast_json_pack(), ast_json_timeval(), ast_json_unref(), ast_log, ast_tvnow(), LOG_ERROR, name, NULL, RAII_VAR, stasis_app_device_state_to_json(), stasis_app_send(), and sub.
Referenced by device_state_cb().
enum stasis_device_state_result stasis_app_device_state_delete | ( | const char * | name | ) |
Delete a device controlled by ARI.
name | the name of the ARI controlled device |
Definition at line 244 of file res_stasis_device_state.c.
References ast_db_del(), ast_device_state_clear_cache(), AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, ast_devstate_changed(), ast_log, ast_strlen_zero(), DEVICE_STATE_FAMILY, DEVICE_STATE_SCHEME_STASIS, LOG_ERROR, name, STASIS_DEVICE_STATE_MISSING, STASIS_DEVICE_STATE_NOT_CONTROLLED, STASIS_DEVICE_STATE_OK, and STASIS_DEVICE_STATE_UNKNOWN.
Referenced by ast_ari_device_states_delete().
struct ast_json * stasis_app_device_state_to_json | ( | const char * | name, |
enum ast_device_state | state | ||
) |
Convert device state to json.
name | the name of the device |
state | the device state |
NULL | on error. |
Definition at line 160 of file res_stasis_device_state.c.
References ast_devstate_str(), ast_json_pack(), and name.
Referenced by ast_ari_device_states_get(), send_device_state(), and stasis_app_device_states_to_json().
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.
name | the name of the ARI controlled device |
value | a valid device state value |
Definition at line 211 of file res_stasis_device_state.c.
References ast_db_put(), ast_debug, AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, ast_devstate_changed(), ast_devstate_val(), ast_log, ast_strlen_zero(), DEVICE_STATE_FAMILY, DEVICE_STATE_SCHEME_STASIS, LOG_ERROR, name, STASIS_DEVICE_STATE_MISSING, STASIS_DEVICE_STATE_NOT_CONTROLLED, STASIS_DEVICE_STATE_OK, STASIS_DEVICE_STATE_UNKNOWN, and value.
Referenced by ast_ari_device_states_update().
struct ast_json * stasis_app_device_states_to_json | ( | void | ) |
Convert device states to json array.
NULL | on error. |
Definition at line 168 of file res_stasis_device_state.c.
References array(), ast_db_freetree(), ast_db_gettree(), ast_json_array_append(), ast_json_array_create(), ast_strlen_zero(), DEVICE_STATE_FAMILY, DEVICE_STATE_SCHEME_STASIS, DEVICE_STATE_SIZE, ast_db_entry::key, name, ast_db_entry::next, NULL, and stasis_app_device_state_to_json().
Referenced by ast_ari_device_states_list().
|
static |
Definition at line 292 of file res_stasis_device_state.c.
References ast_db_get(), ast_devstate_val(), buf, ast_db_entry::data, DEVICE_STATE_FAMILY, and DEVICE_STATE_SIZE.
Referenced by load_module().
|
static |
Definition at line 360 of file res_stasis_device_state.c.
References ao2_bump, ao2_link_flags, ao2_lock, ao2_ref, ao2_unlock, app, ast_debug, ast_device_state_message_type(), ast_device_state_topic(), ast_device_state_topic_all(), ast_log, DEVICE_STATE_ALL, device_state_cb(), device_state_subscription_create(), device_state_subscriptions, is_subscribed_device_state(), LOG_ERROR, NULL, OBJ_NOLOCK, stasis_app_name(), stasis_subscribe_pool, stasis_subscription_accept_message_type(), stasis_subscription_change_type(), STASIS_SUBSCRIPTION_FILTER_SELECTIVE, stasis_subscription_set_filter(), and sub.
|
static |
Definition at line 476 of file res_stasis_device_state.c.
References ao2_cleanup, ast_devstate_prov_del(), device_state_event_source, DEVICE_STATE_PROVIDER_STASIS, device_state_subscriptions, NULL, and stasis_app_unregister_event_source().
|
static |
Definition at line 407 of file res_stasis_device_state.c.
References ao2_cleanup, ao2_lock, ao2_unlock, app, DEVICE_STATE_ALL, device_state_subscriptions, find_device_state_subscription(), name, remove_device_state_subscription(), S_OR, and sub.
|
static |
Definition at line 490 of file res_stasis_device_state.c.
|
static |
Definition at line 490 of file res_stasis_device_state.c.
struct stasis_app_event_source device_state_event_source |
Definition at line 447 of file res_stasis_device_state.c.
Referenced by load_module(), and unload_module().
|
static |
Container for subscribed device states
Definition at line 49 of file res_stasis_device_state.c.
Referenced by devices_to_json(), find_device_state_subscription(), is_subscribed_device_state_lock(), load_module(), remove_device_state_subscription(), subscribe_device_state(), unload_module(), and unsubscribe_device_state().