Asterisk - The Open Source Telephony Project GIT-master-35be64c
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 int extension_state_legacy_add_device_state_info (struct ao2_container *device_state_info, const struct ast_extension_state_device_state_info *device_state)
 
static void extension_state_legacy_cleanup (void)
 
static struct ao2_container * extension_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 409 of file extension_state_legacy.c.

411{
412 return extension_state_legacy_add_destroy(context, exten, change_cb, NULL, data, 0);
413}
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 403 of file extension_state_legacy.c.

405{
406 return extension_state_legacy_add_destroy(context, exten, change_cb, destroy_cb, data, 0);
407}

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 415 of file extension_state_legacy.c.

417{
418 return extension_state_legacy_add_destroy(context, exten, change_cb, destroy_cb, data, 1);
419}

References extension_state_legacy_add_destroy().

Referenced by subscription_established(), and test_watcher_add().

◆ 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 421 of file extension_state_legacy.c.

423{
424 return extension_state_legacy_add_destroy(context, exten, change_cb, NULL, data, 1);
425}

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 427 of file extension_state_legacy.c.

428{
430
431 /* A negative id is considered invalid */
432 if (id < 0) {
433 return -1;
434 }
435
436 if (!id) { /* id == 0 is a callback without extension */
437 if (!change_cb) {
438 return -1;
439 }
440
441 /*
442 * Global callbacks all have the ID of 0 so we need to find the actual index
443 * for them in the vector for removal based on callback.
444 */
446 for (id = 0; id < AST_VECTOR_SIZE(&extension_state_legacy_callbacks); id++) {
448 if (cb && cb->change_cb == change_cb) {
452 ao2_ref(cb, -1);
453 return 0;
454 }
455 }
457
458 return -1;
459 }
460
464 if (cb) {
468 ao2_ref(cb, -1);
469 return 0;
470 }
471 }
473
474 return -1;
475}
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:637
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition vector.h:708

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(), test_watcher_remove(), 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 173 of file extension_state_legacy.c.

175{
176 struct ast_extension_state_device_snapshot *device_snapshot;
177 enum ast_extension_states device_state;
178
179 device_snapshot = ast_extension_state_get_latest_device_snapshot(c, exten, context);
180 if (!device_snapshot) {
181 return -1;
182 }
183
184 device_state = device_snapshot->state;
185
186 /* The caller wants device state info, so allocate a container and populate it */
187 if (device_state_info) {
188 *device_state_info = extension_state_legacy_create_device_state_info(device_snapshot);
189 }
190
191 ao2_ref(device_snapshot, -1);
192
193 return device_state;
194}
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 504 of file extension_state_legacy.c.

505{
506 /* Since we're not pre-allocating for any callbacks this can't fail */
509
510 return 0;
511}
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_add_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 301 of file extension_state_legacy.c.

303{
304 struct extension_state_legacy_state_cb *state_cb;
305 int id;
306
308 if (!state_cb) {
309 return -1;
310 }
311
312 state_cb->change_cb = change_cb;
313 state_cb->destroy_cb = destroy_cb;
314 state_cb->data = data;
315 state_cb->extended = extended;
316
318
319 /*
320 * Callbacks for both per-extension and all are stored in a single vector which may have gaps in it.
321 * When adding a new callback, we look for the first gap in the vector and insert the callback there.
322 * If there are no gaps, we append it to the end of the vector.
323 * For per-extension the ID of a callback is its index in the vector + 1, since 0 is reserved for "all" callbacks.
324 */
325 for (id = 0; id < AST_VECTOR_SIZE(&extension_state_legacy_callbacks); id++) {
327 continue;
328 }
329
330 state_cb->id = id + 1;
331
332 /* This can't fail since the vector would have already resized */
334
335 break;
336 }
337
338 if (!state_cb->id) {
339 /* The vector will resize when we append, which can fail, so handle it */
342 /* On failure the caller retains ownership of data */
343 state_cb->destroy_cb = NULL;
344 ao2_ref(state_cb, -1);
345 return -1;
346 }
348 }
349
350 /* At this point it is guaranteed that the callback has been inserted so we can setup
351 * the message router to accept messages from the appropriate topic and translate into
352 * the legacy callback.
353 */
354 if (!context && !exten) {
355 /*
356 * The all topic will receive all extension state updates which can end up being quite
357 * a lot, so we use a dedicated thread for each legacy callback to ensure that the
358 * pool of stasis threads does not become overloaded.
359 */
361 } else {
362 struct stasis_topic *topic = ast_extension_state_topic(exten, context);
363
364 /*
365 * Per-extension on the other hand will have comparatively few extension state updates
366 * so we use the pool for it instead. Additionally the creation of the message router will
367 * fail if topic is NULL, so we don't do an explicit check and just let it try.
368 */
369 state_cb->router = stasis_message_router_create_pool(topic);
370 ao2_cleanup(topic);
371 }
372
373 /* If there is no message router allocated this callback is useless, so bail */
374 if (!state_cb->router) {
377 /* On failure the caller retains ownership of data */
378 state_cb->destroy_cb = NULL;
379 ao2_ref(state_cb, -1);
380 return -1;
381 }
382
383 /*
384 * Each of the message router callbacks translates the extension state messages into
385 * the legacy callback format and then calls the legacy callback with the appropriate data.
386 */
393
395
396 /*
397 * We don't hold a reference directly but the vector does and since we haven't given the ID back
398 * there's no way for the caller to remove it, thus it has to be valid even now.
399 */
400 return (!context && !exten) ? 0 : state_cb->id;
401}
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_add_device_state_info()

