Asterisk - The Open Source Telephony Project GIT-master-55f4e6d
Data Structures | Typedefs | Enumerations | Functions
presencestate.h File Reference

Presence state management. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_presence_state_message
 Stasis message payload representing a presence state update. More...
 

Typedefs

typedef enum ast_presence_state(* ast_presence_state_prov_cb_type) (const char *data, char **subtype, char **message)
 Presence state provider call back. More...
 

Enumerations

enum  ast_presence_state {
  AST_PRESENCE_NOT_SET = 0 , AST_PRESENCE_UNAVAILABLE , AST_PRESENCE_AVAILABLE , AST_PRESENCE_AWAY ,
  AST_PRESENCE_XA , AST_PRESENCE_CHAT , AST_PRESENCE_DND , AST_PRESENCE_INVALID
}
 

Functions

enum ast_presence_state ast_presence_state (const char *presence_provider, char **subtype, char **message)
 Asks a presence state provider for the current presence state. More...
 
const char * ast_presence_state2str (enum ast_presence_state state)
 Convert presence state to text string for output. More...
 
struct stasis_cacheast_presence_state_cache (void)
 Backend cache for ast_presence_state_topic_cached() More...
 
int ast_presence_state_changed (enum ast_presence_state state, const char *subtype, const char *message, const char *fmt,...)
 Notify the world that a presence provider state changed. More...
 
int ast_presence_state_changed_literal (enum ast_presence_state state, const char *subtype, const char *message, const char *presence_provider)
 Notify the world that a presence provider state changed. More...
 
int ast_presence_state_engine_init (void)
 
struct stasis_message_typeast_presence_state_message_type (void)
 Get presence state message type. More...
 
enum ast_presence_state ast_presence_state_nocache (const char *presence_provider, char **subtype, char **message)
 Asks a presence state provider for the current presence state, bypassing the event cache. More...
 
int ast_presence_state_prov_add (const char *label, ast_presence_state_prov_cb_type callback)
 Add presence state provider. More...
 
int ast_presence_state_prov_del (const char *label)
 Remove presence state provider. More...
 
struct stasis_topicast_presence_state_topic_all (void)
 Get presence state topic. More...
 
struct stasis_topicast_presence_state_topic_cached (void)
 Get caching presence state topic. More...
 
enum ast_presence_state ast_presence_state_val (const char *val)
 Convert presence state from text to integer value. More...
 

Detailed Description

Presence state management.

Definition in file presencestate.h.

Typedef Documentation

◆ ast_presence_state_prov_cb_type

typedef enum ast_presence_state(* ast_presence_state_prov_cb_type) (const char *data, char **subtype, char **message)

Presence state provider call back.

Definition at line 1 of file presencestate.h.

Enumeration Type Documentation

◆ ast_presence_state

Enumerator
AST_PRESENCE_NOT_SET 
AST_PRESENCE_UNAVAILABLE 
AST_PRESENCE_AVAILABLE 
AST_PRESENCE_AWAY 
AST_PRESENCE_XA 
AST_PRESENCE_CHAT 
AST_PRESENCE_DND 
AST_PRESENCE_INVALID 

Definition at line 26 of file presencestate.h.

26 {
34 /* This is not something that a user can
35 * set his presence to. Rather, this is returned
36 * to indicate that presence is in some invalid
37 * state
38 */
40};
@ AST_PRESENCE_UNAVAILABLE
Definition: presencestate.h:28
@ AST_PRESENCE_INVALID
Definition: presencestate.h:39
@ AST_PRESENCE_DND
Definition: presencestate.h:33
@ AST_PRESENCE_AVAILABLE
Definition: presencestate.h:29
@ AST_PRESENCE_AWAY
Definition: presencestate.h:30
@ AST_PRESENCE_NOT_SET
Definition: presencestate.h:27
@ AST_PRESENCE_CHAT
Definition: presencestate.h:32
@ AST_PRESENCE_XA
Definition: presencestate.h:31

Function Documentation

◆ ast_presence_state()

enum ast_presence_state ast_presence_state ( const char *  presence_provider,
char **  subtype,
char **  message 
)

Asks a presence state provider for the current presence state.

Parameters
presence_providerThe presence provider to retrieve the state from.
subtypeThe output paramenter to store the subtype string in. Must be freed if returned
messageThe output paramenter to store the message string in. Must be freed if returned
Return values
presencestate value on success,
-1on failure.

Definition at line 221 of file presencestate.c.

222{
223 return ast_presence_state_helper(presence_provider, subtype, message, 1);
224}
static enum ast_presence_state ast_presence_state_helper(const char *presence_provider, char **subtype, char **message, int check_cache)

References ast_presence_state_helper().

◆ ast_presence_state2str()

const char * ast_presence_state2str ( enum ast_presence_state  state)

Convert presence state to text string for output.

Parameters
stateCurrent presence state

Definition at line 103 of file presencestate.c.

