Asterisk - The Open Source Telephony Project GIT-master-266378a
Loading...
Searching...
No Matches
Data Structures | Functions
extension_state.h File Reference
#include "asterisk/pbx.h"
Include dependency graph for extension_state.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_extension_state_device_snapshot
 Device snapshot for an extension state. More...
 
struct  ast_extension_state_device_state_info
 Individual device states that contributed to snapshot. More...
 
struct  ast_extension_state_presence_snapshot
 Presence snapshot for an extension state. More...
 
struct  ast_extension_state_remove_message
 Stasis message for extension state removal message. More...
 
struct  ast_extension_state_update_message
 Stasis message for extension state update message. More...
 

Functions

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.
 
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.
 
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.
 
struct stasis_message_type * ast_extension_state_remove_message_type (void)
 Get extension state remove 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_update_message_type (void)
 Get extension state update message type.
 

Detailed Description

API providing extension state management.

Definition in file extension_state.h.

Function Documentation

◆ ast_extension_state_get_device_causing_channel()

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.

Since
23.5.0
22.11.0
20.21.0
Parameters
deviceThe device itself
device_stateThe state of the device
Returns
The channel that is causing the device to be in the given state
Return values
NULLif there is no channel causing the device to be in the given state

Definition at line 1069 of file extension_state.c.

1070{
1071 enum ast_channel_state search_state = 0; /* prevent false uninit warning */
1072 char match[AST_CHANNEL_NAME];
1073 struct ast_channel_iterator *chan_iter;
1074 struct ast_channel *chan, *channel = NULL;
1075 struct timeval chantime = {0, }; /* prevent false uninit warning */
1076
1077 switch (device_state) {
1078 case AST_DEVICE_RINGING:
1080 /* find ringing channel */
1081 search_state = AST_STATE_RINGING;
1082 break;
1083 case AST_DEVICE_BUSY:
1084 /* find busy channel */
1085 search_state = AST_STATE_BUSY;
1086 break;
1087 case AST_DEVICE_ONHOLD:
1088 case AST_DEVICE_INUSE:
1089 /* find up channel */
1090 search_state = AST_STATE_UP;
1091 break;
1092 case AST_DEVICE_UNKNOWN:
1094 case AST_DEVICE_INVALID:
1096 case AST_DEVICE_TOTAL /* not a state */:
1097 /* no channels are of interest */
1098 return NULL;
1099 }
1100
1101 /* iterate over all channels of the device */
1102 snprintf(match, sizeof(match), "%s-", device);
1103 chan_iter = ast_channel_iterator_by_name_new(match, strlen(match));
1104 for (; (chan = ast_channel_iterator_next(chan_iter)); ast_channel_unref(chan)) {
1105 ast_channel_lock(chan);
1106 /* this channel's state doesn't match */
1107 if (search_state != ast_channel_state(chan)) {
1108 ast_channel_unlock(chan);
1109 continue;
1110 }
1111 /* any non-ringing channel will fit */
1112 if (search_state != AST_STATE_RINGING) {
1113 ast_channel_unlock(chan);
1114 channel = chan;
1115 break;
1116 }
1117 /* but we need the oldest ringing channel of the device to match with undirected pickup */
1118 if (!channel) {
1119 chantime = ast_channel_creationtime(chan);
1120 ast_channel_ref(chan); /* must ref it! */
1121 channel = chan;
1122 } else if (ast_tvcmp(ast_channel_creationtime(chan), chantime) < 0) {
1123 chantime = ast_channel_creationtime(chan);
1124 ast_channel_unref(channel);
1125 ast_channel_ref(chan); /* must ref it! */
1126 channel = chan;
1127 }
1128 ast_channel_unlock(chan);
1129 }
1131
1132 return channel;
1133}
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition chan_iax2.c:2401
struct ast_channel_iterator * ast_channel_iterator_by_name_new(const char *name, size_t name_len)
Create a new channel iterator based on name.
Definition channel.c:1368
struct ast_channel_iterator * ast_channel_iterator_destroy(struct ast_channel_iterator *i)
Destroy a channel iterator.
Definition channel.c:1349
#define ast_channel_lock(chan)
Definition channel.h:2983
struct ast_channel * ast_channel_iterator_next(struct ast_channel_iterator *i)
Get the next channel for a channel iterator.
Definition channel.c:1388
#define ast_channel_ref(c)
Increase channel reference count.
Definition channel.h:3008
struct timeval ast_channel_creationtime(struct ast_channel *chan)
#define AST_CHANNEL_NAME
Definition channel.h:173
#define ast_channel_unref(c)
Decrease channel reference count.
Definition channel.h:3019
#define ast_channel_unlock(chan)
Definition channel.h:2984
ast_channel_state
ast_channel states
@ AST_STATE_RINGING
@ AST_STATE_BUSY
@ AST_STATE_UP
@ AST_DEVICE_RINGINUSE
Definition devicestate.h:60
@ AST_DEVICE_INUSE
Definition devicestate.h:55
@ AST_DEVICE_UNKNOWN
Definition devicestate.h:53
@ AST_DEVICE_ONHOLD
Definition devicestate.h:61
@ AST_DEVICE_RINGING
Definition devicestate.h:59
@ AST_DEVICE_INVALID
Definition devicestate.h:57
@ AST_DEVICE_BUSY
Definition devicestate.h:56
@ AST_DEVICE_NOT_INUSE
Definition devicestate.h:54
@ AST_DEVICE_TOTAL
Definition devicestate.h:62
@ AST_DEVICE_UNAVAILABLE
Definition devicestate.h:58
#define NULL
Definition resample.c:96
Main Channel structure associated with a channel.
int ast_tvcmp(struct timeval _a, struct timeval _b)
Compress two struct timeval instances returning -1, 0, 1 if the first arg is smaller,...
Definition time.h:137

