This patch adds a new message bus API to Asterisk.

For the initial use of this bus, I took some work kmoore did creating
channel snapshots. So rather than create AMI events directly in the
channel code, this patch generates Stasis events, which manager.c uses
to then publish the AMI event.

This message bus provides a generic publish/subscribe mechanism within
Asterisk. This message bus is:

 - Loosely coupled; new message types can be added in seperate modules.
 - Easy to use; publishing and subscribing are straightforward
   operations.

In addition to basic publish/subscribe, the patch also provides
mechanisms for message forwarding, and for message caching.

(issue ASTERISK-20887)
(closes issue ASTERISK-20959)
Review: https://reviewboard.asterisk.org/r/2339/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@382685 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
David M. Lee
2013-03-08 15:15:13 +00:00
parent f6f6bc7b59
commit 4edd8be35c
13 changed files with 2812 additions and 115 deletions

View File

@@ -125,7 +125,6 @@ References:
#include "asterisk/abstract_jb.h"
#include "asterisk/astobj2.h"
#include "asterisk/poll-compat.h"
#if defined(__cplusplus) || defined(c_plusplus)
@@ -151,6 +150,7 @@ extern "C" {
#include "asterisk/channelstate.h"
#include "asterisk/ccss.h"
#include "asterisk/framehook.h"
#include "asterisk/stasis.h"
#define DATASTORE_INHERIT_FOREVER INT_MAX
@@ -4102,4 +4102,119 @@ int ast_channel_dialed_causes_add(const struct ast_channel *chan, const struct a
void ast_channel_dialed_causes_clear(const struct ast_channel *chan);
struct ast_flags *ast_channel_flags(struct ast_channel *chan);
/*!
* \since 12
* \brief Structure representing a snapshot of channel state.
*
* While not enforced programmatically, this object is shared across multiple
* threads, and should be threated as an immutable object.
*/
struct ast_channel_snapshot {
AST_DECLARE_STRING_FIELDS(
AST_STRING_FIELD(name); /*!< ASCII unique channel name */
AST_STRING_FIELD(accountcode); /*!< Account code for billing */
AST_STRING_FIELD(peeraccount); /*!< Peer account code for billing */
AST_STRING_FIELD(userfield); /*!< Userfield for CEL billing */
AST_STRING_FIELD(uniqueid); /*!< Unique Channel Identifier */
AST_STRING_FIELD(linkedid); /*!< Linked Channel Identifier -- gets propagated by linkage */
AST_STRING_FIELD(parkinglot); /*!< Default parking lot, if empty, default parking lot */
AST_STRING_FIELD(hangupsource); /*!< Who is responsible for hanging up this channel */
AST_STRING_FIELD(appl); /*!< Current application */
AST_STRING_FIELD(data); /*!< Data passed to current application */
AST_STRING_FIELD(context); /*!< Dialplan: Current extension context */
AST_STRING_FIELD(exten); /*!< Dialplan: Current extension number */
AST_STRING_FIELD(caller_name); /*!< Caller ID Name */
AST_STRING_FIELD(caller_number); /*!< Caller ID Number */
AST_STRING_FIELD(connected_name); /*!< Connected Line Name */
AST_STRING_FIELD(connected_number); /*!< Connected Line Number */
);
struct timeval creationtime; /*!< The time of channel creation */
enum ast_channel_state state; /*!< State of line */
int priority; /*!< Dialplan: Current extension priority */
int amaflags; /*!< AMA flags for billing */
int hangupcause; /*!< Why is the channel hanged up. See causes.h */
struct ast_flags flags; /*!< channel flags of AST_FLAG_ type */
};
/*!
* \since 12
* \brief Generate a snapshot of the channel state. This is an ao2 object, so
* ao2_cleanup() to deallocate.
*
* \param chan The channel from which to generate a snapshot
*
* \retval pointer on success (must be ast_freed)
* \retval NULL on error
*/
struct ast_channel_snapshot *ast_channel_snapshot_create(struct ast_channel *chan);
/*!
* \since 12
* \brief Message type for \ref ast_channel_snapshot.
*
* \retval Message type for \ref ast_channel_snapshot.
*/
struct stasis_message_type *ast_channel_snapshot(void);
/*!
* \since 12
* \brief A topic which publishes the events for a particular channel.
*
* \param chan Channel.
*
* \retval Topic for channel's events.
* \retval \c NULL if \a chan is \c NULL.
*/
struct stasis_topic *ast_channel_topic(struct ast_channel *chan);
/*!
* \since 12
* \brief A topic which publishes the events for all channels.
* \retval Topic for all channel events.
*/
struct stasis_topic *ast_channel_topic_all(void);
/*!
* \since 12
* \brief A caching topic which caches \ref ast_channel_snapshot messages from
* ast_channel_events_all(void).
*
* \retval Topic for all channel events.
*/
struct stasis_caching_topic *ast_channel_topic_all_cached(void);
/*!
* \since 12
* \brief Variable set event.
*/
struct ast_channel_varset {
/*! Channel variable was set on (or NULL for global variable) */
struct ast_channel_snapshot *snapshot;
/*! Variable name */
char *variable;
/*! New value */
char *value;
};
/*!
* \since 12
* \brief Message type for \ref ast_channel_varset messages.
*
* \retval Message type for \ref ast_channel_varset messages.
*/
struct stasis_message_type *ast_channel_varset(void);
/*!
* \since 12
* \brief Publish a \ref ast_channel_varset for a channel.
*
* \param chan Channel to pulish the event for, or \c NULL for 'none'.
* \param variable Name of the variable being set
* \param value Value.
*/
void ast_channel_publish_varset(struct ast_channel *chan,
const char *variable, const char *value);
#endif /* _ASTERISK_CHANNEL_H */