104{
105 int i;
106 for (i = 0; i < ARRAY_LEN(state2string); i++) {
107 if (state == state2string[i].state) {
108 return state2string[i].string;
109 }
110 }
111 return "";
112}
static const struct @380 state2string[]
Device state strings for printing.
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, and state2string.

Referenced by action_presencestate(), exten_state_publisher_state_cb(), handle_cli_presencestate_list(), handle_show_hint(), handle_show_hints(), manager_state_cb(), pidf_supplement_body(), presence_read(), and presence_state_to_ami().

◆ ast_presence_state_cache()

struct stasis_cache * ast_presence_state_cache ( void  )

Backend cache for ast_presence_state_topic_cached()

Return values
Cacheof ast_presence_state_message.
Since
12

Definition at line 370 of file presencestate.c.

371{
373}
struct stasis_cache * presence_state_cache
Definition: presencestate.c:90

References presence_state_cache.

Referenced by action_presencestatelist(), and presence_state_cached().

◆ ast_presence_state_changed()

int ast_presence_state_changed ( enum ast_presence_state  state,
const char *  subtype,
const char *  message,
const char *  fmt,
  ... 
)

Notify the world that a presence provider state changed.

Parameters
statethe new presence state
subtypethe new presence subtype
messagethe new presence message
fmtPresence entity whose state has changed

The new state of the entity will be sent off to any subscribers of the presence state. It will also be stored in the internal event cache.

Return values
0Success
-1Failure

Definition at line 350 of file presencestate.c.

354{
356 va_list ap;
357
358 va_start(ap, fmt);
359 vsnprintf(buf, sizeof(buf), fmt, ap);
360 va_end(ap);
361
363}
#define AST_MAX_EXTENSION
Definition: channel.h:134
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
int ast_presence_state_changed_literal(enum ast_presence_state state, const char *subtype, const char *message, const char *presence_provider)
Notify the world that a presence provider state changed.

References AST_MAX_EXTENSION, ast_presence_state_changed_literal(), and buf.

Referenced by load_module().

◆ ast_presence_state_changed_literal()

int ast_presence_state_changed_literal ( enum ast_presence_state  state,
const char *  subtype,
const char *  message,
const char *  presence_provider 
)

Notify the world that a presence provider state changed.

Parameters
statethe new presence state
subtypethe new presence subtype
messagethe new presence message
presence_providerPresence entity whose state has changed

The new state of the entity will be sent off to any subscribers of the presence state. It will also be stored in the internal event cache.

Return values
0Success
-1Failure

Definition at line 336 of file presencestate.c.

340{
342 do_presence_state_change(presence_provider);
343 } else {
344 presence_state_event(presence_provider, state, subtype, message);
345 }
346
347 return 0;
348}
static void do_presence_state_change(const char *provider)
static void presence_state_event(const char *provider, enum ast_presence_state state, const char *subtype, const char *message)

References AST_PRESENCE_NOT_SET, do_presence_state_change(), and presence_state_event().

Referenced by ast_presence_state_changed(), handle_cli_presencestate_change(), and presence_write().

◆ ast_presence_state_engine_init()

int ast_presence_state_engine_init ( void  )

Definition at line 495 of file presencestate.c.

496{
498
500 return -1;
501 }
502
503 presence_state_topic_all = stasis_topic_create("presence_state:all");
505 return -1;
506 }
507
510 return -1;
511 }
512
515 return -1;
516 }
519
520 AST_TEST_REGISTER(test_presence_chan);
521
522 return 0;
523}
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
static void presence_state_engine_cleanup(void)
struct stasis_caching_topic * presence_state_topic_cached
Definition: presencestate.c:91
struct stasis_topic * presence_state_topic_all
Definition: presencestate.c:89
static const char * presence_state_get_id(struct stasis_message *msg)
struct stasis_message_type * ast_presence_state_message_type(void)
Get presence state message type.
@ STASIS_SUBSCRIPTION_FILTER_SELECTIVE
Definition: stasis.h:297
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
Definition: stasis.c:617
struct stasis_caching_topic * stasis_caching_topic_create(struct stasis_topic *original_topic, struct stasis_cache *cache)
Create a topic which monitors and caches messages from another topic.
Definition: stasis_cache.c:948
int stasis_caching_set_filter(struct stasis_caching_topic *caching_topic, enum stasis_subscription_message_filter filter)
Set the message type filtering level on a cache.
Definition: stasis_cache.c:109
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition: stasis.h:1493
struct stasis_cache * stasis_cache_create(snapshot_get_id id_fn)
Create a cache.
Definition: stasis_cache.c:360
int stasis_caching_accept_message_type(struct stasis_caching_topic *caching_topic, struct stasis_message_type *type)
Indicate to a caching topic that we are interested in a message type.
Definition: stasis_cache.c:90
#define AST_TEST_REGISTER(cb)
Definition: test.h:127

