Asterisk - The Open Source Telephony Project GIT-master-a358458
stasis_app_device_state.h File Reference

Stasis Application Device State API. See StasisApplication API" for detailed documentation. More...

#include "asterisk/app.h"
#include "asterisk/stasis_app.h"
Include dependency graph for stasis_app_device_state.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

enum stasis_device_state_result stasis_app_device_state_delete (const char *name)
 Delete a device controlled by ARI. More...
 
struct ast_jsonstasis_app_device_state_to_json (const char *name, enum ast_device_state state)
 Convert device state to json. More...
 
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. More...
 
struct ast_jsonstasis_app_device_states_to_json (void)
 Convert device states to json array. More...
 
enum  stasis_device_state_result {
  STASIS_DEVICE_STATE_OK , STASIS_DEVICE_STATE_NOT_CONTROLLED , STASIS_DEVICE_STATE_MISSING , STASIS_DEVICE_STATE_UNKNOWN ,
  STASIS_DEVICE_STATE_SUBSCRIBERS
}
 

Detailed Description

Stasis Application Device State API. See StasisApplication API" for detailed documentation.

Author
Kevin Harwell kharw.nosp@m.ell@.nosp@m.digiu.nosp@m.m.co.nosp@m.m
Since
12

Definition in file stasis_app_device_state.h.

Enumeration Type Documentation

◆ stasis_device_state_result

Stasis device state application result codes

Enumerator
STASIS_DEVICE_STATE_OK 

Application controlled device state is okay

STASIS_DEVICE_STATE_NOT_CONTROLLED 

The device name is not application controlled

STASIS_DEVICE_STATE_MISSING 

The application controlled device name is missing

STASIS_DEVICE_STATE_UNKNOWN 

The application controlled device is unknown

STASIS_DEVICE_STATE_SUBSCRIBERS 

The application controlled device has subscribers

Definition at line 56 of file stasis_app_device_state.h.

56 {
57 /*! Application controlled device state is okay */
59 /*! The device name is not application controlled */
61 /*! The application controlled device name is missing */
63 /*! The application controlled device is unknown */
65 /*! The application controlled device has subscribers */
67};
@ STASIS_DEVICE_STATE_SUBSCRIBERS
@ STASIS_DEVICE_STATE_NOT_CONTROLLED
@ STASIS_DEVICE_STATE_OK
@ STASIS_DEVICE_STATE_MISSING
@ STASIS_DEVICE_STATE_UNKNOWN

Function Documentation

◆ stasis_app_device_state_delete()

enum stasis_device_state_result stasis_app_device_state_delete ( const char *  name)

Delete a device controlled by ARI.

Parameters
namethe name of the ARI controlled device
Returns
stasis device state application result.

Definition at line 244 of file res_stasis_device_state.c.

