Asterisk - The Open Source Telephony Project GIT-master-6144b6b
Loading...
Searching...
No Matches
Data Structures | Functions | Variables
extension_state_legacy.c File Reference
#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/module.h"
#include "asterisk/extension_state.h"
#include "asterisk/pbx.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_message_router.h"
#include "asterisk/astobj2.h"
#include "asterisk/lock.h"
#include "asterisk/vector.h"
Include dependency graph for extension_state_legacy.c:

Go to the source code of this file.

Data Structures

struct  extension_state_legacy_state_cb
 

Functions

int ast_extension_state (struct ast_channel *c, const char *context, const char *exten)
 Uses hint and devicestate callback to get the state of an extension.
 
int ast_extension_state_add (const char *context, const char *exten, ast_state_cb_type change_cb, void *data)
 Add watcher for extension states.
 
int ast_extension_state_add_destroy (const char *context, const char *exten, ast_state_cb_type change_cb, ast_state_cb_destroy_type destroy_cb, void *data)
 Add watcher for extension states with destructor.
 
int ast_extension_state_add_destroy_extended (const char *context, const char *exten, ast_state_cb_type change_cb, ast_state_cb_destroy_type destroy_cb, void *data)
 Add watcher for extended extension states with destructor.
 
int ast_extension_state_add_extended (const char *context, const char *exten, ast_state_cb_type change_cb, void *data)
 Add watcher for extended extension states.
 
int ast_extension_state_del (int id, ast_state_cb_type change_cb)
 Deletes a state change watcher by ID.
 
int ast_extension_state_extended (struct ast_channel *c, const char *context, const char *exten, struct ao2_container **device_state_info)
 Uses hint and devicestate callback to get the extended state of an extension.
 
int ast_extension_state_legacy_init (void)
 
int ast_hint_presence_state (struct ast_channel *c, const char *context, const char *exten, char **subtype, char **message)
 Uses hint and presence state callback to get the presence state of an extension.
 
static void device_state_info_destroy (void *obj)
 
static int extension_state_legacy_add_destroy (const char *context, const char *exten, ast_state_cb_type change_cb, ast_state_cb_destroy_type destroy_cb, void *data, int extended)
 
static void extension_state_legacy_cleanup (void)
 
static struct ao2_containerextension_state_legacy_create_device_state_info (struct ast_extension_state_device_snapshot *device_snapshot)
 
