Asterisk - The Open Source Telephony Project GIT-master-8f1982c
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Data Structures | Functions | Variables
presencestate.c File Reference

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"
Include dependency graph for presencestate.c:

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

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)
 
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_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...
 
static void do_presence_state_change (const char *provider)
 
static struct ast_presence_state_messagepresence_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_blobpresence_state_to_ami (struct stasis_message *msg)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_presence_state_message_type,.to_ami=presence_state_to_ami,)
 

Variables

struct stasis_cachepresence_state_cache
 
static struct presence_state_providers presence_state_providers = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
struct stasis_topicpresence_state_topic_all
 
struct stasis_caching_topicpresence_state_topic_cached
 
struct {
   enum ast_presence_state   state
 
   const char *   string
 
state2string []
 Device state strings for printing. More...
 

Detailed Description

Presence state management.

Definition in file presencestate.c.

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 224 of file presencestate.c.

225{
226 return ast_presence_state_helper(presence_provider, subtype, message, 1);
227}
static enum ast_presence_state ast_presence_state_helper(const char *presence_provider, char **subtype, char **message, int check_cache)

References ast_presence_state_helper().

◆ 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 106 of file presencestate.c.

107{
108 int i;
109 for (i = 0; i < ARRAY_LEN(state2string); i++) {
110 if (state == state2string[i].state) {
111 return state2string[i].string;
112 }
113 }
114 return "";
115}
static const struct @383 state2string[]
Device state strings for printing.
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, and state2string.

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

◆ 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 373 of file presencestate.c.

374{
376}
struct stasis_cache * presence_state_cache
Definition: presencestate.c:93

References presence_state_cache.

Referenced by action_presencestatelist(), and presence_state_cached().

◆ 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 353 of file presencestate.c.

357{
359 va_list ap;
360
361 va_start(ap, fmt);
362 vsnprintf(buf, sizeof(buf), fmt, ap);
363 va_end(ap);
364
366}
#define AST_MAX_EXTENSION
Definition: channel.h:134
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
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.

References AST_MAX_EXTENSION, ast_presence_state_changed_literal(), and buf.

Referenced by load_module().

◆ 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 339 of file presencestate.c.

343{
345 do_presence_state_change(presence_provider);
346 } else {
347 presence_state_event(presence_provider, state, subtype, message);
348 }
349
350 return 0;
351}
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_NOT_SET
Definition: presencestate.h:27

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

◆ ast_presence_state_engine_init()

int ast_presence_state_engine_init ( void  )

Definition at line 498 of file presencestate.c.

499{
501
503 return -1;
504 }
505
506 presence_state_topic_all = stasis_topic_create("presence_state:all");
508 return -1;
509 }
510
513 return -1;
514 }
515
518 return -1;
519 }
522
523 AST_TEST_REGISTER(test_presence_chan);
524
525 return 0;
526}
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
static void presence_state_engine_cleanup(void)
struct stasis_caching_topic * presence_state_topic_cached
Definition: presencestate.c:94
struct stasis_topic * presence_state_topic_all
Definition: presencestate.c:92
static const char * presence_state_get_id(struct stasis_message *msg)
struct stasis_message_type * ast_presence_state_message_type(void)
Get presence state message type.
@ STASIS_SUBSCRIPTION_FILTER_SELECTIVE
Definition: stasis.h:297
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
Definition: stasis.c:644
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
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
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition: stasis.h:1493
struct stasis_cache * stasis_cache_create(snapshot_get_id id_fn)
Create a cache.
Definition: stasis_cache.c:360
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
#define AST_TEST_REGISTER(cb)
Definition: test.h:127

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

◆ ast_presence_state_helper()

static enum ast_presence_state ast_presence_state_helper ( const char *  presence_provider,
char **  subtype,
char **  message,
int  check_cache 
)
static

Definition at line 149 of file presencestate.c.