245{
246 const char *full_name = name;
247 size_t size = strlen(DEVICE_STATE_SCHEME_STASIS);
248
249 if (strncasecmp(name, DEVICE_STATE_SCHEME_STASIS, size)) {
250 ast_log(LOG_ERROR, "Can only delete '%s' device states!\n",
253 }
254
255 name += size;
256 if (ast_strlen_zero(name)) {
257 ast_log(LOG_ERROR, "Delete requires a device name!\n");
259 }
260
261 if (ast_device_state_clear_cache(full_name)) {
263 }
264
266
267 /* send state change for delete */
271
273}
int ast_db_del(const char *family, const char *key)
Delete entry in astdb.
Definition: main/db.c:476
#define ast_log
Definition: astobj2.c:42
@ AST_DEVSTATE_CACHABLE
Definition: devicestate.h:70
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.
Definition: devicestate.c:510
int ast_device_state_clear_cache(const char *device)
Clear the device from the stasis cache.
Definition: devicestate.c:688
@ AST_DEVICE_UNKNOWN
Definition: devicestate.h:53
static const char name[]
Definition: format_mp3.c:68
#define LOG_ERROR
#define DEVICE_STATE_SCHEME_STASIS
#define DEVICE_STATE_FAMILY
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65

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

◆ stasis_app_device_state_to_json()

struct ast_json * stasis_app_device_state_to_json ( const char *  name,
enum ast_device_state  state 
)

Convert device state to json.

Parameters
namethe name of the device
statethe device state
Returns
JSON representation.
Return values
NULLon error.

Definition at line 160 of file res_stasis_device_state.c.

162{
163 return ast_json_pack("{s: s, s: s}",
164 "name", name,
165 "state", ast_devstate_str(state));
166}
const char * ast_devstate_str(enum ast_device_state devstate) attribute_pure
Convert device state to text string that is easier to parse.
Definition: devicestate.c:255
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612

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

◆ stasis_app_device_state_update()

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.

Note
The controlled device must be prefixed with 'Stasis:'.
Implicitly creates the device state.
Parameters
namethe name of the ARI controlled device
valuea valid device state value
Returns
a stasis device state application result.

Definition at line 211 of file res_stasis_device_state.c.

213{
214 size_t size = strlen(DEVICE_STATE_SCHEME_STASIS);
216
217 ast_debug(3, "Updating device name = %s, value = %s", name, value);
218
219 if (strncasecmp(name, DEVICE_STATE_SCHEME_STASIS, size)) {
220 ast_log(LOG_ERROR, "Update can only be used to set "
221 "'%s' device state!\n", DEVICE_STATE_SCHEME_STASIS);
223 }
224
225 name += size;
226 if (ast_strlen_zero(name)) {
227 ast_log(LOG_ERROR, "Update requires custom device name!\n");
229 }
230
232 ast_log(LOG_ERROR, "Unknown device state "
233 "value '%s'\n", value);
235 }
236
240
242}
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition: main/db.c:342
enum cc_state state
Definition: ccss.c:393
enum ast_device_state ast_devstate_val(const char *val)
Convert device state from text to integer value.
Definition: devicestate.c:260
ast_device_state
Device States.
Definition: devicestate.h:52
#define ast_debug(level,...)
Log a DEBUG message.
int value
Definition: syslog.c:37

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, state, and value.

Referenced by ast_ari_device_states_update().

◆ stasis_app_device_states_to_json()

struct ast_json * stasis_app_device_states_to_json ( void  )

Convert device states to json array.

Returns
JSON representation.
Return values
NULLon error.

Definition at line 168 of file res_stasis_device_state.c.

169{
171 struct ast_db_entry *tree;
172 struct ast_db_entry *entry;
173
175 for (entry = tree; entry; entry = entry->next) {
176 const char *name = strrchr(entry->key, '/');
177
178 if (!ast_strlen_zero(name)) {
179 char device[DEVICE_STATE_SIZE];
180
181 snprintf(device, sizeof(device), "%s%s", DEVICE_STATE_SCHEME_STASIS, ++name);
184 }
185 }
186 ast_db_freetree(tree);
187
188 return array;
189}
struct ast_db_entry * ast_db_gettree(const char *family, const char *keytree)
Get a list of values within the astdb tree.
Definition: main/db.c:610
void ast_db_freetree(struct ast_db_entry *entry)
Free structure created by ast_db_gettree()
Definition: main/db.c:677
static int array(struct ast_channel *chan, const char *cmd, char *var, const char *value)
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_array_create(void)
Create a empty JSON array.
Definition: json.c:362
#define DEVICE_STATE_SIZE
struct ast_json * stasis_app_device_state_to_json(const char *name, enum ast_device_state state)
Convert device state to json.
#define NULL
Definition: resample.c:96
Definition: astdb.h:31
Abstract JSON element (object, array, string, int, ...).
Definition: search.h:40
char * key
Definition: search.h:41

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, entry::key, name, NULL, and stasis_app_device_state_to_json().

Referenced by ast_ari_device_states_list().