Asterisk - The Open Source Telephony Project GIT-master-6144b6b
Loading...
Searching...
No Matches
extension_state.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2026, Sangoma Technologies Corporation
5 *
6 * Joshua C. Colp <jcolp@sangoma.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*! \file
20 * \ref ExtensionState
21 *
22 * \page ExtensionState API providing extension state management.
23
24Before we talk about extension state let's talk about the fundamentals that
25drive it. Extension state is driven based on three things: hints, device state,
26and presence state. Hints are the stateless configuration that map a dialplan location,
27context and extension, to zero or more devices and/or zero or more presence state
28providers. Device state provides information about the associated device(s).
29Presence state provides information about the associated presence state provider(s).
30
31The extension state API itself acts as an aggregator of the device state and presence
32state information using the hint configuration to determine both the individual
33identifier as well as the aggregation sources. The API provides the ability to query
34the current state of an extension, as well as subscribe to be notified when the state
35of an extension changes.
36
37When hint configuration changes this is reconciled and the extension state is updated
38accordingly. If a hint has been added the corresponding extension state is created. If
39a hint has been removed the corresponding extension state is removed. For cases where
40the hint has been added or updated the sources of information are updated on the
41extension state and its state is recalculated. This may involve subscribing to new
42device state topics or unsubscribing from old ones.
43
44Extension state uses synchronous per-device subscriptions to receive device state
45updates. Synchronous is used as the overhead of asynchronous delivery is not worth
46the added overhead and CPU for the small amount of work done when device states change.
47On receipt of a device state update the extension device state is recalculated and if
48the state has changed the extension device state is updated and any subscribers are
49notified.
50
51Presence state uses a single global subscription to receive presence state updates as
52no per-presence state provider topic is available and also due to the extremely small
53number of presence state updates that occur on a system. Just like device state
54updates the extension presence state is recalculated and if it has changed it is
55updated and any subscribers are notified.
56
57To minimize querying of other APIs in Asterisk extension state keeps an internal
58cache of device states and presence state on each extension state. This cache is
59updated when device state or presence state changes and is used to determine the
60aggregated state of an extension. The aggregated state is also cached on the
61extension state for quick access by API users who do not subscribe to receive
62updates.
63
64*/
65
66#ifndef _ASTERISK_EXTENSION_STATE_H
67#define _ASTERISK_EXTENSION_STATE_H
68
69#include "asterisk/pbx.h"
70
71/*! \brief Individual device states that contributed to snapshot */
73 /*! \brief The state of the device */
75 /*! \brief The name of the device */
76 char device[0];
77};
78
79/*! \brief Device snapshot for an extension state*/
81 /*! \brief The state of the extension */
83 /*! \brief The device that caused this update */
85 /*! \brief Vector of additional device states that contributed to update */
87};
88
89/*! \brief Presence snapshot for an extension state */
91 /*! \brief The presence state of the extension */
93 /*! \brief The subtype of the presence state */
95 /*! \brief An optional message for the presence */
97};
98
99/*! \brief Stasis message for extension state update message */
101 /*! \brief The old device snapshot */
103 /*! \brief The new device snapshot - will be pointer equivalent to old if unchanged */
105 /*! \brief The old presence snapshot */
107 /*! \brief The new presence snapshot - will be pointer equivalent to old if unchanged */
109 /*! \brief The dialplan context */
110 char *context;
111 /*! \brief The dialplan extension */
112 char extension[0];
113};
114
115/*! \brief Stasis message for extension state removal message */
117 /*! \brief The dialplan context */
118 char *context;
119 /*! \brief The dialplan extension */
120 char extension[0];
121};
122
123/*!
124 * \brief Get the Stasis topic to receive all extension state messages
125 * \since 23.5.0
126 * \since 22.11.0
127 * \since 20.21.0
128 *
129 * \return The topic for extension state messages
130 * \retval NULL if it has not been allocated
131 */
133
134/*!
135 * \brief Get the Stasis topic to receive extension state messages for a specific extension
136 * \since 23.5.0
137 * \since 22.11.0
138 * \since 20.21.0
139 *
140 * \param exten The extension to receive extension state messages for
141 * \param context The context of the extension
142 * \return The topic for extension state messages
143 * \retval NULL if it has not been allocated
144 */
145struct stasis_topic *ast_extension_state_topic(const char *exten, const char *context);
146
147/*!
148 * \brief Get the latest device state message for an extension
149 * \since 23.5.0
150 * \since 22.11.0
151 * \since 20.21.0
152 *
153 * \param chan The optional channel to get the underlying hint from, if it needs to be created
154 * \param exten The extension to get the device state message for
155 * \param context The context of the extension
156 * \return The latest device snapshot for the extension
157 * \retval NULL if the extension does not have a configured hint
158 */
160 const char *exten, const char *context);
161
162/*!
163 * \brief Get the latest presence state message for an extension
164 * \since 23.5.0
165 * \since 22.11.0
166 * \since 20.21.0
167 *
168 * \param chan The optional channel to get the underlying hint from, if it needs to be created
169 * \param exten The extension to get the presence state message for
170 * \param context The context of the extension
171 * \return The latest presence snapshot for the extension
172 * \retval NULL if the extension does not have a configured hint
173 */
175 const char *exten, const char *context);
176
177/*!
178 * \brief Get the channel that is causing the device to be in the given state, if any
179 * \since 23.5.0
180 * \since 22.11.0
181 * \since 20.21.0
182 *
183 * \param device The device itself
184 * \param device_state The state of the device
185 * \return The channel that is causing the device to be in the given state
186 * \retval NULL if there is no channel causing the device to be in the given state
187 */
188struct ast_channel *ast_extension_state_get_device_causing_channel(const char *device, enum ast_device_state device_state);
189
190/*!
191 * \brief Get extension state update message type
192 * \since 23.5.0
193 * \since 22.11.0
194 * \since 20.21.0
195 *
196 * \retval Stasis message type for extension state update messages
197 */
199
200/*!
201 * \brief Get extension state remove message type
202 * \since 23.5.0
203 * \since 22.11.0
204 * \since 20.21.0
205 *
206 * \retval Stasis message type for extension state remove messages
207 */
209
210#endif /* ASTERISK_EXTENSION_STATE_H */
ast_device_state
Device States.
Definition devicestate.h:52
struct stasis_message_type * ast_extension_state_update_message_type(void)
Get extension state update message type.
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_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.
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.
Core PBX routines and definitions.
ast_extension_states
Extension states.
Definition pbx.h:61
ast_presence_state
Main Channel structure associated with a channel.
Device snapshot for an extension state.
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.
enum ast_extension_states state
The state of the extension.
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.
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.
Stasis message for extension state removal message.
char * context
The dialplan context.
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.
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.
structure to hold extensions
#define AST_VECTOR(name, type)
Define a vector structure.
Definition vector.h:44