Asterisk - The Open Source Telephony Project
18.5.0
|
Presence state management. More...
#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/linkedlists.h"
#include "asterisk/presencestate.h"
#include "asterisk/pbx.h"
#include "asterisk/app.h"
#include "asterisk/test.h"
Go to the source code of this file.
Data Structures | |
struct | presence_state_provider |
A presence state provider. More... | |
struct | presence_state_providers |
A list of providers. More... | |
Macros | |
#define | TEST_CATEGORY "/main/presence/" |
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_cache * | ast_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) |
static enum ast_presence_state | ast_presence_state_helper (const char *presence_provider, char **subtype, char **message, int check_cache) |
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_topic * | ast_presence_state_topic_all (void) |
Get presence state topic. More... | |
struct stasis_topic * | ast_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... | |
AST_TEST_DEFINE (test_presence_chan) | |
static void | do_presence_state_change (const char *provider) |
static struct ast_presence_state_message * | presence_state_alloc (const char *provider, enum ast_presence_state state, const char *subtype, const char *message) |
static enum ast_presence_state | presence_state_cached (const char *presence_provider, char **subtype, char **message) |
static void | presence_state_dtor (void *obj) |
static void | presence_state_engine_cleanup (void) |
static void | presence_state_event (const char *provider, enum ast_presence_state state, const char *subtype, const char *message) |
static const char * | presence_state_get_id (struct stasis_message *msg) |
static struct ast_manager_event_blob * | presence_state_to_ami (struct stasis_message *msg) |
static int | presence_test_presencestate (const char *label, char **subtype, char **message) |
STASIS_MESSAGE_TYPE_DEFN (ast_presence_state_message_type,.to_ami=presence_state_to_ami,) | |
Variables | |
struct stasis_cache * | presence_state_cache |
static struct presence_state_providers | presence_state_providers = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , } |
struct stasis_topic * | presence_state_topic_all |
struct stasis_caching_topic * | presence_state_topic_cached |
static int | presence_test_alice_state = AST_PRESENCE_UNAVAILABLE |
static int | presence_test_bob_state = AST_PRESENCE_UNAVAILABLE |
static struct ast_channel_tech | presence_test_tech |
struct { | |
enum ast_presence_state state | |
const char * string | |
} | state2string [] |
Device state strings for printing. More... | |
Presence state management.
Definition in file presencestate.c.
#define TEST_CATEGORY "/main/presence/" |
Definition at line 393 of file presencestate.c.
Referenced by AST_TEST_DEFINE().
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.
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 |
presence | state value on success, |
-1 | on failure. |
Definition at line 221 of file presencestate.c.
References ast_presence_state_helper().
const char* ast_presence_state2str | ( | enum ast_presence_state | state | ) |
Convert presence state to text string for output.
state | Current 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().
struct stasis_cache* ast_presence_state_cache | ( | void | ) |
Backend cache for ast_presence_state_topic_cached()
Cache | of ast_presence_state_message. |
Definition at line 370 of file presencestate.c.
References presence_state_cache.
Referenced by action_presencestatelist(), and presence_state_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.
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.
0 | Success |
-1 | Failure |
Definition at line 350 of file presencestate.c.
References AST_MAX_EXTENSION, ast_presence_state_changed_literal(), and buf.
Referenced by load_module().
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.
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.
0 | Success |
-1 | Failure |
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().
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().
|
static |
Definition at line 146 of file presencestate.c.
References ast_debug, ast_free, ast_get_channel_tech(), ast_log, AST_PRESENCE_AVAILABLE, AST_PRESENCE_AWAY, AST_PRESENCE_CHAT, AST_PRESENCE_DND, AST_PRESENCE_INVALID, AST_PRESENCE_NOT_SET, AST_PRESENCE_UNAVAILABLE, AST_PRESENCE_XA, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdupa, presence_state_provider::callback, presence_state_provider::label, LOG_WARNING, NULL, presence_state_cached(), ast_channel_tech::presencestate, provider, state, and strsep().
Referenced by ast_presence_state(), ast_presence_state_nocache(), and do_presence_state_change().
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.
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 |
presence | state value on success, |
-1 | on failure. |
Definition at line 226 of file presencestate.c.
References ast_presence_state_helper().
Referenced by AST_TEST_DEFINE(), and presence_read().
int ast_presence_state_prov_add | ( | const char * | label, |
ast_presence_state_prov_cb_type | callback | ||
) |
Add presence state provider.
label | to use in hint, like label:object |
callback | Callback |
0 | success |
-1 | failure |
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().
int ast_presence_state_prov_del | ( | const char * | label | ) |
Remove presence state provider.
label | to use in hint, like label:object |
-1 | on failure |
0 | on 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().
struct stasis_topic* ast_presence_state_topic_all | ( | void | ) |
Get presence state topic.
Stasis | topic for presence state messages |
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().
struct stasis_topic* ast_presence_state_topic_cached | ( | void | ) |
Get caching presence state topic.
Caching | Stasis topic for presence state messages |
Definition at line 375 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.
val | The text representing the presence state. Valid values are anything that comes after AST_PRESENCE_ in one of the defined values. |
Definition at line 114 of file presencestate.c.
References ARRAY_LEN, AST_PRESENCE_INVALID, and state2string.
Referenced by parse_data().
AST_TEST_DEFINE | ( | test_presence_chan | ) |
Definition at line 415 of file presencestate.c.
References ast_channel_register(), ast_channel_unregister(), ast_free, ast_log, AST_PRESENCE_AVAILABLE, AST_PRESENCE_DND, ast_presence_state2str(), ast_presence_state_nocache(), AST_PRESENCE_UNAVAILABLE, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, sip_to_pjsip::info(), LOG_WARNING, NULL, presence_test_alice_state, presence_test_bob_state, provider, state, TEST_CATEGORY, TEST_EXECUTE, TEST_INIT, and ast_channel_tech::type.
|
static |
Definition at line 319 of file presencestate.c.
References ast_free, AST_PRESENCE_INVALID, ast_presence_state_helper(), NULL, presence_state_event(), and state.
Referenced by ast_presence_state_changed_literal().
|
static |
Definition at line 274 of file presencestate.c.
References ao2_alloc, ao2_cleanup, ao2_ref, ast_string_field_init, ast_string_field_set, NULL, presence_state_dtor(), RAII_VAR, S_OR, and state.
Referenced by presence_state_event().
|
static |
Definition at line 125 of file presencestate.c.
References ao2_cleanup, AST_PRESENCE_INVALID, ast_presence_state_cache(), ast_presence_state_message_type(), ast_strdup, ast_strlen_zero, NULL, RAII_VAR, stasis_cache_get(), stasis_message_data(), and ast_presence_state_message::state.
Referenced by ast_presence_state_helper().
|
static |
Definition at line 268 of file presencestate.c.
References ast_string_field_free_memory.
Referenced by presence_state_alloc().
|
static |
Definition at line 484 of file presencestate.c.
References ao2_cleanup, ast_presence_state_message_type(), AST_TEST_UNREGISTER, NULL, stasis_caching_unsubscribe_and_join(), and STASIS_MESSAGE_TYPE_CLEANUP.
Referenced by ast_presence_state_engine_init().
|
static |
Definition at line 294 of file presencestate.c.
References ao2_cleanup, ast_presence_state_message_type(), ast_presence_state_topic_all(), NULL, presence_state_alloc(), RAII_VAR, stasis_message_create(), and stasis_publish().
Referenced by ast_presence_state_changed_literal(), and do_presence_state_change().
|
static |
Definition at line 380 of file presencestate.c.
References ast_presence_state_message_type(), NULL, stasis_message_data(), and stasis_message_type().
Referenced by ast_presence_state_engine_init().
|
static |
Definition at line 525 of file presencestate.c.
References ast_escape_c_alloc(), ast_free, ast_manager_event_blob_create(), ast_presence_state2str(), EVENT_FLAG_CALL, stasis_message_data(), and ast_presence_state_message::state.
|
static |
Definition at line 398 of file presencestate.c.
References AST_PRESENCE_UNAVAILABLE, presence_test_alice_state, and presence_test_bob_state.
STASIS_MESSAGE_TYPE_DEFN | ( | ast_presence_state_message_type | , |
. | to_ami = presence_state_to_ami |
||
) |
struct stasis_cache* presence_state_cache |
Definition at line 90 of file presencestate.c.
Referenced by ast_presence_state_cache().
|
static |
struct stasis_topic* presence_state_topic_all |
Definition at line 89 of file presencestate.c.
Referenced by ast_presence_state_topic_all().
struct stasis_caching_topic* presence_state_topic_cached |
Definition at line 91 of file presencestate.c.
|
static |
Definition at line 395 of file presencestate.c.
Referenced by AST_TEST_DEFINE(), and presence_test_presencestate().
|
static |
Definition at line 396 of file presencestate.c.
Referenced by AST_TEST_DEFINE(), and presence_test_presencestate().
|
static |
Definition at line 409 of file presencestate.c.
enum ast_presence_state state |
Definition at line 72 of file presencestate.c.
Referenced by ast_presence_state_helper(), AST_TEST_DEFINE(), do_presence_state_change(), and presence_state_alloc().
const { ... } state2string[] |
Device state strings for printing.
Referenced by ast_presence_state2str(), and ast_presence_state_val().
const char* string |
Definition at line 71 of file presencestate.c.
Referenced by ast_escape_quoted(), ast_escape_semicolons(), AST_TEST_DEFINE(), ast_uri_encode(), ast_xml_escape(), nword(), and private_enum_init().