static void extension_state_legacy_remove_cb (void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
 
static void extension_state_legacy_state_cb_destroy (void *obj)
 
static void extension_state_legacy_subscription_change_cb (void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
 
static void extension_state_legacy_update_cb (void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
 

Variables

struct { 
 
   size_t   current 
 
   struct extension_state_legacy_state_cb **   elems 
 
   size_t   max 
 
extension_state_legacy_callbacks 
 Legacy callbacks, the index of it in the vector is the id given to the API user for per-extension.
 
static ast_mutex_t extension_state_legacy_callbacks_lock = AST_MUTEX_INIT_VALUE
 Lock to protect the callbacks vector.
 

Function Documentation

◆ ast_extension_state()

int ast_extension_state ( struct ast_channel c,
const char *  context,
const char *  exten 
)

Uses hint and devicestate callback to get the state of an extension.

Parameters
cthis is not important
contextwhich context to look in
extenwhich extension to get state
Returns
extension state as defined in the ast_extension_states enum

Definition at line 55 of file extension_state_legacy.c.

56{
57 struct ast_extension_state_device_snapshot *device_snapshot;
58 enum ast_extension_states device_state;
59
60 device_snapshot = ast_extension_state_get_latest_device_snapshot(c, exten, context);
61 if (!device_snapshot) {
62 return -1;
63 }
64
65 device_state = device_snapshot->state;
66 ao2_ref(device_snapshot, -1);
67
68 return device_state;
69}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
struct ast_extension_state_device_snapshot * ast_extension_state_get_latest_device_snapshot(struct ast_channel *chan, const char *exten, const char *context)
Get the latest device state message for an extension.
ast_extension_states
Extension states.
Definition pbx.h:61
Device snapshot for an extension state.
enum ast_extension_states state
The state of the extension.
static struct test_val c

References ao2_ref, ast_extension_state_get_latest_device_snapshot(), c, and ast_extension_state_device_snapshot::state.

Referenced by action_extensionstate(), extstate_read(), and get_queue_member_status().

◆ ast_extension_state_add()

int ast_extension_state_add ( const char *  context,
const char *  exten,
ast_state_cb_type  change_cb,
void *  data 
)

Add watcher for extension states.

Parameters
contextwhich context to look in
extenwhich extension to get state
change_cbcallback to call if state changed
datato pass to callback
Note
If context and exten are NULL then the added watcher is global. The change_cb is called for every extension's state change.
The change_cb is called if the state of an extension is changed.
Return values
-1on failure
0Global watcher added successfully
IDon success

Definition at line 375 of file extension_state_legacy.c.

377{
378 return extension_state_legacy_add_destroy(context, exten, change_cb, NULL, data, 0);
379}
static int extension_state_legacy_add_destroy(const char *context, const char *exten, ast_state_cb_type change_cb, ast_state_cb_destroy_type destroy_cb, void *data, int extended)
#define NULL
Definition resample.c:96

References extension_state_legacy_add_destroy(), and NULL.

Referenced by __init_manager(), create_queue_member(), and publisher_start().

◆ ast_extension_state_add_destroy()

int ast_extension_state_add_destroy ( const char *  context,
const char *  exten,
ast_state_cb_type  change_cb,
ast_state_cb_destroy_type  destroy_cb,
void *  data 
)

Add watcher for extension states with destructor.

Since
1.8.9
10.1.0
Parameters
contextwhich context to look in
extenwhich extension to get state
change_cbcallback to call if state changed
destroy_cbcallback to call when the watcher is destroyed.
datato pass to callbacks
Note
If context and exten are NULL then the added watcher is global. The change_cb is called for every extension's state change.
The change_cb is called if the state of an extension is changed.
The destroy_cb is called when the watcher is deleted so the watcher can release any associated resources.
Return values
-1on failure
0Global watcher added successfully
IDon success

Definition at line 369 of file extension_state_legacy.c.

371{
372 return extension_state_legacy_add_destroy(context, exten, change_cb, destroy_cb, data, 0);
373}

References extension_state_legacy_add_destroy().

◆ ast_extension_state_add_destroy_extended()

int ast_extension_state_add_destroy_extended ( const char *  context,
const char *  exten,
ast_state_cb_type  change_cb,
ast_state_cb_destroy_type  destroy_cb,
void *  data 
)

Add watcher for extended extension states with destructor.

Since
11
Parameters
contextwhich context to look in
extenwhich extension to get state
change_cbcallback to call if state changed
destroy_cbcallback to call when the watcher is destroyed.
datato pass to callbacks
Note
If context and exten are NULL then the added watcher is global. The change_cb is called for every extension's state change.
The change_cb is called if the state of an extension is changed. The extended state is passed to the callback in the device_state_info member of ast_state_cb_info.
The destroy_cb is called when the watcher is deleted so the watcher can release any associated resources.
Return values
-1on failure
0Global watcher added successfully
IDon success

Definition at line 381 of file extension_state_legacy.c.

383{
384 return extension_state_legacy_add_destroy(context, exten, change_cb, destroy_cb, data, 1);
385}

References extension_state_legacy_add_destroy().

Referenced by subscription_established().

◆ ast_extension_state_add_extended()

int ast_extension_state_add_extended ( const char *  context,
const char *  exten,
ast_state_cb_type  change_cb,
void *  data 
)

Add watcher for extended extension states.

Since
11
Parameters
contextwhich context to look in
extenwhich extension to get state
change_cbcallback to call if state changed
datato pass to callback
Note
If context and exten are NULL then the added watcher is global. The change_cb is called for every extension's state change.
The change_cb is called if the state of an extension is changed. The extended state is passed to the callback in the device_state_info member of ast_state_cb_info.
Return values
-1on failure
0Global watcher added successfully
IDon success

Definition at line 387 of file extension_state_legacy.c.

389{
390 return extension_state_legacy_add_destroy(context, exten, change_cb, NULL, data, 1);
391}

References extension_state_legacy_add_destroy(), and NULL.

◆ ast_extension_state_del()

int ast_extension_state_del ( int  id,
ast_state_cb_type  change_cb 
)

Deletes a state change watcher by ID.

Parameters
idof the state watcher to delete (0 for global watcher)
change_cbcallback to call if state changed (Used if id == 0 (global))
Return values
0success
-1failure

Definition at line 393 of file extension_state_legacy.c.

394{
396
397 /* A negative id is considered invalid */
398 if (id < 0) {
399 return -1;
400 }
401
402 if (!id) { /* id == 0 is a callback without extension */
403 if (!change_cb) {
404 return -1;
405 }
406
407 /*
408 * Global callbacks all have the ID of 0 so we need to find the actual index
409 * for them in the vector for removal based on callback.
410 */
412 for (id = 0; id < AST_VECTOR_SIZE(&extension_state_legacy_callbacks); id++) {
414 if (cb && cb->change_cb == change_cb) {
418 ao2_ref(cb, -1);
419 return 0;
420 }
421 }
423
424 return -1;
425 }
426
430 if (cb) {
434 ao2_ref(cb, -1);
435 return 0;
436 }
437 }
439
440 return -1;
441}
static struct @377 extension_state_legacy_callbacks
Legacy callbacks, the index of it in the vector is the id given to the API user for per-extension.
static ast_mutex_t extension_state_legacy_callbacks_lock
Lock to protect the callbacks vector.
#define ast_mutex_unlock(a)
Definition lock.h:197
#define ast_mutex_lock(a)
Definition lock.h:196
void stasis_message_router_unsubscribe(struct stasis_message_router *router)
Unsubscribe the router from the upstream topic.
struct stasis_message_router * router
#define AST_VECTOR_REPLACE(vec, idx, elem)
Replace an element at a specific position in a vector, growing the vector if needed.
Definition vector.h:295
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition vector.h:620
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition vector.h:691

References ao2_ref, ast_mutex_lock, ast_mutex_unlock, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, extension_state_legacy_state_cb::change_cb, extension_state_legacy_callbacks, extension_state_legacy_callbacks_lock, NULL, extension_state_legacy_state_cb::router, and stasis_message_router_unsubscribe().

Referenced by destroy_queue_member_cb(), subscription_shutdown(), and unload_module().

◆ ast_extension_state_extended()

int ast_extension_state_extended ( struct ast_channel c,
const char *  context,
const char *  exten,
struct ao2_container **  device_state_info 
)

Uses hint and devicestate callback to get the extended state of an extension.

Since
11
Parameters
cthis is not important
contextwhich context to look in
extenwhich extension to get state
[out]device_state_infoptr to an ao2_container with extended state info, must be unref'd after use.
Returns
extension state as defined in the ast_extension_states enum

Definition at line 143 of file extension_state_legacy.c.

145{
146 struct ast_extension_state_device_snapshot *device_snapshot;
147 enum ast_extension_states device_state;
148
149 device_snapshot = ast_extension_state_get_latest_device_snapshot(c, exten, context);
150 if (!device_snapshot) {
151 return -1;
152 }
153
154 device_state = device_snapshot->state;
155
156 /* The caller wants device state info, so allocate a container and populate it */
157 if (device_state_info) {
158 *device_state_info = extension_state_legacy_create_device_state_info(device_snapshot);
159 }
160
161 ao2_ref(device_snapshot, -1);
162
163 return device_state;
164}
static struct ao2_container * extension_state_legacy_create_device_state_info(struct ast_extension_state_device_snapshot *device_snapshot)

References ao2_ref, ast_extension_state_get_latest_device_snapshot(), c, extension_state_legacy_create_device_state_info(), and ast_extension_state_device_snapshot::state.

Referenced by exten_state_data_alloc().

◆ ast_extension_state_legacy_init()

int ast_extension_state_legacy_init ( void  )

Provided by extension_state_legacy.c

Definition at line 470 of file extension_state_legacy.c.

471{
472 /* Since we're not pre-allocating for any callbacks this can't fail */
475
476 return 0;
477}
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition clicompat.c:19
static void extension_state_legacy_cleanup(void)
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition vector.h:124

References ast_register_cleanup(), AST_VECTOR_INIT, extension_state_legacy_callbacks, and extension_state_legacy_cleanup().

Referenced by asterisk_daemon().

◆ ast_hint_presence_state()

int ast_hint_presence_state ( struct ast_channel c,
const char *  context,
const char *  exten,
char **  subtype,
char **  message 
)

Uses hint and presence state callback to get the presence state of an extension.

Parameters
cthis is not important
contextwhich context to look in
extenwhich extension to get state
[out]subtypeFurther information regarding the presence returned
[out]messageCustom message further describing current presence
Note
The subtype and message are dynamically allocated and must be freed by the caller of this function.
Returns
returns the presence state value.

Definition at line 71 of file extension_state_legacy.c.

72{
73 struct ast_extension_state_presence_snapshot *presence_snapshot;
75
76 presence_snapshot = ast_extension_state_get_latest_presence_snapshot(c, exten, context);
77 if (!presence_snapshot) {
78 return -1;
79 }
80
81 presence_state = presence_snapshot->presence_state;
82 if (presence_snapshot->presence_subtype) {
83 *subtype = ast_strdup(presence_snapshot->presence_subtype);
84 }
85 if (presence_snapshot->presence_message) {
86 *message = ast_strdup(presence_snapshot->presence_message);
87 }
88
89 ao2_ref(presence_snapshot, -1);
90
91 return presence_state;
92}
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
struct ast_extension_state_presence_snapshot * ast_extension_state_get_latest_presence_snapshot(struct ast_channel *chan, const char *exten, const char *context)
Get the latest presence state message for an extension.
ast_presence_state
Presence snapshot for an extension state.
char * presence_subtype
The subtype of the presence state.
char * presence_message
An optional message for the presence.
enum ast_presence_state presence_state
The presence state of the extension.

References ao2_ref, ast_extension_state_get_latest_presence_snapshot(), ast_strdup, c, ast_extension_state_presence_snapshot::presence_message, ast_extension_state_presence_snapshot::presence_state, and ast_extension_state_presence_snapshot::presence_subtype.

Referenced by exten_state_data_alloc().

◆ device_state_info_destroy()

static void device_state_info_destroy ( void *  obj)
static

Definition at line 100 of file extension_state_legacy.c.

101{
102 struct ast_device_state_info *info = obj;
103
104 ao2_cleanup(info->causing_channel);
105}
#define ao2_cleanup(obj)
Definition astobj2.h:1934

References ao2_cleanup.

Referenced by extension_state_legacy_create_device_state_info().

◆ extension_state_legacy_add_destroy()

static int extension_state_legacy_add_destroy ( const char *  context,
const char *  exten,
ast_state_cb_type  change_cb,
ast_state_cb_destroy_type  destroy_cb,
void *  data,
int  extended 
)
static

Definition at line 271 of file extension_state_legacy.c.

273{
274 struct extension_state_legacy_state_cb *state_cb;
275 int id;
276
278 if (!state_cb) {
279 return -1;
280 }
281
282 state_cb->change_cb = change_cb;
283 state_cb->destroy_cb = destroy_cb;
284 state_cb->data = data;
285 state_cb->extended = extended;
286
288
289 /*
290 * Callbacks for both per-extension and all are stored in a single vector which may have gaps in it.
291 * When adding a new callback, we look for the first gap in the vector and insert the callback there.
292 * If there are no gaps, we append it to the end of the vector.
293 * For per-extension the ID of a callback is its index in the vector + 1, since 0 is reserved for "all" callbacks.
294 */
295 for (id = 0; id < AST_VECTOR_SIZE(&extension_state_legacy_callbacks); id++) {
297 continue;
298 }
299
300 state_cb->id = id + 1;
301
302 /* This can't fail since the vector would have already resized */
304
305 break;
306 }
307
308 if (!state_cb->id) {
309 /* The vector will resize when we append, which can fail, so handle it */
312 ao2_ref(state_cb, -1);
313 return -1;
314 }
316 }
317
318 /* At this point it is guaranteed that the callback has been inserted so we can setup
319 * the message router to accept messages from the appropriate topic and translate into
320 * the legacy callback.
321 */
322 if (!context && !exten) {
323 /*
324 * The all topic will receive all extension state updates which can end up being quite
325 * a lot, so we use a dedicated thread for each legacy callback to ensure that the
326 * pool of stasis threads does not become overloaded.
327 */
329 } else {
330 struct stasis_topic *topic = ast_extension_state_topic(exten, context);
331
332 /*
333 * Per-extension on the other hand will have comparatively few extension state updates
334 * so we use the pool for it instead. Additionally the creation of the message router will
335 * fail if topic is NULL, so we don't do an explicit check and just let it try.
336 */
337 state_cb->router = stasis_message_router_create_pool(topic);
338 ao2_cleanup(topic);
339 }
340
341 /* If there is no message router allocated this callback is useless, so bail */
342 if (!state_cb->router) {
345 ao2_ref(state_cb, -1);
346 return -1;
347 }
348
349 /*
350 * Each of the message router callbacks translates the extension state messages into
351 * the legacy callback format and then calls the legacy callback with the appropriate data.
352 */
359
361
362 /*
363 * We don't hold a reference directly but the vector does and since we haven't given the ID back
364 * there's no way for the caller to remove it, thus it has to be valid even now.
365 */
366 return (!context && !exten) ? 0 : state_cb->id;
367}
enum queue_result id
Definition app_queue.c:1790
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition astobj2.h:367
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition astobj2.h:404
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition astobj2.h:480
struct stasis_message_type * ast_extension_state_update_message_type(void)
Get extension state update message type.
struct stasis_topic * ast_extension_state_topic(const char *exten, const char *context)
Get the Stasis topic to receive extension state messages for a specific extension.
struct stasis_topic * ast_extension_state_topic_all(void)
Get the Stasis topic to receive all extension state messages.
struct stasis_message_type * ast_extension_state_remove_message_type(void)
Get extension state remove message type.
static void extension_state_legacy_update_cb(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
static void extension_state_legacy_remove_cb(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
static void extension_state_legacy_subscription_change_cb(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
static void extension_state_legacy_state_cb_destroy(void *obj)
struct stasis_message_type * stasis_subscription_change_type(void)
Gets the message type for subscription change notices.
#define stasis_message_router_create(topic)
Create a new message router object.
int stasis_message_router_add(struct stasis_message_router *router, struct stasis_message_type *message_type, stasis_subscription_cb callback, void *data)
Add a route to a message router.
#define stasis_message_router_create_pool(topic)
Create a new message router object.
ast_state_cb_destroy_type destroy_cb
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition vector.h:267

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_bump, ao2_cleanup, ao2_ref, ast_extension_state_remove_message_type(), ast_extension_state_topic(), ast_extension_state_topic_all(), ast_extension_state_update_message_type(), ast_mutex_lock, ast_mutex_unlock, AST_VECTOR_APPEND, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, extension_state_legacy_state_cb::change_cb, extension_state_legacy_state_cb::data, extension_state_legacy_state_cb::destroy_cb, extension_state_legacy_state_cb::extended, extension_state_legacy_callbacks, extension_state_legacy_callbacks_lock, extension_state_legacy_remove_cb(), extension_state_legacy_state_cb_destroy(), extension_state_legacy_subscription_change_cb(), extension_state_legacy_update_cb(), id, extension_state_legacy_state_cb::id, NULL, extension_state_legacy_state_cb::router, stasis_message_router_add(), stasis_message_router_create, stasis_message_router_create_pool, and stasis_subscription_change_type().

Referenced by ast_extension_state_add(), ast_extension_state_add_destroy(), ast_extension_state_add_destroy_extended(), and ast_extension_state_add_extended().

◆ extension_state_legacy_cleanup()

static void extension_state_legacy_cleanup ( void  )
static

Definition at line 450 of file extension_state_legacy.c.

451{
452 int i;
453
455 for (i = 0; i < AST_VECTOR_SIZE(&extension_state_legacy_callbacks); i++) {
457
458 if (!cb) {
459 continue;
460 }
461
464 ao2_ref(cb, -1);
465 }
468}
void stasis_message_router_unsubscribe_and_join(struct stasis_message_router *router)
Unsubscribe the router from the upstream topic, blocking until the final message has been processed.
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition vector.h:185

References ao2_ref, ast_mutex_lock, ast_mutex_unlock, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, extension_state_legacy_callbacks, extension_state_legacy_callbacks_lock, NULL, extension_state_legacy_state_cb::router, and stasis_message_router_unsubscribe_and_join().

Referenced by ast_extension_state_legacy_init().

◆ extension_state_legacy_create_device_state_info()

static struct ao2_container * extension_state_legacy_create_device_state_info ( struct ast_extension_state_device_snapshot device_snapshot)
static

Definition at line 114 of file extension_state_legacy.c.

115{
117 int i;
118
119 if (!device_state_info) {
120 return NULL;
121 }
122
123 for (i = 0; i < AST_VECTOR_SIZE(&device_snapshot->additional_devices); i++) {
124 struct ast_extension_state_device_state_info *source_info = AST_VECTOR_GET(&device_snapshot->additional_devices, i);
125 struct ast_device_state_info *obj;
126
127 obj = ao2_alloc_options(sizeof(*obj) + strlen(source_info->device) + 1, device_state_info_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
128 if (!obj) {
129 ao2_ref(device_state_info, -1);
130 return NULL;
131 }
132
133 obj->device_state = source_info->state;
134 strcpy(obj->device_name, source_info->device); /* Safe */
136 ao2_link(device_state_info, obj);
137 ao2_ref(obj, -1);
138 }
139
140 return device_state_info;
141}
#define ao2_link(container, obj)
Add an object to a container.
Definition astobj2.h:1532
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Definition astobj2.h:1327
struct ast_channel * ast_extension_state_get_device_causing_channel(const char *device, enum ast_device_state device_state)
Get the channel that is causing the device to be in the given state, if any.
static void device_state_info_destroy(void *obj)
Generic container type.
struct ast_channel * causing_channel
Definition pbx.h:98
char device_name[1]
Definition pbx.h:99
enum ast_device_state device_state
Definition pbx.h:97
struct ast_extension_state_device_snapshot::@232 additional_devices
Vector of additional device states that contributed to update.
Individual device states that contributed to snapshot.
enum ast_device_state state
The state of the device.
char device[0]
The name of the device.

References ast_extension_state_device_snapshot::additional_devices, AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_container_alloc_list, ao2_link, ao2_ref, ast_extension_state_get_device_causing_channel(), AST_VECTOR_GET, AST_VECTOR_SIZE, ast_device_state_info::causing_channel, ast_extension_state_device_state_info::device, ast_device_state_info::device_name, ast_device_state_info::device_state, device_state_info_destroy(), NULL, and ast_extension_state_device_state_info::state.

Referenced by ast_extension_state_extended(), and extension_state_legacy_update_cb().

◆ extension_state_legacy_remove_cb()

static void extension_state_legacy_remove_cb ( void *  userdata,
struct stasis_subscription sub,
struct stasis_message msg 
)
static

Definition at line 246 of file extension_state_legacy.c.

248{
249 struct extension_state_legacy_state_cb *cb = userdata;
250 struct ast_extension_state_remove_message *remove_message = stasis_message_data(msg);
251 struct ast_state_cb_info info = {
252 .reason = AST_HINT_UPDATE_DEVICE,
253 .exten_state = AST_EXTENSION_REMOVED,
254 };
255
256 cb->change_cb(remove_message->context, remove_message->extension, &info, cb->data);
257}
@ AST_EXTENSION_REMOVED
Definition pbx.h:62
@ AST_HINT_UPDATE_DEVICE
Definition pbx.h:91
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
Stasis message for extension state removal message.
char * context
The dialplan context.
char extension[0]
The dialplan extension.

References AST_EXTENSION_REMOVED, AST_HINT_UPDATE_DEVICE, extension_state_legacy_state_cb::change_cb, ast_extension_state_remove_message::context, extension_state_legacy_state_cb::data, ast_extension_state_remove_message::extension, and stasis_message_data().

Referenced by extension_state_legacy_add_destroy().

◆ extension_state_legacy_state_cb_destroy()

static void extension_state_legacy_state_cb_destroy ( void *  obj)
static

◆ extension_state_legacy_subscription_change_cb()

static void extension_state_legacy_subscription_change_cb ( void *  userdata,
struct stasis_subscription sub,
struct stasis_message msg 
)
static

Definition at line 174 of file extension_state_legacy.c.

176{
178 ao2_cleanup(userdata);
179 }
180}
static struct stasis_subscription * sub
Statsd channel stats. Exmaple of how to subscribe to Stasis events.
int stasis_subscription_final_message(struct stasis_subscription *sub, struct stasis_message *msg)
Determine whether a message is the final message to be received on a subscription.
Definition stasis.c:1252

References ao2_cleanup, stasis_subscription_final_message(), and sub.

Referenced by extension_state_legacy_add_destroy().

◆ extension_state_legacy_update_cb()

static void extension_state_legacy_update_cb ( void *  userdata,
struct stasis_subscription sub,
struct stasis_message msg 
)
static

Definition at line 205 of file extension_state_legacy.c.

207{
208 struct extension_state_legacy_state_cb *cb = userdata;
209 struct ast_extension_state_update_message *update_message = stasis_message_data(msg);
210 struct ast_state_cb_info info = {
211 .exten_state = update_message->new_device_snapshot->state,
212 .presence_state = update_message->new_presence_snapshot->presence_state,
213 .presence_subtype = S_OR(update_message->new_presence_snapshot->presence_subtype, ""),
214 .presence_message = S_OR(update_message->new_presence_snapshot->presence_message, ""),
215 };
216
217 /* If the presence has changed, notify the callback */
218 if (update_message->new_presence_snapshot != update_message->old_presence_snapshot) {
220 cb->change_cb(update_message->context, update_message->extension, &info, cb->data);
221 }
222
223 /* If the device state has changed, notify the callback */
224 if (update_message->new_device_snapshot != update_message->old_device_snapshot) {
226
227 /* If they want extended information we need to provide the channels */
228 if (cb->extended) {
230 }
231
232 cb->change_cb(update_message->context, update_message->extension, &info, cb->data);
233
234 ao2_cleanup(info.device_state_info);
235 }
236}
@ AST_HINT_UPDATE_PRESENCE
Definition pbx.h:93
#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 for extension state update message.
char * context
The dialplan context.
struct ast_extension_state_presence_snapshot * old_presence_snapshot
The old presence snapshot.
char extension[0]
The dialplan extension.
struct ast_extension_state_device_snapshot * old_device_snapshot
The old device snapshot.
struct ast_extension_state_presence_snapshot * new_presence_snapshot
The new presence snapshot - will be pointer equivalent to old if unchanged.
struct ast_extension_state_device_snapshot * new_device_snapshot
The new device snapshot - will be pointer equivalent to old if unchanged.

References ao2_cleanup, AST_HINT_UPDATE_DEVICE, AST_HINT_UPDATE_PRESENCE, extension_state_legacy_state_cb::change_cb, ast_extension_state_update_message::context, extension_state_legacy_state_cb::data, extension_state_legacy_state_cb::extended, ast_extension_state_update_message::extension, extension_state_legacy_create_device_state_info(), ast_extension_state_update_message::new_device_snapshot, ast_extension_state_update_message::new_presence_snapshot, ast_extension_state_update_message::old_device_snapshot, ast_extension_state_update_message::old_presence_snapshot, ast_extension_state_presence_snapshot::presence_message, ast_extension_state_presence_snapshot::presence_state, ast_extension_state_presence_snapshot::presence_subtype, S_OR, stasis_message_data(), and ast_extension_state_device_snapshot::state.

Referenced by extension_state_legacy_add_destroy().

Variable Documentation

◆ current

size_t current

Definition at line 53 of file extension_state_legacy.c.

◆ elems

Definition at line 53 of file extension_state_legacy.c.

◆ [struct]

struct { ... } extension_state_legacy_callbacks

Legacy callbacks, the index of it in the vector is the id given to the API user for per-extension.

Referenced by ast_extension_state_del(), ast_extension_state_legacy_init(), extension_state_legacy_add_destroy(), and extension_state_legacy_cleanup().

◆ extension_state_legacy_callbacks_lock

ast_mutex_t extension_state_legacy_callbacks_lock = AST_MUTEX_INIT_VALUE
static

Lock to protect the callbacks vector.

Definition at line 50 of file extension_state_legacy.c.

Referenced by ast_extension_state_del(), extension_state_legacy_add_destroy(), and extension_state_legacy_cleanup().

◆ max

size_t max

Definition at line 53 of file extension_state_legacy.c.