150{
151 char *labels = ast_strdupa(presence_provider);
152 char *label;
154 enum ast_presence_state state_order[] = {
159 [AST_PRESENCE_CHAT] = 4,
160 [AST_PRESENCE_AWAY] = 5,
161 [AST_PRESENCE_XA] = 6,
162 [AST_PRESENCE_DND] = 7
163 };
164
165 *subtype = NULL;
166 *message = NULL;
167
168 while ((label = strsep(&labels, "&"))) {
170 char *next_subtype = NULL;
171 char *next_message = NULL;
172
173 if (check_cache) {
174 next_state = presence_state_cached(label, &next_subtype, &next_message);
175 }
176
177 if (next_state == AST_PRESENCE_INVALID) {
179 const struct ast_channel_tech *chan_tech;
180 char *address;
181
182 if ((address = strchr(label, '/'))) {
183 *address++ = '\0';
184
185 if ((chan_tech = ast_get_channel_tech(label)) && chan_tech->presencestate) {
186 next_state = chan_tech->presencestate(address, &next_subtype, &next_message);
187 }
188 } else if ((address = strchr(label, ':'))) {
189 *address++ = '\0';
190
193 ast_debug(5, "Checking provider %s with %s\n", provider->label, label);
194
195 if (!strcasecmp(provider->label, label)) {
196 next_state = provider->callback(address, &next_subtype, &next_message);
197 break;
198 }
199 }
201
202 if (!provider) {
203 ast_log(LOG_WARNING, "No provider found for label: %s\n", label);
204 }
205 } else {
206 ast_log(LOG_WARNING, "No label found for presence state provider: %s\n", label);
207 }
208 }
209
210 if (state_order[next_state] > state_order[state]) {
211 state = next_state;
212
213 ast_free(*subtype);
215
216 *subtype = next_subtype;
217 *message = next_message;
218 }
219 }
220
221 return state;
222}
char * strsep(char **str, const char *delims)
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
static struct prometheus_metrics_provider provider
Definition: bridges.c:201
const struct ast_channel_tech * ast_get_channel_tech(const char *name)
Get a channel technology structure by name.
Definition: channel.c:591
char * address
Definition: f2c.h:59
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_WARNING
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:494
enum ast_presence_state state
Definition: presencestate.c:75
static enum ast_presence_state presence_state_cached(const char *presence_provider, char **subtype, char **message)
ast_presence_state
Definition: presencestate.h:26
@ AST_PRESENCE_UNAVAILABLE
Definition: presencestate.h:28
@ AST_PRESENCE_INVALID
Definition: presencestate.h:39
@ AST_PRESENCE_DND
Definition: presencestate.h:33
@ AST_PRESENCE_AVAILABLE
Definition: presencestate.h:29
@ AST_PRESENCE_AWAY
Definition: presencestate.h:30
@ AST_PRESENCE_CHAT
Definition: presencestate.h:32
@ AST_PRESENCE_XA
Definition: presencestate.h:31
#define NULL
Definition: resample.c:96
Structure to describe a channel "technology", ie a channel driver See for examples:
Definition: channel.h:648
int(*const presencestate)(const char *presence_provider, char **subtype, char **message)
Definition: channel.h:696
A presence state provider.
Definition: presencestate.c:97
A list of providers.

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

◆ 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 229 of file presencestate.c.

230{
231 return ast_presence_state_helper(presence_provider, subtype, message, 0);
232}

References ast_presence_state_helper().

Referenced by presence_read().

◆ 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 234 of file presencestate.c.

235{
237
238 if (!callback || !(provider = ast_calloc(1, sizeof(*provider)))) {
239 return -1;
240 }
241
242 provider->callback = callback;
243 ast_copy_string(provider->label, label, sizeof(provider->label));
244
248
249 return 0;
250}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
static struct ast_channel * callback(struct ast_channelstorage_instance *driver, ao2_callback_data_fn *cb_fn, void *arg, void *data, int ao2_flags)
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_INSERT_HEAD
Definition: linkedlists.h:718
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425

