Asterisk - The Open Source Telephony Project GIT-master-6144b6b
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_channelast_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_snapshotast_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_snapshotast_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_typeast_extension_state_remove_message_type (void)
 Get extension state remove message type.
 
struct stasis_topicast_extension_state_topic (const char *exten, const char *context)
 Get the Stasis topic to receive extension state messages for a specific extension.
 
struct stasis_topicast_extension_state_topic_all (void)
 Get the Stasis topic to receive all extension state messages.
 
struct stasis_message_typeast_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 1070 of file extension_state.c.

1071{
1072 enum ast_channel_state search_state = 0; /* prevent false uninit warning */
1073 char match[AST_CHANNEL_NAME];
1074 struct ast_channel_iterator *chan_iter;
1075 struct ast_channel *chan, *channel = NULL;
1076 struct timeval chantime = {0, }; /* prevent false uninit warning */
1077
1078 switch (device_state) {
1079 case AST_DEVICE_RINGING:
1081 /* find ringing channel */
1082 search_state = AST_STATE_RINGING;
1083 break;
1084 case AST_DEVICE_BUSY:
1085 /* find busy channel */
1086 search_state = AST_STATE_BUSY;
1087 break;
1088 case AST_DEVICE_ONHOLD:
1089 case AST_DEVICE_INUSE:
1090 /* find up channel */
1091 search_state = AST_STATE_UP;
1092 break;
1093 case AST_DEVICE_UNKNOWN:
1095 case AST_DEVICE_INVALID:
1097 case AST_DEVICE_TOTAL /* not a state */:
1098 /* no channels are of interest */
1099 return NULL;
1100 }
1101
1102 /* iterate over all channels of the device */
1103 snprintf(match, sizeof(match), "%s-", device);
1104 chan_iter = ast_channel_iterator_by_name_new(match, strlen(match));
1105 for (; (chan = ast_channel_iterator_next(chan_iter)); ast_channel_unref(chan)) {
1106 ast_channel_lock(chan);
1107 /* this channel's state doesn't match */
1108 if (search_state != ast_channel_state(chan)) {
1109 ast_channel_unlock(chan);
1110 continue;
1111 }
1112 /* any non-ringing channel will fit */
1113 if (search_state != AST_STATE_RINGING) {
1114 ast_channel_unlock(chan);
1115 channel = chan;
1116 break;
1117 }
1118 /* but we need the oldest ringing channel of the device to match with undirected pickup */
1119 if (!channel) {
1120 chantime = ast_channel_creationtime(chan);
1121 ast_channel_ref(chan); /* must ref it! */
1122 channel = chan;
1123 } else if (ast_tvcmp(ast_channel_creationtime(chan), chantime) < 0) {
1124 chantime = ast_channel_creationtime(chan);
1125 ast_channel_unref(channel);
1126 ast_channel_ref(chan); /* must ref it! */
1127 channel = chan;
1128 }
1129 ast_channel_unlock(chan);
1130 }
1132
1133 return channel;
1134}
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_create_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 1317 of file extension_state.c.

1319{
1320 struct extension_state *state;
1321 struct ast_extension_state_device_snapshot *device_snapshot;
1322
1323 state = extension_state_get(chan, context, exten);
1324 if (!state) {
1325 return NULL;
1326 }
1327
1328 ao2_lock(state);
1329 device_snapshot = ao2_bump(state->device_snapshot);
1331 ao2_ref(state, -1);
1332
1333 return device_snapshot;
1334}
#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)
Device snapshot for an extension state.
Extension state information.

References ao2_bump, ao2_lock, ao2_ref, ao2_unlock, 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 1336 of file extension_state.c.

1338{
1339 struct extension_state *state;
1340 struct ast_extension_state_presence_snapshot *presence_snapshot;
1341
1342 state = extension_state_get(chan, context, exten);
1343 if (!state) {
1344 return NULL;
1345 }
1346
1347 ao2_lock(state);
1348 presence_snapshot = ao2_bump(state->presence_snapshot);
1350 ao2_ref(state, -1);
1351
1352 return presence_snapshot;
1353}
Presence snapshot for an extension state.

References ao2_bump, ao2_lock, ao2_ref, ao2_unlock, extension_state_get(), 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 1299 of file extension_state.c.

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

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 1294 of file extension_state.c.

1295{
1297}
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  )

Get extension state update message type.

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

Referenced by ast_extension_state_init(), extension_state_cleanup(), extension_state_device_state_cb(), extension_state_legacy_add_destroy(), extension_state_presence_state_cb(), and extension_state_update_sources().