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,
'/'))) {
185 }
else if ((
address = strchr(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;
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/"
398static int presence_test_presencestate(
const char *label,
char **subtype,
char **
message)
400 if (!strcmp(label,
"Alice")) {
401 return presence_test_alice_state;
402 }
else if (!strcmp(label,
"Bob")) {
403 return presence_test_bob_state;
410 .
type =
"PresenceTestChannel",
411 .description =
"Presence test technology",
412 .presencestate = presence_test_presencestate,
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;
444 if (
state != presence_test_alice_state) {
445 ast_log(
LOG_WARNING,
"Presence state of '%s' returned '%s' instead of the expected value '%s'\n",
447 goto presence_test_cleanup;
457 if (
state != presence_test_alice_state) {
458 ast_log(
LOG_WARNING,
"Presence state of '%s' returned '%s' instead of the expected value '%s'\n",
460 goto presence_test_cleanup;
467 if (
state != presence_test_bob_state) {
468 ast_log(
LOG_WARNING,
"Presence state of '%s' returned '%s' instead of the expected value '%s'\n",
470 goto presence_test_cleanup;
475presence_test_cleanup:
538 presence_state->provider,
Prototypes for public functions only of internal interest,.
Asterisk main include file. File version handling, generic pbx functions.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
#define ast_strdup(str)
A wrapper for strdup()
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ast_calloc(num, len)
A wrapper for calloc()
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_alloc(data_size, destructor_fn)
static struct prometheus_metrics_provider provider
void ast_channel_unregister(const struct ast_channel_tech *tech)
Unregister a channel technology.
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 ...
const struct ast_channel_tech * ast_get_channel_tech(const char *name)
Get a channel technology structure by name.
#define AST_MAX_EXTENSION
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
char * strsep(char **str, const char *delims)
#define ast_debug(level,...)
Log a DEBUG message.
A set of macros to manage forward-linked lists.
#define AST_RWLIST_REMOVE_CURRENT
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized.
#define AST_RWLIST_TRAVERSE_SAFE_END
#define AST_RWLIST_TRAVERSE
#define AST_RWLIST_INSERT_HEAD
Asterisk locking-related definitions:
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.
Core PBX routines and definitions.
static void presence_state_engine_cleanup(void)
struct stasis_cache * ast_presence_state_cache(void)
Backend cache for ast_presence_state_topic_cached()
struct stasis_caching_topic * presence_state_topic_cached
static void presence_state_dtor(void *obj)
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.
static const struct @380 state2string[]
Device state strings for printing.
int ast_presence_state_prov_add(const char *label, ast_presence_state_prov_cb_type callback)
Add presence state provider.
static void do_presence_state_change(const char *provider)
struct stasis_topic * presence_state_topic_all
struct stasis_topic * ast_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.
static const char * presence_state_get_id(struct stasis_message *msg)
static enum ast_presence_state ast_presence_state_helper(const char *presence_provider, char **subtype, char **message, int check_cache)
enum ast_presence_state state
static struct ast_manager_event_blob * presence_state_to_ami(struct stasis_message *msg)
struct stasis_topic * ast_presence_state_topic_all(void)
Get presence state topic.
int ast_presence_state_engine_init(void)
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.
struct stasis_cache * presence_state_cache
static void presence_state_event(const char *provider, enum ast_presence_state state, const char *subtype, const char *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.
static enum ast_presence_state presence_state_cached(const char *presence_provider, char **subtype, char **message)
static struct ast_presence_state_message * presence_state_alloc(const char *provider, enum ast_presence_state state, const char *subtype, const char *message)
int ast_presence_state_prov_del(const char *label)
Remove presence state provider.
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.
const char * ast_presence_state2str(enum ast_presence_state state)
Convert presence state to text string for output.
STASIS_MESSAGE_TYPE_DEFN(ast_presence_state_message_type,.to_ami=presence_state_to_ami,)
Presence state management.
enum ast_presence_state(* ast_presence_state_prov_cb_type)(const char *data, char **subtype, char **message)
Presence state provider call back.
@ AST_PRESENCE_UNAVAILABLE
struct stasis_message_type * ast_presence_state_message_type(void)
Get presence state message type.
static void to_ami(struct ast_sip_subscription *sub, struct ast_str **buf)
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
struct stasis_topic * stasis_caching_get_topic(struct stasis_caching_topic *caching_topic)
Returns the topic of cached events from a caching topics.
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
@ STASIS_SUBSCRIPTION_FILTER_SELECTIVE
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
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.
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.
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
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 stasis_cache * stasis_cache_create(snapshot_get_id id_fn)
Create a cache.
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
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 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_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
char * ast_escape_c_alloc(const char *s)
Escape standard 'C' sequences in the given string.
Structure to describe a channel "technology", ie a channel driver See for examples:
int(*const presencestate)(const char *presence_provider, char **subtype, char **message)
Struct containing info for an AMI event to send out.
Stasis message payload representing a presence state update.
enum ast_presence_state state
A presence state provider.
ast_presence_state_prov_cb_type callback
#define AST_TEST_REGISTER(cb)
#define AST_TEST_UNREGISTER(cb)
#define AST_TEST_DEFINE(hdr)
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.