Move device state distribution to Stasis-core

In the move from Asterisk's event system to Stasis, this makes
distributed device state aggregation always-on, removes unnecessary
task processors where possible, and collapses aggregate and
non-aggregate states into a single cache for ease of retrieval. This
also removes an intermediary step in device state aggregation.

Review: https://reviewboard.asterisk.org/r/2389/
(closes issue ASTERISK-21101)
Patch-by: Kinsey Moore <kmoore@digium.com>


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@385860 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kinsey Moore
2013-04-16 15:33:59 +00:00
parent c1ae5dc49b
commit 191cf99ae1
10 changed files with 712 additions and 448 deletions

View File

@@ -38,6 +38,7 @@
#define _ASTERISK_DEVICESTATE_H
#include "asterisk/channelstate.h"
#include "asterisk/utils.h"
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
@@ -270,19 +271,87 @@ struct ast_devstate_aggregate {
};
/*!
* \brief Enable distributed device state processing.
*
* \details
* By default, Asterisk assumes that device state change events will only be
* originating from one instance. If a module gets loaded and configured such
* that multiple instances of Asterisk will be sharing device state, this
* function should be called to enable distributed device state processing.
* It is off by default to save on unnecessary processing.
*
* \retval 0 success
* \retval -1 failure
* \brief The structure that contains device state
* \since 12
*/
int ast_enable_distributed_devstate(void);
struct ast_device_state_message {
AST_DECLARE_STRING_FIELDS(
AST_STRING_FIELD(cache_id); /*!< A unique ID used for hashing */
AST_STRING_FIELD(device); /*!< The name of the device */
);
enum ast_device_state state; /*!< The state of the device */
struct ast_eid *eid; /*!< The EID of the server where this message originated, NULL EID means aggregate state */
enum ast_devstate_cache cachable; /*!< Flag designating the cachability of this device state */
};
/*!
* \brief Get the Stasis topic for device state messages
* \retval The topic for device state messages
* \retval NULL if it has not been allocated
* \since 12
*/
struct stasis_topic *ast_device_state_topic_all(void);
/*!
* \brief Get the Stasis topic for device state messages for a specific device
* \param uniqueid The device for which to get the topic
* \retval The topic structure for MWI messages for a given device
* \retval NULL if it failed to be found or allocated
* \since 12
*/
struct stasis_topic *ast_device_state_topic(const char *device);
/*!
* \brief Get the Stasis caching topic for device state messages
* \retval The caching topic for device state messages
* \retval NULL if it has not been allocated
* \since 12
*/
struct stasis_caching_topic *ast_device_state_topic_cached(void);
/*!
* \brief Get the Stasis message type for device state messages
* \retval The message type for device state messages
* \retval NULL if it has not been allocated
* \since 12
*/
struct stasis_message_type *ast_device_state_message_type(void);
/*!
* \brief Initialize the device state core
* \retval 0 Success
* \retval -1 Failure
* \since 12
*/
int devstate_init(void);
/*!
* \brief Publish a device state update
* \param[in] device The device name
* \param[in] state The state of the device
* \param[in] cachable Whether the device state can be cached
* \retval 0 Success
* \retval -1 Failure
* \since 12
*/
#define ast_publish_device_state(device, state, cachable) \
ast_publish_device_state_full(device, state, cachable, &ast_eid_default)
/*!
* \brief Publish a device state update with EID
* \param[in] device The device name
* \param[in] state The state of the device
* \param[in] cachable Whether the device state can be cached
* \param[in] eid The EID of the server that originally published the message
* \retval 0 Success
* \retval -1 Failure
* \since 12
*/
int ast_publish_device_state_full(
const char *device,
enum ast_device_state state,
enum ast_devstate_cache cachable,
struct ast_eid *eid);
#if defined(__cplusplus) || defined(c_plusplus)
}

View File

@@ -47,6 +47,7 @@
#include "asterisk/linkedlists.h"
#include "asterisk/stringfields.h"
#include "asterisk/pbx.h"
#include "asterisk/stasis.h"
/*
* As per RFC 3920 - section 3.1, the maximum length for a full Jabber ID
@@ -135,7 +136,7 @@ struct ast_xmpp_client {
int timeout;
unsigned int reconnect:1; /*!< Reconnect this client */
struct stasis_subscription *mwi_sub; /*!< If distributing event information the MWI subscription */
struct ast_event_sub *device_state_sub; /*!< If distributing event information the device state subscription */
struct stasis_subscription *device_state_sub; /*!< If distributing event information the device state subscription */
};
/*!