87 .
to_ami = presence_state_to_ami,
138 res = presence_state->
state;
165 while ((label =
strsep(&labels,
"&"))) {
167 char *next_subtype =
NULL;
168 char *next_message =
NULL;
179 if ((address = strchr(label,
'/'))) {
183 next_state = chan_tech->
presencestate(address, &next_subtype, &next_message);
185 }
else if ((address = strchr(label,
':'))) {
190 ast_debug(5,
"Checking provider %s with %s\n", provider->
label, label);
192 if (!strcasecmp(provider->
label, label)) {
193 next_state = provider->
callback(address, &next_subtype, &next_message);
207 if (state_order[next_state] > state_order[state]) {
213 *subtype = next_subtype;
214 *message = next_message;
235 if (!callback || !(provider =
ast_calloc(1,
sizeof(*provider)))) {
255 if (!strcasecmp(provider->
label, label)) {
285 presence_state->state =
state;
291 return presence_state;
307 if (!presence_state) {
321 char *subtype =
NULL;
339 const char *presence_provider)
353 const char *fmt, ...)
359 vsnprintf(buf,
sizeof(buf), fmt, ap);
388 return presence_state->provider;
391 #if defined(TEST_FRAMEWORK) 393 #define TEST_CATEGORY "/main/presence/" 400 if (!strcmp(label,
"Alice")) {
402 }
else if (!strcmp(label,
"Bob")) {
410 .
type =
"PresenceTestChannel",
411 .description =
"Presence test technology",
424 info->name =
"channel_presence";
426 info->summary =
"Channel presence state tests";
427 info->description =
"Creates test channel technology and then test the presence state callback";
435 goto presence_test_cleanup;
439 snprintf(provider,
sizeof(provider),
"%s/Alice", presence_test_tech.
type);
445 ast_log(
LOG_WARNING,
"Presence state of '%s' returned '%s' instead of the expected value '%s'\n",
447 goto presence_test_cleanup;
451 snprintf(provider,
sizeof(provider),
"%s/Alice&%s/Bob", presence_test_tech.
type, presence_test_tech.
type);
458 ast_log(
LOG_WARNING,
"Presence state of '%s' returned '%s' instead of the expected value '%s'\n",
460 goto presence_test_cleanup;
468 ast_log(
LOG_WARNING,
"Presence state of '%s' returned '%s' instead of the expected value '%s'\n",
470 goto presence_test_cleanup;
475 presence_test_cleanup:
487 presence_state_topic_all =
NULL;
489 presence_state_cache =
NULL;
504 if (!presence_state_topic_all) {
509 if (!presence_state_cache) {
514 if (!presence_state_topic_cached) {
538 presence_state->provider,
int(*const presencestate)(const char *presence_provider, char **subtype, char **message)
Struct containing info for an AMI event to send out.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
static void do_presence_state_change(const char *provider)
struct stasis_topic * presence_state_topic_all
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.
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
static enum ast_presence_state ast_presence_state_helper(const char *presence_provider, char **subtype, char **message, int check_cache)
static struct ast_channel_tech presence_test_tech
static const char * presence_state_get_id(struct stasis_message *msg)
int ast_presence_state_prov_del(const char *label)
Remove presence state provider.
const struct ast_channel_tech * ast_get_channel_tech(const char *name)
Get a channel technology structure by name.
ast_presence_state_prov_cb_type callback
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
STASIS_MESSAGE_TYPE_DEFN(ast_presence_state_message_type,.to_ami=presence_state_to_ami,)
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
A presence state provider.
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.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
static int presence_test_presencestate(const char *label, char **subtype, char **message)
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
#define AST_TEST_REGISTER(cb)
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
static void presence_state_dtor(void *obj)
Stasis message payload representing a presence state update.
int ast_channel_register(const struct ast_channel_tech *tech)
Register a channel technology (a new channel driver) Called by a channel module to register the kind ...
#define ast_strdup(str)
A wrapper for strdup()
static struct ast_presence_state_message * presence_state_alloc(const char *provider, enum ast_presence_state state, const char *subtype, const char *message)
struct stasis_topic * ast_presence_state_topic_all(void)
Get presence state topic.
struct stasis_caching_topic * stasis_caching_unsubscribe_and_join(struct stasis_caching_topic *caching_topic)
Unsubscribes a caching topic from its upstream topic, blocking until all messages have been forwarded...
struct ast_manager_event_blob * ast_manager_event_blob_create(int event_flags, const char *manager_event, const char *extra_fields_fmt,...)
Construct a ast_manager_event_blob.
#define ast_strlen_zero(foo)
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
#define AST_RWLIST_INSERT_HEAD
#define ast_debug(level,...)
Log a DEBUG message.
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.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define AST_MAX_EXTENSION
#define AST_RWLIST_TRAVERSE
#define ao2_ref(o, delta)
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.
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...
#define AST_RWLIST_REMOVE_CURRENT
#define ast_strdupa(s)
duplicate a string in memory from the stack
A set of macros to manage forward-linked lists.
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Core PBX routines and definitions.
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Presence state management.
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.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
#define AST_TEST_UNREGISTER(cb)
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
struct stasis_cache * presence_state_cache
int ast_presence_state_engine_init(void)
#define ao2_alloc(data_size, destructor_fn)
static struct ast_manager_event_blob * presence_state_to_ami(struct stasis_message *msg)
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
#define ast_calloc(num, len)
A wrapper for calloc()
char * ast_escape_c_alloc(const char *s)
Escape standard 'C' sequences in the given string.
static void to_ami(struct ast_sip_subscription *sub, struct ast_str **buf)
Prototypes for public functions only of internal interest,.
const char * ast_presence_state2str(enum ast_presence_state state)
Convert presence state to text string for output.
static void presence_state_event(const char *provider, enum ast_presence_state state, const char *subtype, const char *message)
static const struct @413 state2string[]
Device state strings for printing.
char * strsep(char **str, const char *delims)
struct stasis_cache * stasis_cache_create(snapshot_get_id id_fn)
Create a cache.
struct stasis_cache * ast_presence_state_cache(void)
Backend cache for ast_presence_state_topic_cached()
static int presence_test_alice_state
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
static enum ast_presence_state presence_state_cached(const char *presence_provider, char **subtype, char **message)
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
static int presence_test_bob_state
struct stasis_message_type * ast_presence_state_message_type(void)
Get presence state message type.
enum ast_presence_state state
struct stasis_message * stasis_cache_get(struct stasis_cache *cache, struct stasis_message_type *type, const char *id)
Retrieve an item from the cache for the ast_eid_default entity.
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.
struct stasis_topic * ast_presence_state_topic_cached(void)
Get caching presence state topic.
int ast_presence_state_prov_add(const char *label, ast_presence_state_prov_cb_type callback)
Add presence state provider.
enum ast_presence_state ast_presence_state_val(const char *val)
Convert presence state from text to integer value.
struct stasis_topic * stasis_caching_get_topic(struct stasis_caching_topic *caching_topic)
Returns the topic of cached events from a caching topics.
static struct prometheus_metrics_provider provider
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
struct stasis_caching_topic * presence_state_topic_cached
#define AST_RWLIST_TRAVERSE_SAFE_END
enum ast_presence_state(* ast_presence_state_prov_cb_type)(const char *data, char **subtype, char **message)
Presence state provider call back.
enum ast_presence_state state
AST_TEST_DEFINE(test_presence_chan)
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
static void presence_state_engine_cleanup(void)