Move more channel events to Stasis; move res_json.c to main/json.c.

This patch started out simply as fixing the bouncing tests introduced
in r382685, but required some other changes to give it a decent
implementation.

To fix the bouncing tests, the UserEvent and Newexten AMI events
needed to be refactored to dispatch via Stasis. Dispatching directly
to AMI resulted in those events sometimes getting ahead of the
associated Newchannel events, which would understandably confuse anyone.

I found that instead of creating a zillion different message types and
structures associated with them, it would be preferable to define a
message type that has a channel snapshot and a blob of structured data
with a small bit of additional information. The JSON object model
provides a very nice way of representing structured data, so I went
with that.

 * Move JSON support from res_json.c to main/json.c
   * Made libjansson-dev a required dependency
 * Added an ast_channel_blob message type, which has a channel
   snapshot and JSON blob of data.
 * Changed UserEvent and Newexten events so that they are dispatched
   via ast_channel_blob messages on the channel's topic.
 * Got rid of the ast_channel_varset message; used ast_channel_blob
   instead.
 * Extracted the manager functions converting Stasis channel events to
   AMI events into manager_channel.c.

(issue ASTERISK-21096)
Review: https://reviewboard.asterisk.org/r/2381/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@383579 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
David M. Lee
2013-03-22 14:06:46 +00:00
parent 401f7c1880
commit cf9324b25e
15 changed files with 1647 additions and 1305 deletions

View File

@@ -151,6 +151,7 @@ extern "C" {
#include "asterisk/ccss.h"
#include "asterisk/framehook.h"
#include "asterisk/stasis.h"
#include "asterisk/json.h"
#define DATASTORE_INHERIT_FOREVER INT_MAX
@@ -4187,24 +4188,51 @@ struct stasis_caching_topic *ast_channel_topic_all_cached(void);
/*!
* \since 12
* \brief Variable set event.
* \brief Blob of data associated with a channel.
*
* The \c blob is actually a JSON object of structured data. It has a "type" field
* which contains the type string describing this blob.
*/
struct ast_channel_varset {
/*! Channel variable was set on (or NULL for global variable) */
struct ast_channel_blob {
/*! Channel blob is associated with (or NULL for global/all channels) */
struct ast_channel_snapshot *snapshot;
/*! Variable name */
char *variable;
/*! New value */
char *value;
/*! JSON blob of data */
struct ast_json *blob;
};
/*!
* \since 12
* \brief Message type for \ref ast_channel_varset messages.
* \brief Message type for \ref ast_channel_blob messages.
*
* \retval Message type for \ref ast_channel_varset messages.
* \retval Message type for \ref ast_channel_blob messages.
*/
struct stasis_message_type *ast_channel_varset(void);
struct stasis_message_type *ast_channel_blob(void);
/*!
* \since 12
* \brief Extracts the type field from a \ref ast_channel_blob.
* Returned \c char* is still owned by \a obj
* \param obj Channel blob object.
* \return Type field value from the blob.
* \return \c NULL on error.
*/
const char *ast_channel_blob_type(struct ast_channel_blob *obj);
/*!
* \since 12
* \brief Creates a \ref ast_channel_blob message.
*
* The \a blob JSON object requires a \c "type" field describing the blob. It
* should also be treated as immutable and not modified after it is put into the
* message.
*
* \param chan Channel blob is associated with, or NULL for global/all channels.
* \param blob JSON object representing the data.
* \return \ref ast_channel_blob message.
* \return \c NULL on error
*/
struct stasis_message *ast_channel_blob_create(struct ast_channel *chan,
struct ast_json *blob);
/*!
* \since 12