|
Asterisk - The Open Source Telephony Project GIT-master-6144b6b
|
Before we talk about extension state let's talk about the fundamentals that drive it. Extension state is driven based on three things: hints, device state, and presence state. Hints are the stateless configuration that map a dialplan location, context and extension, to zero or more devices and/or zero or more presence state providers. Device state provides information about the associated device(s). Presence state provides information about the associated presence state provider(s).
The extension state API itself acts as an aggregator of the device state and presence state information using the hint configuration to determine both the individual identifier as well as the aggregation sources. The API provides the ability to query the current state of an extension, as well as subscribe to be notified when the state of an extension changes.
When hint configuration changes this is reconciled and the extension state is updated accordingly. If a hint has been added the corresponding extension state is created. If a hint has been removed the corresponding extension state is removed. For cases where the hint has been added or updated the sources of information are updated on the extension state and its state is recalculated. This may involve subscribing to new device state topics or unsubscribing from old ones.
Extension state uses synchronous per-device subscriptions to receive device state updates. Synchronous is used as the overhead of asynchronous delivery is not worth the added overhead and CPU for the small amount of work done when device states change. On receipt of a device state update the extension device state is recalculated and if the state has changed the extension device state is updated and any subscribers are notified.
Presence state uses a single global subscription to receive presence state updates as no per-presence state provider topic is available and also due to the extremely small number of presence state updates that occur on a system. Just like device state updates the extension presence state is recalculated and if it has changed it is updated and any subscribers are notified.
To minimize querying of other APIs in Asterisk extension state keeps an internal cache of device states and presence state on each extension state. This cache is updated when device state or presence state changes and is used to determine the aggregated state of an extension. The aggregated state is also cached on the extension state for quick access by API users who do not subscribe to receive updates.