References ast_channel_creationtime(), ast_channel_iterator_by_name_new(), ast_channel_iterator_destroy(), ast_channel_iterator_next(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_ref, ast_channel_unlock, ast_channel_unref, AST_DEVICE_BUSY, AST_DEVICE_INUSE, AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, AST_DEVICE_ONHOLD, AST_DEVICE_RINGING, AST_DEVICE_RINGINUSE, AST_DEVICE_TOTAL, AST_DEVICE_UNAVAILABLE, AST_DEVICE_UNKNOWN, AST_STATE_BUSY, AST_STATE_RINGING, AST_STATE_UP, ast_tvcmp(), match(), and NULL.

Referenced by extension_state_legacy_add_device_state_info().

◆ ast_extension_state_get_latest_device_snapshot()

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.

Since
23.5.0
22.11.0
20.21.0
Parameters
chanThe optional channel to get the underlying hint from, if it needs to be created
extenThe extension to get the device state message for
contextThe context of the extension
Returns
The latest device snapshot for the extension
Return values
NULLif the extension does not have a configured hint

Definition at line 1406 of file extension_state.c.

1408{
1409 struct extension_state *state;
1410 struct ast_extension_state_device_snapshot *device_snapshot;
1411
1412 state = extension_state_get(chan, context, exten);
1413 if (!state) {
1414 return NULL;
1415 }
1416
1417 ao2_lock(state);
1419 device_snapshot = ao2_bump(state->device_snapshot);
1421 ao2_ref(state, -1);
1422
1423 return device_snapshot;
1424}
#define ao2_unlock(a)
Definition astobj2.h:729
#define ao2_lock(a)
Definition astobj2.h:717
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition astobj2.h:480
static struct extension_state * extension_state_get(struct ast_channel *chan, const char *context, const char *extension)
static void extension_state_device_snapshot_refresh(struct extension_state *state)
Device snapshot for an extension state.
Extension state information.

References ao2_bump, ao2_lock, ao2_ref, ao2_unlock, extension_state_device_snapshot_refresh(), extension_state_get(), and NULL.

Referenced by ast_extension_state(), and ast_extension_state_extended().

◆ ast_extension_state_get_latest_presence_snapshot()

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.

Since
23.5.0
22.11.0
20.21.0
Parameters
chanThe optional channel to get the underlying hint from, if it needs to be created
extenThe extension to get the presence state message for
contextThe context of the extension
Returns
The latest presence snapshot for the extension
Return values
NULLif the extension does not have a configured hint

Definition at line 1485 of file extension_state.c.

1487{
1488 struct extension_state *state;
1489 struct ast_extension_state_presence_snapshot *presence_snapshot;
1490
1491 state = extension_state_get(chan, context, exten);
1492 if (!state) {
1493 return NULL;
1494 }
1495
1496 ao2_lock(state);
1498 presence_snapshot = ao2_bump(state->presence_snapshot);
1500 ao2_ref(state, -1);
1501
1502 return presence_snapshot;
1503}
static void extension_state_presence_snapshot_refresh(struct extension_state *state)
Presence snapshot for an extension state.

References ao2_bump, ao2_lock, ao2_ref, ao2_unlock, extension_state_get(), extension_state_presence_snapshot_refresh(), and NULL.

Referenced by ast_hint_presence_state().

◆ ast_extension_state_remove_message_type()

struct stasis_message_type * ast_extension_state_remove_message_type ( void  )

Get extension state remove message type.

Since
23.5.0
22.11.0
20.21.0
Return values
Stasismessage type for extension state remove messages

Referenced by ast_extension_state_init(), extension_state_cleanup(), extension_state_legacy_add_destroy(), and extension_state_remove_message_create().

◆ ast_extension_state_topic()

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.

Since
23.5.0
22.11.0
20.21.0
Parameters
extenThe extension to receive extension state messages for
contextThe context of the extension
Returns
The topic for extension state messages
Return values
NULLif it has not been allocated

Definition at line 1298 of file extension_state.c.

1299{
1300 struct extension_state *state;
1301 struct stasis_topic *topic;
1302
1303 state = extension_state_get(NULL, context, exten);
1304 if (!state) {
1305 return NULL;
1306 }
1307
1308 ao2_lock(state);
1309 topic = ao2_bump(state->extension_state_topic);
1311 ao2_ref(state, -1);
1312
1313 return topic;
1314}

References ao2_bump, ao2_lock, ao2_ref, ao2_unlock, extension_state_get(), and NULL.

Referenced by extension_state_legacy_add_destroy().

◆ ast_extension_state_topic_all()

struct stasis_topic * ast_extension_state_topic_all ( void  )

Get the Stasis topic to receive all extension state messages.

Since
23.5.0
22.11.0
20.21.0
Returns
The topic for extension state messages
Return values
NULLif it has not been allocated

Definition at line 1293 of file extension_state.c.

1294{
1296}
static struct stasis_topic * extension_state_topic_all
Topic which receives all extension state updates.

References extension_state_topic_all.

Referenced by extension_state_legacy_add_destroy().

◆ ast_extension_state_update_message_type()

struct stasis_message_type * ast_extension_state_update_message_type ( void  )