mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-17 23:38:23 +00:00
Break res_stasis into smaller files.
When implementing playback for stasis-http, the monolithicedness of res_stasis really started to get in my way. This patch breaks the major components of res_stasis.c into individual files. * res/stasis/app.c - Stasis application tracking * res/stasis/control.c - Channel control objects * res/stasis/command.c - Channel command object This refactoring also allows res_stasis applications to be loaded as independent modules, such as the new res_stasis_answer module. The bulk of this patch is simply moving code from one file to another, adjusting names and adding accessors as necessary. Review: https://reviewboard.asterisk.org/r/2530/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@388729 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -478,6 +478,9 @@ int ast_register_application2(const char *app, int (*execute)(struct ast_channel
|
||||
*/
|
||||
int ast_unregister_application(const char *app);
|
||||
|
||||
/*! Macro to safely ref and unref the self module for the current scope */
|
||||
#define SCOPED_MODULE_USE(module) \
|
||||
RAII_VAR(struct ast_module *, __self__ ## __LINE__, ast_module_ref(module), ast_module_unref)
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
}
|
||||
|
||||
@@ -53,27 +53,6 @@
|
||||
#include "asterisk/channel.h"
|
||||
#include "asterisk/json.h"
|
||||
|
||||
struct ast_channel_snapshot;
|
||||
|
||||
/*! @{ */
|
||||
|
||||
/*!
|
||||
* \brief Control a channel using \c stasis_app.
|
||||
*
|
||||
* This function blocks until the channel hangs up, or
|
||||
* stasis_app_control_continue() is called on the channel's \ref
|
||||
* stasis_app_control struct.
|
||||
*
|
||||
* \param chan Channel to control with Stasis.
|
||||
* \param app_name Application controlling the channel.
|
||||
* \param argc Number of arguments for the application.
|
||||
* \param argv Arguments for the application.
|
||||
*/
|
||||
int stasis_app_exec(struct ast_channel *chan, const char *app_name, int argc,
|
||||
char *argv[]);
|
||||
|
||||
/*! @} */
|
||||
|
||||
/*! @{ */
|
||||
|
||||
/*!
|
||||
@@ -87,7 +66,7 @@ int stasis_app_exec(struct ast_channel *chan, const char *app_name, int argc,
|
||||
* \param message Message to handle. (borrowed copy)
|
||||
*/
|
||||
typedef void (*stasis_app_cb)(void *data, const char *app_name,
|
||||
struct ast_json *message);
|
||||
struct ast_json *message);
|
||||
|
||||
/*!
|
||||
* \brief Register a new Stasis application.
|
||||
@@ -147,6 +126,16 @@ struct stasis_app_control *stasis_app_control_find_by_channel(
|
||||
struct stasis_app_control *stasis_app_control_find_by_channel_id(
|
||||
const char *channel_id);
|
||||
|
||||
/*!
|
||||
* \brief Returns the uniqueid of the channel associated with this control
|
||||
*
|
||||
* \param control Control object.
|
||||
* \return Uniqueid of the associate channel.
|
||||
* \return \c NULL if \a control is \c NULL.
|
||||
*/
|
||||
const char *stasis_app_control_get_channel_id(
|
||||
const struct stasis_app_control *control);
|
||||
|
||||
/*!
|
||||
* \brief Exit \c res_stasis and continue execution in the dialplan.
|
||||
*
|
||||
@@ -160,20 +149,30 @@ void stasis_app_control_continue(struct stasis_app_control *control);
|
||||
* \brief Answer the channel associated with this control.
|
||||
* \param control Control for \c res_stasis.
|
||||
* \return 0 for success.
|
||||
* \return -1 for error.
|
||||
* \return Non-zero for error.
|
||||
*/
|
||||
int stasis_app_control_answer(struct stasis_app_control *control);
|
||||
|
||||
/*! @} */
|
||||
|
||||
/*! @{ */
|
||||
/*!
|
||||
* \brief Returns the most recent snapshot for the associated channel.
|
||||
*
|
||||
* The returned pointer is AO2 managed, so ao2_cleanup() when you're done.
|
||||
*
|
||||
* \param control Control for \c res_stasis.
|
||||
* \return Most recent snapshot. ao2_cleanup() when done.
|
||||
* \return \c NULL if channel isn't in cache.
|
||||
*/
|
||||
struct ast_channel_snapshot *stasis_app_control_get_snapshot(
|
||||
const struct stasis_app_control *control);
|
||||
|
||||
/*!
|
||||
* \brief Build a JSON object from a \ref ast_channel_snapshot.
|
||||
* \return JSON object representing channel snapshot.
|
||||
* \return \c NULL on error
|
||||
* \brief Publish a message to the \a control's channel's topic.
|
||||
*
|
||||
* \param control Control to publish to
|
||||
* \param message Message to publish
|
||||
*/
|
||||
struct ast_json *ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot);
|
||||
void stasis_app_control_publish(
|
||||
struct stasis_app_control *control, struct stasis_message *message);
|
||||
|
||||
/*!
|
||||
* \brief Increment the res_stasis reference count.
|
||||
|
||||
88
include/asterisk/stasis_app_impl.h
Normal file
88
include/asterisk/stasis_app_impl.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2013, Digium, Inc.
|
||||
*
|
||||
* David M. Lee, II <dlee@digium.com>
|
||||
*
|
||||
* See http://www.asterisk.org for more information about
|
||||
* the Asterisk project. Please do not directly contact
|
||||
* any of the maintainers of this project for assistance;
|
||||
* the project provides a web site, mailing lists and IRC
|
||||
* channels for your use.
|
||||
*
|
||||
* This program is free software, distributed under the terms of
|
||||
* the GNU General Public License Version 2. See the LICENSE file
|
||||
* at the top of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef _ASTERISK_RES_STASIS_H
|
||||
#define _ASTERISK_RES_STASIS_H
|
||||
|
||||
/*! \file
|
||||
*
|
||||
* \brief Backend API for implementing components of res_stasis.
|
||||
*
|
||||
* \author David M. Lee, II <dlee@digium.com>
|
||||
* \since 12
|
||||
*
|
||||
* This file defines functions useful for defining new commands to execute
|
||||
* on channels while they are in Stasis.
|
||||
*/
|
||||
|
||||
#include "asterisk/stasis_app.h"
|
||||
|
||||
/*!
|
||||
* \since 12
|
||||
* \brief Control a channel using \c stasis_app.
|
||||
*
|
||||
* This function blocks until the channel hangs up, or
|
||||
* stasis_app_control_continue() is called on the channel's \ref
|
||||
* stasis_app_control struct.
|
||||
*
|
||||
* \param chan Channel to control with Stasis.
|
||||
* \param app_name Application controlling the channel.
|
||||
* \param argc Number of arguments for the application.
|
||||
* \param argv Arguments for the application.
|
||||
*/
|
||||
int stasis_app_exec(struct ast_channel *chan, const char *app_name, int argc,
|
||||
char *argv[]);
|
||||
|
||||
/*! Callback type for stasis app commands */
|
||||
typedef void *(*stasis_app_command_cb)(struct stasis_app_control *control,
|
||||
struct ast_channel *chan, void *data);
|
||||
|
||||
/*!
|
||||
* \since 12
|
||||
* \brief Invokes a \a command on a \a control's channel.
|
||||
*
|
||||
* This function dispatches the command to be executed in the context of
|
||||
* stasis_app_exec(), so this command will block waiting for the results of
|
||||
* the command.
|
||||
*
|
||||
* \param control Control object for the channel to send the command to.
|
||||
* \param command Command function to execute.
|
||||
* \param data Optional data to pass along with the control function.
|
||||
* \return Return value from \a command.
|
||||
* \return \c NULL on error.
|
||||
*/
|
||||
void *stasis_app_send_command(struct stasis_app_control *control,
|
||||
stasis_app_command_cb command, void *data);
|
||||
|
||||
/*!
|
||||
* \since 12
|
||||
* \brief Asynchronous version of stasis_app_send().
|
||||
*
|
||||
* This function enqueues a command for execution, but returns immediately
|
||||
* without waiting for the response.
|
||||
*
|
||||
* \param control Control object for the channel to send the command to.
|
||||
* \param command Command function to execute.
|
||||
* \param data Optional data to pass along with the control function.
|
||||
* \return 0 on success.
|
||||
* \return Non-zero on error.
|
||||
*/
|
||||
int stasis_app_send_command_async(struct stasis_app_control *control,
|
||||
stasis_app_command_cb command, void *data);
|
||||
|
||||
#endif /* _ASTERISK_RES_STASIS_H */
|
||||
Reference in New Issue
Block a user