References ast_presence_state_message_type(), ast_register_cleanup(), AST_TEST_REGISTER, presence_state_cache, presence_state_engine_cleanup(), presence_state_get_id(), presence_state_topic_all, presence_state_topic_cached, stasis_cache_create(), stasis_caching_accept_message_type(), stasis_caching_set_filter(), stasis_caching_topic_create(), STASIS_MESSAGE_TYPE_INIT, STASIS_SUBSCRIPTION_FILTER_SELECTIVE, and stasis_topic_create().

Referenced by asterisk_daemon().

◆ ast_presence_state_message_type()

struct stasis_message_type * ast_presence_state_message_type ( void  )

Get presence state message type.

Return values
Stasismessage type for presence state messages
Since
12

Referenced by action_presencestatelist(), ast_presence_state_engine_init(), load_pbx(), presence_state_cached(), presence_state_cb(), presence_state_engine_cleanup(), presence_state_event(), and presence_state_get_id().

◆ ast_presence_state_nocache()

enum ast_presence_state ast_presence_state_nocache ( const char *  presence_provider,
char **  subtype,
char **  message 
)

Asks a presence state provider for the current presence state, bypassing the event cache.

Some presence state providers may perform transformations on presence data when it is requested (such as a base64 decode). In such instances, use of the event cache is not suitable and should be bypassed.

Parameters
presence_providerThe presence provider to retrieve the state from.
subtypeThe output paramenter to store the subtype string in. Must be freed if returned
messageThe output paramenter to store the message string in. Must be freed if returned
Return values
presencestate value on success,
-1on failure.

Definition at line 226 of file presencestate.c.

227{
228 return ast_presence_state_helper(presence_provider, subtype, message, 0);
229}

References ast_presence_state_helper().

Referenced by presence_read().

◆ ast_presence_state_prov_add()

int ast_presence_state_prov_add ( const char *  label,
ast_presence_state_prov_cb_type  callback 
)

Add presence state provider.

Parameters
labelto use in hint, like label:object
callbackCallback
Return values
0success
-1failure

Definition at line 231 of file presencestate.c.

232{
234
235 if (!callback || !(provider = ast_calloc(1, sizeof(*provider)))) {
236 return -1;
237 }
238
239 provider->callback = callback;
240 ast_copy_string(provider->label, label, sizeof(provider->label));
241
245
246 return 0;
247}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
static struct prometheus_metrics_provider provider
Definition: bridges.c:201
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:718
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
A presence state provider.
Definition: presencestate.c:94
ast_presence_state_prov_cb_type callback
Definition: presencestate.c:96
A list of providers.

References ast_calloc, ast_copy_string(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, presence_state_provider::callback, presence_state_provider::label, and provider.

Referenced by load_module().

◆ ast_presence_state_prov_del()

int ast_presence_state_prov_del ( const char *  label)

Remove presence state provider.

Parameters
labelto use in hint, like label:object
Return values
-1on failure
0on success

Definition at line 248 of file presencestate.c.

249{
251 int res = -1;
252
255 if (!strcasecmp(provider->label, label)) {
258 res = 0;
259 break;
260 }
261 }
264
265 return res;
266}
#define ast_free(a)
Definition: astmm.h:180
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:570
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:545
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:617

References ast_free, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, presence_state_provider::label, and provider.

Referenced by unload_module().

◆ ast_presence_state_topic_all()

struct stasis_topic * ast_presence_state_topic_all ( void  )

Get presence state topic.

Return values
Stasistopic for presence state messages
Since
12

Definition at line 365 of file presencestate.c.

366{
368}

References presence_state_topic_all.

Referenced by load_module(), load_pbx(), presence_state_event(), and publish_hint_change().

◆ ast_presence_state_topic_cached()

struct stasis_topic * ast_presence_state_topic_cached ( void  )

Get caching presence state topic.

Return values
CachingStasis topic for presence state messages
Since
12

Definition at line 375 of file presencestate.c.

376{
378}
struct stasis_topic * stasis_caching_get_topic(struct stasis_caching_topic *caching_topic)
Returns the topic of cached events from a caching topics.
Definition: stasis_cache.c:85

References presence_state_topic_cached, and stasis_caching_get_topic().

◆ ast_presence_state_val()

enum ast_presence_state ast_presence_state_val ( const char *  val)

Convert presence state from text to integer value.

Parameters
valThe text representing the presence state. Valid values are anything that comes after AST_PRESENCE_ in one of the defined values.
Returns
The AST_PRESENCE_ integer value

Definition at line 114 of file presencestate.c.

115{
116 int i;
117 for (i = 0; i < ARRAY_LEN(state2string); i++) {
118 if (!strcasecmp(val, state2string[i].string)) {
119 return state2string[i].state;
120 }
121 }
123}
Definition: ast_expr2.c:325

References ARRAY_LEN, AST_PRESENCE_INVALID, and state2string.

Referenced by parse_data().