ARI: Add ability to raise arbitrary User Events

User events can now be generated from ARI.  Events can be signalled with
arbitrary json variables, and include one or more of channel, bridge, or
endpoint snapshots.  An application must be specified which will receive
the event message (other applications can subscribe to it).  The message
will also be delivered via AMI provided a channel is attached.  Dialplan
generated user event messages are still transmitted via the channel, and
will only be received by a stasis application they are attached to or if
the channel is subscribed to.

This change also introduces the multi object blob mechanism used to send
multiple snapshot types in a single message.  The dialplan app UserEvent
was also changed to use multi object blob, and a new stasis message type
created to handle them.

ASTERISK-22697 #close
Review: https://reviewboard.asterisk.org/r/3494/
........

Merged revisions 414405 from http://svn.asterisk.org/svn/asterisk/branches/12


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@414406 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Scott Griepentrog
2014-05-22 16:09:51 +00:00
parent d00882108f
commit cf21644d6a
17 changed files with 839 additions and 100 deletions

View File

@@ -1032,6 +1032,77 @@ struct ao2_container *stasis_cache_dump_by_eid(struct stasis_cache *cache, struc
*/
struct ao2_container *stasis_cache_dump_all(struct stasis_cache *cache, struct stasis_message_type *type);
/*!
* \brief Object type code for multi user object snapshots
*/
enum stasis_user_multi_object_snapshot_type {
STASIS_UMOS_CHANNEL = 0, /*!< Channel Snapshots */
STASIS_UMOS_BRIDGE, /*!< Bridge Snapshots */
STASIS_UMOS_ENDPOINT, /*!< Endpoint Snapshots */
};
/*! \brief Number of snapshot types */
#define STASIS_UMOS_MAX (STASIS_UMOS_ENDPOINT + 1)
/*!
* \brief Message type for custom user defined events with multi object blobs
* \return The stasis_message_type for user event
* \since 12.3.0
*/
struct stasis_message_type *ast_multi_user_event_type(void);
/*!
* \brief Create a stasis multi object blob
* \since 12.3.0
*
* \details
* Multi object blob can store a combination of arbitrary json values
* (the blob) and also snapshots of various other system objects (such
* as channels, bridges, etc) for delivery through a stasis message.
* The multi object blob is first created, then optionally objects
* are added to it, before being attached to a message and delivered
* to stasis topic.
*
* \param blob Json blob
*
* \note When used for an ast_multi_user_event_type message, the
* json blob should contain at minimum {eventname: name}.
*
* \retval ast_multi_object_blob* if succeeded
* \retval NULL if creation failed
*/
struct ast_multi_object_blob *ast_multi_object_blob_create(struct ast_json *blob);
/*!
* \brief Add an object to a multi object blob previously created
* \since 12.3.0
*
* \param multi The multi object blob previously created
* \param type Type code for the object such as channel, bridge, etc.
* \param object Snapshot object of the type supplied to typename
*
* \return Nothing
*/
void ast_multi_object_blob_add(struct ast_multi_object_blob *multi, enum stasis_user_multi_object_snapshot_type type, void *object);
/*!
* \brief Create and publish a stasis message blob on a channel with it's snapshot
* \since 12.3.0
*
* \details
* For compatibility with app_userevent, this creates a multi object
* blob message, attaches the channel snapshot to it, and publishes it
* to the channel's topic.
*
* \param chan The channel to snapshot and publish event to
* \param type The message type
* \param blob A json blob to publish with the snapshot
*
* \return Nothing
*/
void ast_multi_object_blob_single_channel_publish(struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob);
/*! @} */
/*! @{ */

View File

@@ -228,6 +228,33 @@ void stasis_app_unregister_event_source(struct stasis_app_event_source *obj);
*/
void stasis_app_unregister_event_sources(void);
/*! \brief Return code for stasis_app_user_event */
enum stasis_app_user_event_res {
STASIS_APP_USER_OK,
STASIS_APP_USER_APP_NOT_FOUND,
STASIS_APP_USER_EVENT_SOURCE_NOT_FOUND,
STASIS_APP_USER_EVENT_SOURCE_BAD_SCHEME,
STASIS_APP_USER_USEREVENT_INVALID,
STASIS_APP_USER_INTERNAL_ERROR,
};
/*!
* \brief Generate a Userevent for stasis app (echo to AMI)
*
* \param app_name Name of the application to generate event for/to.
* \param event_name Name of the Userevent.
* \param source_uris URIs for the source objects to attach to event.
* \param sources_count Array size of source_uris.
* \param userevent_data Custom parameters for the user event
* \param userevents_count Array size of userevent_data
*
* \return \ref stasis_app_user_event_res return code.
*/
enum stasis_app_user_event_res stasis_app_user_event(const char *app_name,
const char *event_name,
const char **source_uris, int sources_count,
struct ast_json *json_variables);
/*! \brief Return code for stasis_app_[un]subscribe */
enum stasis_app_subscribe_res {
@@ -590,6 +617,13 @@ struct ast_channel_snapshot *stasis_app_control_get_snapshot(
void stasis_app_control_publish(
struct stasis_app_control *control, struct stasis_message *message);
/*!
* \brief Returns the stasis topic for an app
*
* \param app Stasis app to get topic of
*/
struct stasis_topic *ast_app_get_topic(struct stasis_app *app);
/*!
* \brief Queue a control frame without payload.
*

View File

@@ -379,14 +379,6 @@ struct stasis_message_type *ast_channel_dial_type(void);
*/
struct stasis_message_type *ast_channel_varset_type(void);
/*!
* \since 12
* \brief Message type for when a custom user event is sent on a channel.
*
* \retval A stasis message type
*/
struct stasis_message_type *ast_channel_user_event_type(void);
/*!
* \since 12
* \brief Message type for when a hangup is requested on a channel.