static int extension_state_legacy_add_device_state_info ( struct ao2_container *  device_state_info,
const struct ast_extension_state_device_state_info *  device_state 
)
static

Definition at line 116 of file extension_state_legacy.c.

118{
119 struct ast_device_state_info *obj;
120
121 obj = ao2_alloc_options(sizeof(*obj) + strlen(device_state->device) + 1, device_state_info_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
122 if (!obj) {
123 return -1;
124 }
125
126 obj->device_state = device_state->state;
127 strcpy(obj->device_name, device_state->device); /* Safe */
129 ao2_link(device_state_info, obj);
130 ao2_ref(obj, -1);
131
132 return 0;
133}
#define ao2_link(container, obj)
Add an object to a container.
Definition astobj2.h:1532
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)
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

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_link, ao2_ref, ast_extension_state_get_device_causing_channel(), ast_device_state_info::causing_channel, ast_device_state_info::device_name, ast_device_state_info::device_state, and device_state_info_destroy().

Referenced by extension_state_legacy_create_device_state_info().

◆ extension_state_legacy_cleanup()

static void extension_state_legacy_cleanup ( void  )
static

Definition at line 484 of file extension_state_legacy.c.

485{
486 int i;
487
489 for (i = 0; i < AST_VECTOR_SIZE(&extension_state_legacy_callbacks); i++) {
491
492 if (!cb) {
493 continue;
494 }
495
498 ao2_ref(cb, -1);
499 }
502}
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 142 of file extension_state_legacy.c.

143{
145 int i;
146
147 if (!device_state_info) {
148 return NULL;
149 }
150
151 /*
152 * The causing device is not part of additional_devices, but the legacy API
153 * expects the device state info to contain every contributing device.
154 */
155 if (device_snapshot->causing_device &&
156 extension_state_legacy_add_device_state_info(device_state_info, device_snapshot->causing_device)) {
157 ao2_ref(device_state_info, -1);
158 return NULL;
159 }
160
161 for (i = 0; i < AST_VECTOR_SIZE(&device_snapshot->additional_devices); i++) {
162 struct ast_extension_state_device_state_info *source_info = AST_VECTOR_GET(&device_snapshot->additional_devices, i);
163
164 if (extension_state_legacy_add_device_state_info(device_state_info, source_info)) {
165 ao2_ref(device_state_info, -1);
166 return NULL;
167 }
168 }
169
170 return device_state_info;
171}
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Definition astobj2.h:1327
static int extension_state_legacy_add_device_state_info(struct ao2_container *device_state_info, const struct ast_extension_state_device_state_info *device_state)
Generic container type.
struct ast_extension_state_device_snapshot::@232 additional_devices
Vector of additional device states that contributed to update.
struct ast_extension_state_device_state_info * causing_device
The device that caused this update.
Individual device states that contributed to snapshot.

References ast_extension_state_device_snapshot::additional_devices, AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_container_alloc_list, ao2_ref, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_extension_state_device_snapshot::causing_device, extension_state_legacy_add_device_state_info(), and NULL.

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 276 of file extension_state_legacy.c.

278{
279 struct extension_state_legacy_state_cb *cb = userdata;
280 struct ast_extension_state_remove_message *remove_message = stasis_message_data(msg);
281 struct ast_state_cb_info info = {
282 .reason = AST_HINT_UPDATE_DEVICE,
283 .exten_state = AST_EXTENSION_REMOVED,
284 };
285
286 cb->change_cb(remove_message->context, remove_message->extension, &info, cb->data);
287}
@ 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 204 of file extension_state_legacy.c.

206{
208 ao2_cleanup(userdata);
209 }
210}
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 235 of file extension_state_legacy.c.

237{
238 struct extension_state_legacy_state_cb *cb = userdata;
239 struct ast_extension_state_update_message *update_message = stasis_message_data(msg);
240 struct ast_state_cb_info info = {
241 .exten_state = update_message->new_device_snapshot->state,
242 .presence_state = update_message->new_presence_snapshot->presence_state,
243 .presence_subtype = S_OR(update_message->new_presence_snapshot->presence_subtype, ""),
244 .presence_message = S_OR(update_message->new_presence_snapshot->presence_message, ""),
245 };
246
247 /* If the presence has changed, notify the callback */
248 if (update_message->new_presence_snapshot != update_message->old_presence_snapshot) {
250 cb->change_cb(update_message->context, update_message->extension, &info, cb->data);
251 }
252
253 /* If the device state has changed, notify the callback */
254 if (update_message->new_device_snapshot != update_message->old_device_snapshot) {
256
257 /* If they want extended information we need to provide the channels */
258 if (cb->extended) {
260 }
261
262 cb->change_cb(update_message->context, update_message->extension, &info, cb->data);
263
264 ao2_cleanup(info.device_state_info);
265 }
266}
@ 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.