References ast_calloc, ast_copy_string(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, callback(), presence_state_provider::label, and provider.

Referenced by load_module().

◆ 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 251 of file presencestate.c.

252{
254 int res = -1;
255
258 if (!strcasecmp(provider->label, label)) {
261 res = 0;
262 break;
263 }
264 }
267
268 return res;
269}
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:570
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:545
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:617

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

◆ 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 368 of file presencestate.c.

369{
371}

References presence_state_topic_all.

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

◆ 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 378 of file presencestate.c.

379{
381}
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

References presence_state_topic_cached, and stasis_caching_get_topic().

◆ 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 117 of file presencestate.c.

118{
119 int i;
120 for (i = 0; i < ARRAY_LEN(state2string); i++) {
121 if (!strcasecmp(val, state2string[i].string)) {
122 return state2string[i].state;
123 }
124 }
126}
Definition: ast_expr2.c:325

References ARRAY_LEN, AST_PRESENCE_INVALID, and state2string.

Referenced by parse_data().

◆ do_presence_state_change()

static void do_presence_state_change ( const char *  provider)
static

Definition at line 322 of file presencestate.c.

323{
324 char *subtype = NULL;
325 char *message = NULL;
327
329
331 return;
332 }
333
335 ast_free(subtype);
337}

References ast_free, AST_PRESENCE_INVALID, ast_presence_state_helper(), NULL, presence_state_event(), provider, and state.

Referenced by ast_presence_state_changed_literal().

◆ presence_state_alloc()

static struct ast_presence_state_message * presence_state_alloc ( const char *  provider,
enum ast_presence_state  state,
const char *  subtype,
const char *  message 
)
static

Definition at line 277 of file presencestate.c.

281{
282 RAII_VAR(struct ast_presence_state_message *, presence_state, ao2_alloc(sizeof(*presence_state), presence_state_dtor), ao2_cleanup);
283
284 if (!presence_state || ast_string_field_init(presence_state, 256)) {
285 return NULL;
286 }
287
288 presence_state->state = state;
289 ast_string_field_set(presence_state, provider, provider);
290 ast_string_field_set(presence_state, subtype, S_OR(subtype, ""));
291 ast_string_field_set(presence_state, message, S_OR(message, ""));
292
293 ao2_ref(presence_state, +1);
294 return presence_state;
295}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
static void presence_state_dtor(void *obj)
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:521
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
Stasis message payload representing a presence state update.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941

References ao2_alloc, ao2_cleanup, ao2_ref, ast_string_field_init, ast_string_field_set, NULL, presence_state_dtor(), provider, RAII_VAR, S_OR, and state.

Referenced by presence_state_event().

◆ presence_state_cached()

static enum ast_presence_state presence_state_cached ( const char *  presence_provider,
char **  subtype,
char **  message 
)
static

Definition at line 128 of file presencestate.c.

129{
131 RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
132 struct ast_presence_state_message *presence_state;
133
135
136 if (!msg) {
137 return res;
138 }
139
140 presence_state = stasis_message_data(msg);
141 res = presence_state->state;
142
143 *subtype = !ast_strlen_zero(presence_state->subtype) ? ast_strdup(presence_state->subtype) : NULL;
144 *message = !ast_strlen_zero(presence_state->message) ? ast_strdup(presence_state->message) : NULL;
145
146 return res;
147}
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
struct stasis_cache * ast_presence_state_cache(void)
Backend cache for ast_presence_state_topic_cached()
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
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.
Definition: stasis_cache.c:686
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
enum ast_presence_state state

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

◆ presence_state_dtor()

static void presence_state_dtor ( void *  obj)
static

Definition at line 271 of file presencestate.c.

272{
273 struct ast_presence_state_message *presence_state = obj;
274 ast_string_field_free_memory(presence_state);
275}
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:374

References ast_string_field_free_memory.

Referenced by presence_state_alloc().

◆ presence_state_engine_cleanup()

static void presence_state_engine_cleanup ( void  )
static

Definition at line 487 of file presencestate.c.

