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

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.
const char * ast_presence_state2str (enum ast_presence_state state)
 Convert presence state to text string for output.
struct stasis_cacheast_presence_state_cache (void)
 Backend cache for ast_presence_state_topic_cached().
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.
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.
int ast_presence_state_engine_init (void)
struct stasis_message_typeast_presence_state_message_type (void)
 Get presence state message type.
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.
int ast_presence_state_prov_add (const char *label, ast_presence_state_prov_cb_type callback)
 Add presence state provider.
int ast_presence_state_prov_del (const char *label)
 Remove presence state provider.
struct stasis_topicast_presence_state_topic_all (void)
 Get presence state topic.
struct stasis_topicast_presence_state_topic_cached (void)
 Get caching presence state topic.
enum ast_presence_state ast_presence_state_val (const char *val)
 Convert presence state from text to integer value.

Variables

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


Detailed Description

Presence state management.

Definition in file presencestate.h.


Enumeration Type Documentation

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.

00026                         {
00027    AST_PRESENCE_NOT_SET = 0,
00028    AST_PRESENCE_UNAVAILABLE,
00029    AST_PRESENCE_AVAILABLE,
00030    AST_PRESENCE_AWAY,
00031    AST_PRESENCE_XA,
00032    AST_PRESENCE_CHAT,
00033    AST_PRESENCE_DND,
00034    /* This is not something that a user can
00035     * set his presence to. Rather, this is returned
00036     * to indicate that presence is in some invalid
00037     * state
00038     */
00039    AST_PRESENCE_INVALID,
00040 };


Function Documentation

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_provider The presence provider to retrieve the state from.
subtype The output paramenter to store the subtype string in. Must be freed if returned
message The output paramenter to store the message string in. Must be freed if returned
Return values:
presence state value on success,
-1 on failure.

Definition at line 220 of file presencestate.c.

References ast_presence_state_helper().

00221 {
00222    return ast_presence_state_helper(presence_provider, subtype, message, 1);
00223 }

const char* ast_presence_state2str ( enum ast_presence_state  state  ) 

Convert presence state to text string for output.

Parameters:
state Current presence state

Definition at line 105 of file presencestate.c.

References ARRAY_LEN, and state2string.

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

00106 {
00107    int i;
00108    for (i = 0; i < ARRAY_LEN(state2string); i++) {
00109       if (state == state2string[i].state) {
00110          return state2string[i].string;
00111       }
00112    }
00113    return "";
00114 }

struct stasis_cache* ast_presence_state_cache ( void   )  [read]

Backend cache for ast_presence_state_topic_cached().

Return values:
Cache of ast_presence_state_message.
Since:
12

Definition at line 369 of file presencestate.c.

Referenced by action_presencestatelist(), and presence_state_cached().

00370 {
00371    return presence_state_cache;
00372 }

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:
state the new presence state
subtype the new presence subtype
message the new presence message
fmt Presence 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:
0 Success
-1 Failure

Definition at line 349 of file presencestate.c.

References AST_MAX_EXTENSION, ast_presence_state_changed_literal(), and buf.

Referenced by load_module().

00353 {
00354    char buf[AST_MAX_EXTENSION];
00355    va_list ap;
00356 
00357    va_start(ap, fmt);
00358    vsnprintf(buf, sizeof(buf), fmt, ap);
00359    va_end(ap);
00360 
00361    return ast_presence_state_changed_literal(state, subtype, message, buf);
00362 }

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:
state the new presence state
subtype the new presence subtype
message the new presence message
presence_provider Presence 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:
0 Success
-1 Failure

Definition at line 335 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().

00339 {
00340    if (state == AST_PRESENCE_NOT_SET) {
00341       do_presence_state_change(presence_provider);
00342    } else {
00343       presence_state_event(presence_provider, state, subtype, message);
00344    }
00345 
00346    return 0;
00347 }

int ast_presence_state_engine_init ( void   ) 

struct stasis_message_type* ast_presence_state_message_type ( void   )  [read]

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_provider The presence provider to retrieve the state from.
subtype The output paramenter to store the subtype string in. Must be freed if returned
message The output paramenter to store the message string in. Must be freed if returned
Return values:
presence state value on success,
-1 on failure.

Definition at line 225 of file presencestate.c.

References ast_presence_state_helper().

Referenced by presence_read().

00226 {
00227    return ast_presence_state_helper(presence_provider, subtype, message, 0);
00228 }

int ast_presence_state_prov_add ( const char *  label,
ast_presence_state_prov_cb_type  callback 
)

Add presence state provider.

Parameters:
label to use in hint, like label:object
callback Callback
Return values:
0 success
-1 failure

Definition at line 230 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 presence_state_provider::list.

Referenced by load_module().

00231 {
00232    struct presence_state_provider *provider;
00233 
00234    if (!callback || !(provider = ast_calloc(1, sizeof(*provider)))) {
00235       return -1;
00236    }
00237 
00238    provider->callback = callback;
00239    ast_copy_string(provider->label, label, sizeof(provider->label));
00240 
00241    AST_RWLIST_WRLOCK(&presence_state_providers);
00242    AST_RWLIST_INSERT_HEAD(&presence_state_providers, provider, list);
00243    AST_RWLIST_UNLOCK(&presence_state_providers);
00244 
00245    return 0;
00246 }

int ast_presence_state_prov_del ( const char *  label  ) 

Remove presence state provider.

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

Definition at line 247 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 presence_state_provider::list.

Referenced by unload_module().

00248 {
00249    struct presence_state_provider *provider;
00250    int res = -1;
00251 
00252    AST_RWLIST_WRLOCK(&presence_state_providers);
00253    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&presence_state_providers, provider, list) {
00254       if (!strcasecmp(provider->label, label)) {
00255          AST_RWLIST_REMOVE_CURRENT(list);
00256          ast_free(provider);
00257          res = 0;
00258          break;
00259       }
00260    }
00261    AST_RWLIST_TRAVERSE_SAFE_END;
00262    AST_RWLIST_UNLOCK(&presence_state_providers);
00263 
00264    return res;
00265 }

struct stasis_topic* ast_presence_state_topic_all ( void   )  [read]

Get presence state topic.

Return values:
Stasis topic for presence state messages
Since:
12

Definition at line 364 of file presencestate.c.

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

00365 {
00366    return presence_state_topic_all;
00367 }

struct stasis_topic* ast_presence_state_topic_cached ( void   )  [read]

Get caching presence state topic.

Return values:
Caching Stasis topic for presence state messages
Since:
12

Definition at line 374 of file presencestate.c.

References stasis_caching_get_topic().

enum ast_presence_state ast_presence_state_val ( const char *  val  ) 

Convert presence state from text to integer value.

Parameters:
val The 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 116 of file presencestate.c.

References ARRAY_LEN, AST_PRESENCE_INVALID, and state2string.

Referenced by parse_data().

00117 {
00118    int i;
00119    for (i = 0; i < ARRAY_LEN(state2string); i++) {
00120       if (!strcasecmp(val, state2string[i].string)) {
00121          return state2string[i].state;
00122       }
00123    }
00124    return AST_PRESENCE_INVALID;
00125 }


Variable Documentation

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

Presence state provider call back.


Generated on Thu Apr 16 06:32:27 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6