Asterisk - The Open Source Telephony Project  18.5.0
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 43 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 };

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.

References ast_presence_state_helper().

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)

◆ 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.

References ARRAY_LEN, and state2string.

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

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 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static const struct @413 state2string[]
Device state strings for printing.

◆ 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.

References presence_state_cache.

Referenced by action_presencestatelist(), and presence_state_cached().

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

◆ 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.

References AST_MAX_EXTENSION, ast_presence_state_changed_literal(), and buf.

Referenced by load_module().

354 {
355  char buf[AST_MAX_EXTENSION];
356  va_list ap;
357 
358  va_start(ap, fmt);
359  vsnprintf(buf, sizeof(buf), fmt, ap);
360  va_end(ap);
361 
362  return ast_presence_state_changed_literal(state, subtype, message, buf);
363 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_MAX_EXTENSION
Definition: channel.h:135
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.

◆ 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.

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

340 {
341  if (state == AST_PRESENCE_NOT_SET) {
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)

◆ ast_presence_state_engine_init()

int ast_presence_state_engine_init ( void  )

Definition at line 495 of file presencestate.c.

References ast_presence_state_message_type(), ast_register_cleanup(), AST_TEST_REGISTER, presence_state_engine_cleanup(), presence_state_get_id(), 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().

496 {
498 
500  return -1;
501  }
502 
503  presence_state_topic_all = stasis_topic_create("presence_state:all");
505  return -1;
506  }
507 
509  if (!presence_state_cache) {
510  return -1;
511  }
512 
515  return -1;
516  }
519 
520  AST_TEST_REGISTER(test_presence_chan);
521 
522  return 0;
523 }
struct stasis_topic * presence_state_topic_all
Definition: presencestate.c:89
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
static const char * presence_state_get_id(struct stasis_message *msg)
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition: stasis.h:1501
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
#define AST_TEST_REGISTER(cb)
Definition: test.h:127
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
Definition: stasis.c:618
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
struct stasis_cache * presence_state_cache
Definition: presencestate.c:90
struct stasis_cache * stasis_cache_create(snapshot_get_id id_fn)
Create a cache.
Definition: stasis_cache.c:360
struct stasis_message_type * ast_presence_state_message_type(void)
Get presence state message type.
struct stasis_caching_topic * presence_state_topic_cached
Definition: presencestate.c:91
static void presence_state_engine_cleanup(void)

◆ 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(), presence_state_get_id(), and test_cb().

◆ 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.

References ast_presence_state_helper().

Referenced by AST_TEST_DEFINE(), and presence_read().

227 {
228  return ast_presence_state_helper(presence_provider, subtype, message, 0);
229 }
static enum ast_presence_state ast_presence_state_helper(const char *presence_provider, char **subtype, char **message, int check_cache)

◆ 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.

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

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 }
ast_presence_state_prov_cb_type callback
Definition: presencestate.c:96
A list of providers.
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
A presence state provider.
Definition: presencestate.c:94
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:717
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
static struct prometheus_metrics_provider provider
Definition: bridges.c:178

◆ 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.

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

249 {
251  int res = -1;
252 
255  if (!strcasecmp(provider->label, label)) {
257  ast_free(provider);
258  res = 0;
259  break;
260  }
261  }
264 
265  return res;
266 }
A list of providers.
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
A presence state provider.
Definition: presencestate.c:94
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:569
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
#define ast_free(a)
Definition: astmm.h:182
static struct prometheus_metrics_provider provider
Definition: bridges.c:178
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616

◆ 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.

References presence_state_topic_all.

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

366 {
368 }
struct stasis_topic * presence_state_topic_all
Definition: presencestate.c:89

◆ 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.

References stasis_caching_get_topic().

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
struct stasis_caching_topic * presence_state_topic_cached
Definition: presencestate.c:91

◆ 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.

References ARRAY_LEN, AST_PRESENCE_INVALID, and state2string.

Referenced by parse_data().

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  }
122  return AST_PRESENCE_INVALID;
123 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
Definition: ast_expr2.c:325
static const struct @413 state2string[]
Device state strings for printing.