488{
495 AST_TEST_UNREGISTER(test_presence_chan);
496}
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
Definition: stasis.h:1515
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...
Definition: stasis_cache.c:146
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128

References ao2_cleanup, ast_presence_state_message_type(), AST_TEST_UNREGISTER, NULL, presence_state_cache, presence_state_topic_all, presence_state_topic_cached, stasis_caching_unsubscribe_and_join(), and STASIS_MESSAGE_TYPE_CLEANUP.

Referenced by ast_presence_state_engine_init().

◆ presence_state_event()

static void presence_state_event ( const char *  provider,
enum ast_presence_state  state,
const char *  subtype,
const char *  message 
)
static

Definition at line 297 of file presencestate.c.

301{
302 RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
303 RAII_VAR(struct ast_presence_state_message *, presence_state, NULL, ao2_cleanup);
304
306 return;
307 }
308
309 presence_state = presence_state_alloc(provider, state, subtype, message);
310 if (!presence_state) {
311 return;
312 }
313
315 if (!msg) {
316 return;
317 }
318
320}
struct stasis_topic * ast_presence_state_topic_all(void)
Get presence state topic.
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_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.
Definition: stasis.c:1538

References ao2_cleanup, ast_presence_state_message_type(), ast_presence_state_topic_all(), NULL, presence_state_alloc(), provider, RAII_VAR, stasis_message_create(), and stasis_publish().

Referenced by ast_presence_state_changed_literal(), and do_presence_state_change().

◆ presence_state_get_id()

static const char * presence_state_get_id ( struct stasis_message msg)
static

Definition at line 383 of file presencestate.c.

384{
385 struct ast_presence_state_message *presence_state = stasis_message_data(msg);
386
388 return NULL;
389 }
390
391 return presence_state->provider;
392}
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.

References ast_presence_state_message_type(), NULL, stasis_message_data(), and stasis_message_type().

Referenced by ast_presence_state_engine_init().

◆ presence_state_to_ami()

static struct ast_manager_event_blob * presence_state_to_ami ( struct stasis_message msg)
static

Definition at line 528 of file presencestate.c.

529{
530 struct ast_presence_state_message *presence_state = stasis_message_data(msg);
531 struct ast_manager_event_blob *res;
532
533 char *subtype = ast_escape_c_alloc(presence_state->subtype);
534 char *message = ast_escape_c_alloc(presence_state->message);
535
536 res = ast_manager_event_blob_create(EVENT_FLAG_CALL, "PresenceStateChange",
537 "Presentity: %s\r\n"
538 "Status: %s\r\n"
539 "Subtype: %s\r\n"
540 "Message: %s\r\n",
541 presence_state->provider,
542 ast_presence_state2str(presence_state->state),
543 subtype ?: "",
544 message ?: "");
545
546 ast_free(subtype);
548
549 return res;
550}
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.
Definition: manager.c:10237
#define EVENT_FLAG_CALL
Definition: manager.h:76
const char * ast_presence_state2str(enum ast_presence_state state)
Convert presence state to text string for output.
char * ast_escape_c_alloc(const char *s)
Escape standard 'C' sequences in the given string.
Definition: utils.c:2140
Struct containing info for an AMI event to send out.
Definition: manager.h:503

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.

◆ STASIS_MESSAGE_TYPE_DEFN()

STASIS_MESSAGE_TYPE_DEFN ( ast_presence_state_message_type  ,
to_ami = presence_state_to_ami 
)

Variable Documentation

◆ presence_state_cache

struct stasis_cache* presence_state_cache

◆ presence_state_providers

struct presence_state_providers presence_state_providers = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
static

◆ presence_state_topic_all

struct stasis_topic* presence_state_topic_all

◆ presence_state_topic_cached

struct stasis_caching_topic* presence_state_topic_cached

◆ state

◆ 

const struct { ... } state2string[]

Device state strings for printing.

Referenced by ast_presence_state2str(), and ast_presence_state_val().

◆ string

const char* string