Asterisk - The Open Source Telephony Project GIT-master-35be64c
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 1090 of file extension_state.c.

1091{
1092 enum ast_channel_state search_state = 0; /* prevent false uninit warning */
1093 char match[AST_CHANNEL_NAME];
1094 struct ast_channel_iterator *chan_iter;
1095 struct ast_channel *chan, *channel = NULL;
1096 struct timeval chantime = {0, }; /* prevent false uninit warning */
1097
1098 switch (device_state) {
1099 case AST_DEVICE_RINGING:
1101 /* find ringing channel */
1102 search_state = AST_STATE_RINGING;
1103 break;
1104 case AST_DEVICE_BUSY:
1105 /* find busy channel */
1106 search_state = AST_STATE_BUSY;
1107 break;
1108 case AST_DEVICE_ONHOLD:
1109 case AST_DEVICE_INUSE:
1110 /* find up channel */
1111 search_state = AST_STATE_UP;
1112 break;
1113 case AST_DEVICE_UNKNOWN:
1115 case AST_DEVICE_INVALID:
1117 case AST_DEVICE_TOTAL /* not a state */:
1118 /* no channels are of interest */
1119 return NULL;
1120 }
1121
1122 /* iterate over all channels of the device */
1123 snprintf(match, sizeof(match), "%s-", device);
1124 chan_iter = ast_channel_iterator_by_name_new(match, strlen(match));
1125 for (; (chan = ast_channel_iterator_next(chan_iter)); ast_channel_unref(chan)) {
1126 ast_channel_lock(chan);
1127 /* this channel's state doesn't match */
1128 if (search_state != ast_channel_state(chan)) {
1129 ast_channel_unlock(chan);
1130 continue;
1131 }
1132 /* any non-ringing channel will fit */
1133 if (search_state != AST_STATE_RINGING) {
1134 ast_channel_unlock(chan);
1135 channel = chan;
1136 break;
1137 }
1138 /* but we need the oldest ringing channel of the device to match with undirected pickup */
1139 if (!channel) {
1140 chantime = ast_channel_creationtime(chan);
1141 ast_channel_ref(chan); /* must ref it! */
1142 channel = chan;
1143 } else if (ast_tvcmp(ast_channel_creationtime(chan), chantime) < 0) {
1144 chantime = ast_channel_creationtime(chan);
1145 ast_channel_unref(channel);
1146 ast_channel_ref(chan); /* must ref it! */
1147 channel = chan;
1148 }
1149 ast_channel_unlock(chan);
1150 }
1152
1153 return channel;
1154}
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 1427 of file extension_state.c.

1429{
1430 struct extension_state *state;
1431 struct ast_extension_state_device_snapshot *device_snapshot;
1432
1433 state = extension_state_get(chan, context, exten);
1434 if (!state) {
1435 return NULL;
1436 }
1437
1438 ao2_lock(state);
1440 device_snapshot = ao2_bump(state->device_snapshot);
1442 ao2_ref(state, -1);
1443
1444 return device_snapshot;
1445}
#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 1506 of file extension_state.c.

1508{
1509 struct extension_state *state;
1510 struct ast_extension_state_presence_snapshot *presence_snapshot;
1511
1512 state = extension_state_get(chan, context, exten);
1513 if (!state) {
1514 return NULL;
1515 }
1516
1517 ao2_lock(state);
1519 presence_snapshot = ao2_bump(state->presence_snapshot);
1521 ao2_ref(state, -1);
1522
1523 return presence_snapshot;
1524}
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 1319 of file extension_state.c.

1320{
1321 struct extension_state *state;
1322 struct stasis_topic *topic;
1323
1324 state = extension_state_get(NULL, context, exten);
1325 if (!state) {
1326 return NULL;
1327 }
1328
1329 ao2_lock(state);
1330 topic = ao2_bump(state->extension_state_topic);
1332 ao2_ref(state, -1);
1333
1334 return topic;
1335}

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

1315{
1317}
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  )