mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-02 20:08:17 +00:00
res_aeap & res_speech_aeap: Add Asterisk External Application Protocol
Add framework to connect to, and read and write protocol based messages from and to an external application using an Asterisk External Application Protocol (AEAP). This has been divided into several abstractions: 1. transport - base communication layer (currently websocket only) 2. message - AEAP description and data (currently JSON only) 3. transaction - links/binds requests and responses 4. aeap - transport, message, and transaction handler/manager This patch also adds an AEAP implementation for speech to text. Existing speech API callbacks for speech to text have been completed making it possible for Asterisk to connect to a configured external translator service and provide audio for STT. Results can also be received from the external translator, and made available as speech results in Asterisk. Unit tests have also been created that test the AEAP framework, and also the speech to text implementation. ASTERISK-29726 #close Change-Id: Iaa4b259f84aa63501e5fd2a6fb107f900b4d4ed2
This commit is contained in:
committed by
Friendly Automation
parent
53a3af6321
commit
272bac70dd
370
include/asterisk/res_aeap.h
Normal file
370
include/asterisk/res_aeap.h
Normal file
@@ -0,0 +1,370 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2021, Sangoma Technologies Corporation
|
||||
*
|
||||
* Kevin Harwell <kharwell@sangoma.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.
|
||||
*/
|
||||
|
||||
/*! \file
|
||||
* \brief Asterisk External Application Protocol API
|
||||
*/
|
||||
|
||||
#ifndef AST_RES_AEAP_H
|
||||
#define AST_RES_AEAP_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct ao2_container;
|
||||
struct ast_sorcery;
|
||||
struct ast_variable;
|
||||
|
||||
struct ast_aeap_client_config;
|
||||
struct ast_aeap_message;
|
||||
|
||||
#define AEAP_CONFIG_CLIENT "client"
|
||||
|
||||
/*!
|
||||
* \brief Retrieve the AEAP sorcery object
|
||||
*
|
||||
* \returns the AEAP sorcery object
|
||||
*/
|
||||
struct ast_sorcery *ast_aeap_sorcery(void);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve a listing of all client configuration objects by protocol.
|
||||
*
|
||||
* \note Caller is responsible for the returned container's reference.
|
||||
*
|
||||
* \param protocol An optional protocol to filter on (if NULL returns all client configs)
|
||||
*
|
||||
* \returns A container of client configuration objects
|
||||
*/
|
||||
struct ao2_container *ast_aeap_client_configs_get(const char *protocol);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve codec capabilities from the configuration
|
||||
*
|
||||
* \param config A configuration object
|
||||
*
|
||||
* \returns The configuration's codec capabilities
|
||||
*/
|
||||
const struct ast_format_cap *ast_aeap_client_config_codecs(const struct ast_aeap_client_config *cfg);
|
||||
|
||||
/*!
|
||||
* \brief Check a given protocol against that in an Asterisk external application configuration
|
||||
*
|
||||
* \param config A configuration object
|
||||
* \param protocol The protocol to check
|
||||
*
|
||||
* \returns True if the configuration's protocol matches, false otherwise
|
||||
*/
|
||||
int ast_aeap_client_config_has_protocol(const struct ast_aeap_client_config *cfg,
|
||||
const char *protocol);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve a list of custom configuration fields
|
||||
*
|
||||
* \param id configuration id/sorcery lookup key
|
||||
*
|
||||
* \returns variables, or NULL on error
|
||||
*/
|
||||
struct ast_variable *ast_aeap_custom_fields_get(const char *id);
|
||||
|
||||
/*!
|
||||
* \brief An Asterisk external application object
|
||||
*
|
||||
* Connects to an external application, sending and receiving data, and
|
||||
* dispatches received data to registered handlers.
|
||||
*/
|
||||
struct ast_aeap;
|
||||
|
||||
/*!
|
||||
* \brief Event raised when a message is received
|
||||
*
|
||||
* \param aeap An Asterisk external application object
|
||||
* \param message The received message
|
||||
* \param obj Associated user object
|
||||
*
|
||||
* \returns 0 on if message handled, otherwise non-zero
|
||||
*/
|
||||
typedef int (*ast_aeap_on_message)(struct ast_aeap *aeap, struct ast_aeap_message *message, void *obj);
|
||||
|
||||
/*!
|
||||
* \brief An Asterisk external application message handler
|
||||
*
|
||||
* Used to register message handlers with an AEAP object.
|
||||
*/
|
||||
struct ast_aeap_message_handler {
|
||||
/*! The handler name */
|
||||
const char *name;
|
||||
/*! Callback triggered when on a name match */
|
||||
ast_aeap_on_message on_message;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Event raised when a sent message does not receive a reply within
|
||||
* a specified time interval
|
||||
*
|
||||
* \param aeap An Asterisk external application object
|
||||
* \param message The message sent that received no response
|
||||
* \param obj Associated user object
|
||||
*/
|
||||
typedef void (*ast_aeap_on_timeout)(struct ast_aeap *aeap, struct ast_aeap_message *message, void *obj);
|
||||
|
||||
/*!
|
||||
* \brief Callback to cleanup a user object
|
||||
*
|
||||
* \param obj The user object
|
||||
*/
|
||||
typedef void (*ast_aeap_user_obj_cleanup)(void *obj);
|
||||
|
||||
/*!
|
||||
* \brief Supported Asterisk external application data types
|
||||
*/
|
||||
enum AST_AEAP_DATA_TYPE {
|
||||
AST_AEAP_DATA_TYPE_NONE,
|
||||
AST_AEAP_DATA_TYPE_BINARY,
|
||||
AST_AEAP_DATA_TYPE_STRING,
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Callbacks and other parameters used by an Asterisk external application object
|
||||
*/
|
||||
struct ast_aeap_params {
|
||||
/*!
|
||||
* If true pass along error messages to the implementation.
|
||||
* Otherwise log it only, and consider it handled.
|
||||
*/
|
||||
unsigned int emit_error;
|
||||
|
||||
/*! The message type used for communication */
|
||||
const struct ast_aeap_message_type *msg_type;
|
||||
|
||||
/*! Response handlers array */
|
||||
const struct ast_aeap_message_handler *response_handlers;
|
||||
/*! The number of response handlers */
|
||||
uintmax_t response_handlers_size;
|
||||
|
||||
/*! Request handlers array */
|
||||
const struct ast_aeap_message_handler *request_handlers;
|
||||
/*! The number of request handlers */
|
||||
uintmax_t request_handlers_size;
|
||||
|
||||
/*!
|
||||
* \brief Raised when binary data is received
|
||||
*
|
||||
* \param aeap An Asterisk external application object
|
||||
* \param buf The buffer containing binary data
|
||||
* \param size The size of the buffer
|
||||
*/
|
||||
void (*on_binary)(struct ast_aeap *aeap, const void *buf, intmax_t size);
|
||||
|
||||
/*!
|
||||
* \brief Raised when string data is received
|
||||
*
|
||||
* \param aeap An Asterisk external application object
|
||||
* \param buf The buffer containing string data
|
||||
* \param size The size/length of the string
|
||||
*/
|
||||
void (*on_string)(struct ast_aeap *aeap, const char *buf, intmax_t size);
|
||||
|
||||
/*!
|
||||
* \brief Raised when an error occurs during reading
|
||||
*
|
||||
* \note This is an AEAP transport level read error event
|
||||
*
|
||||
* \note When this event is triggered the client has also
|
||||
* been disconnected.
|
||||
*
|
||||
* \param aeap An Asterisk external application object
|
||||
*/
|
||||
void (*on_error)(struct ast_aeap *aeap);
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Create an Asterisk external application object
|
||||
*
|
||||
* \param type The type of underlying transport
|
||||
* \param params Callbacks and other parameters to use
|
||||
*
|
||||
* \returns A new ao2 reference counted aeap object, or NULL on error
|
||||
*/
|
||||
struct ast_aeap *ast_aeap_create(const char *type, const struct ast_aeap_params *params);
|
||||
|
||||
/*!
|
||||
* \brief Create an Asterisk external application object by sorcery id
|
||||
*
|
||||
* \param id The sorcery id to lookup
|
||||
* \param params Callbacks and other parameters to use
|
||||
*
|
||||
* \returns A new ao2 reference counted aeap object, or NULL on error
|
||||
*/
|
||||
struct ast_aeap *ast_aeap_create_by_id(const char *id, const struct ast_aeap_params *params);
|
||||
|
||||
/*!
|
||||
* \brief Connect to an external application
|
||||
*
|
||||
* \param aeap An Asterisk external application object
|
||||
* \param url The url to connect to
|
||||
* \param protocol A protocol to use
|
||||
* \param timeout How long (in milliseconds) to attempt to connect (-1 equals infinite)
|
||||
*
|
||||
* \returns 0 if able to connect, -1 on error
|
||||
*/
|
||||
int ast_aeap_connect(struct ast_aeap *aeap, const char *url, const char *protocol, int timeout);
|
||||
|
||||
/*!
|
||||
* \brief Create and connect to an Asterisk external application by sorcery id
|
||||
*
|
||||
* \param id The sorcery id to lookup
|
||||
* \param params Callbacks and other parameters to use
|
||||
* \param timeout How long (in milliseconds) to attempt to connect (-1 equals infinite)
|
||||
*
|
||||
* \returns A new ao2 reference counted aeap object, or NULL on error
|
||||
*/
|
||||
struct ast_aeap *ast_aeap_create_and_connect_by_id(const char *id,
|
||||
const struct ast_aeap_params *params, int timeout);
|
||||
|
||||
/*!
|
||||
* \brief Create and connect to an Asterisk external application
|
||||
*
|
||||
* \param type The type of client connection to make
|
||||
* \param params Callbacks and other parameters to use
|
||||
* \param url The url to connect to
|
||||
* \param protocol A protocol to use
|
||||
* \param timeout How long (in milliseconds) to attempt to connect (-1 equals infinite)
|
||||
*
|
||||
* \returns A new ao2 reference counted aeap object, or NULL on error
|
||||
*/
|
||||
struct ast_aeap *ast_aeap_create_and_connect(const char *type,
|
||||
const struct ast_aeap_params *params, const char *url, const char *protocol, int timeout);
|
||||
|
||||
/*!
|
||||
* \brief Disconnect an Asterisk external application object
|
||||
*
|
||||
* \note Depending on the underlying transport this call may block
|
||||
*
|
||||
* \param aeap An Asterisk external application object
|
||||
*
|
||||
* \returns 0 on success, -1 on error
|
||||
*/
|
||||
int ast_aeap_disconnect(struct ast_aeap *aeap);
|
||||
|
||||
/*!
|
||||
* \brief Register a user data object
|
||||
*
|
||||
* \note The "cleanup" is called on un-register, if one is specified
|
||||
*
|
||||
* \param aeap An Asterisk external application object
|
||||
* \param id The look up id for the object
|
||||
* \param obj The user object to register
|
||||
* \param cleanup Optional user object clean up callback
|
||||
*
|
||||
* \returns 0 on success, -1 on error
|
||||
*/
|
||||
int ast_aeap_user_data_register(struct ast_aeap *aeap, const char *id, void *obj,
|
||||
ast_aeap_user_obj_cleanup cleanup);
|
||||
|
||||
/*!
|
||||
* \brief Un-register a user data object
|
||||
*
|
||||
* \note If specified on register, the "cleanup" callback is called during unregister.
|
||||
*
|
||||
* \param aeap An Asterisk external application object
|
||||
* \param id The look up id for the object
|
||||
*/
|
||||
void ast_aeap_user_data_unregister(struct ast_aeap *aeap, const char *id);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve a registered user data object by its id
|
||||
*
|
||||
* \note Depending on how it was registered the returned user data object's lifetime
|
||||
* may be managed by the given "aeap" object. If it was registered with a cleanup
|
||||
* handler that [potentially] frees it the caller of this function must ensure
|
||||
* it's done using the returned object before it's unregistered.
|
||||
*
|
||||
* \param data A user data object
|
||||
*
|
||||
* \returns A user data object
|
||||
*/
|
||||
void *ast_aeap_user_data_object_by_id(struct ast_aeap *aeap, const char *id);
|
||||
|
||||
/*!
|
||||
* \brief Send a binary data to an external application
|
||||
*
|
||||
* \param aeap An Asterisk external application object
|
||||
* \param buf Binary data to send
|
||||
* \param size The size of the binary data
|
||||
*
|
||||
* \returns 0 on success, -1 on error
|
||||
*/
|
||||
int ast_aeap_send_binary(struct ast_aeap *aeap, const void *buf, uintmax_t size);
|
||||
|
||||
/*!
|
||||
* \brief Send a message to an external application
|
||||
*
|
||||
* \note "Steals" the given message reference, thus callers are not required to un-ref
|
||||
* the message object after calling this function.
|
||||
*
|
||||
* \param aeap An Asterisk external application object
|
||||
* \param msg The message to send
|
||||
*
|
||||
* \returns 0 on success, -1 on error
|
||||
*/
|
||||
int ast_aeap_send_msg(struct ast_aeap *aeap, struct ast_aeap_message *msg);
|
||||
|
||||
/*!
|
||||
* \brief Parameters to be used when sending a transaction based message
|
||||
*/
|
||||
struct ast_aeap_tsx_params {
|
||||
/*! The message to send */
|
||||
struct ast_aeap_message *msg;
|
||||
/*! The amount of time (in milliseconds) to wait for a received message */
|
||||
int timeout;
|
||||
/*! Optional callback raised when no message is received in an allotted time */
|
||||
ast_aeap_on_timeout on_timeout;
|
||||
/*! Whether or not to block the current thread, and wait for a received message */
|
||||
int wait;
|
||||
/*!
|
||||
* Optional user object to pass to handlers. User is responsible for object's lifetime
|
||||
* unless an obj_cleanup callback is specified that handles its cleanup (e.g. freeing
|
||||
* of memory).
|
||||
*/
|
||||
void *obj;
|
||||
/*!
|
||||
* Optional user object cleanup callback. If specified, called upon "this" param's
|
||||
* destruction (including on error).
|
||||
*/
|
||||
ast_aeap_user_obj_cleanup obj_cleanup;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Send a transaction based message to an external application using the given parameters
|
||||
*
|
||||
* \note "Steals" the given message reference, thus callers are not required to un-ref
|
||||
* the message object after calling this function.
|
||||
*
|
||||
* \note Also handles cleaning up the user object if the obj_cleanup callback
|
||||
* is specified in "params".
|
||||
*
|
||||
* \param aeap An Asterisk external application object
|
||||
* \param msg The message to send
|
||||
* \param params (optional) Additional parameters to consider when sending. Heap allocation
|
||||
* not required.
|
||||
*
|
||||
* \returns 0 on success, -1 on error
|
||||
*/
|
||||
int ast_aeap_send_msg_tsx(struct ast_aeap *aeap, struct ast_aeap_tsx_params *params);
|
||||
|
||||
#endif /* AST_RES_AEAP_H */
|
||||
374
include/asterisk/res_aeap_message.h
Normal file
374
include/asterisk/res_aeap_message.h
Normal file
@@ -0,0 +1,374 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2021, Sangoma Technologies Corporation
|
||||
*
|
||||
* Kevin Harwell <kharwell@sangoma.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.
|
||||
*/
|
||||
|
||||
/*! \file
|
||||
* \brief Asterisk External Application Protocol Message API
|
||||
*/
|
||||
|
||||
#ifndef AST_AEAP_MESSAGE_H
|
||||
#define AST_AEAP_MESSAGE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "asterisk/res_aeap.h"
|
||||
|
||||
struct ast_aeap_message;
|
||||
|
||||
/*!
|
||||
* \brief Message type virtual method table
|
||||
*/
|
||||
struct ast_aeap_message_type {
|
||||
/*! The size of the message implementation type. Used for allocations. */
|
||||
size_t type_size;
|
||||
/*! The name of this type */
|
||||
const char *type_name;
|
||||
/*! The type to serialize to, and de-serialize from */
|
||||
enum AST_AEAP_DATA_TYPE serial_type;
|
||||
|
||||
/*!
|
||||
* \brief Construct/Initialize a message object
|
||||
*
|
||||
* \param self The message object to initialize
|
||||
* \param params Other optional parameter(s) to possibly use
|
||||
*
|
||||
* \returns 0 on success, -1 on error
|
||||
*/
|
||||
int (*construct1)(struct ast_aeap_message *self, const void *params);
|
||||
|
||||
/*!
|
||||
* \brief Construct/Initialize a message object
|
||||
*
|
||||
* \param self The message object to initialize
|
||||
* \param msg_type The type of message (e.g. request or response)
|
||||
* \param name The name of the message
|
||||
* \param id The message id
|
||||
* \param params Other optional parameter(s) to possibly use
|
||||
*
|
||||
* \returns 0 on success, -1 on error
|
||||
*/
|
||||
int (*construct2)(struct ast_aeap_message *self, const char *msg_type, const char *name,
|
||||
const char *id, const void *params);
|
||||
|
||||
/*!
|
||||
* \brief Destruct/Cleanup object resources
|
||||
*
|
||||
* \param self The message object being destructed
|
||||
*/
|
||||
void (*destruct)(struct ast_aeap_message *self);
|
||||
|
||||
/*!
|
||||
* \brief Deserialize the given buffer into a message object
|
||||
*
|
||||
* \param self The message object to deserialize into
|
||||
* \param buf The buffer to deserialize
|
||||
* \param size The size/length of the buffer
|
||||
*
|
||||
* \returns 0 on success, -1 on error
|
||||
*/
|
||||
int (*deserialize)(struct ast_aeap_message *self, const void *buf, intmax_t size);
|
||||
|
||||
/*!
|
||||
* \brief Serialize the message object into byte/char buffer
|
||||
*
|
||||
* \param self The message object to serialize
|
||||
* \param buf [out] The buffer to hold the "packed" data
|
||||
* \param size [out] The size of the data written to the buffer
|
||||
*
|
||||
* \returns 0 on success, -1 on error
|
||||
*/
|
||||
int (*serialize)(const struct ast_aeap_message *self, void **buf, intmax_t *size);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve a message id
|
||||
*
|
||||
* \param self The message object
|
||||
*
|
||||
* \returns The message id
|
||||
*/
|
||||
const char *(*id)(const struct ast_aeap_message *self);
|
||||
|
||||
/*!
|
||||
* \brief Set a message id.
|
||||
*
|
||||
* \param self The message object
|
||||
* \param id The id to set
|
||||
*
|
||||
* \returns 0 on success, -1 on error
|
||||
*/
|
||||
int (*id_set)(struct ast_aeap_message *self, const char *id);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve a message name
|
||||
*
|
||||
* \param self The message object
|
||||
*
|
||||
* \returns The message name
|
||||
*/
|
||||
const char *(*name)(const struct ast_aeap_message *self);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve the core message data/body
|
||||
*
|
||||
* \param self This message object
|
||||
*/
|
||||
void *(*data)(struct ast_aeap_message *self);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve whether or not this is a request message
|
||||
*
|
||||
* \param self The message object
|
||||
*
|
||||
* \returns True if message is a request, false otherwise
|
||||
*/
|
||||
int (*is_request)(const struct ast_aeap_message *self);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve whether or not this is a response message
|
||||
*
|
||||
* \param self The message object
|
||||
*
|
||||
* \returns True if message is a response, false otherwise
|
||||
*/
|
||||
int (*is_response)(const struct ast_aeap_message *self);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve the error message if it has one
|
||||
*
|
||||
* \param self The message object
|
||||
*
|
||||
* \returns The error message if available, or NULL
|
||||
*/
|
||||
const char *(*error_msg)(const struct ast_aeap_message *self);
|
||||
|
||||
/*!
|
||||
* \brief Set an error message
|
||||
*
|
||||
* \param self The message object
|
||||
* \param error_msg The error message string to set
|
||||
*
|
||||
* \returns 0 on success, -1 on error
|
||||
*/
|
||||
int (*error_msg_set)(struct ast_aeap_message *self, const char *error_msg);
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Asterisk external application base message
|
||||
*/
|
||||
struct ast_aeap_message {
|
||||
/*! The type virtual table */
|
||||
const struct ast_aeap_message_type *type;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Retrieve the serial type a message type
|
||||
*
|
||||
* \param type A message type
|
||||
*
|
||||
* \returns The type's serial type
|
||||
*/
|
||||
enum AST_AEAP_DATA_TYPE ast_aeap_message_serial_type(const struct ast_aeap_message_type *type);
|
||||
|
||||
/*!
|
||||
* \brief Create an Asterisk external application message object
|
||||
*
|
||||
* \param type The type of message object to create
|
||||
* \param params Any parameter(s) to pass to the type's constructor
|
||||
*
|
||||
* \returns An ao2 reference counted AEAP message object, or NULL on error
|
||||
*/
|
||||
struct ast_aeap_message *ast_aeap_message_create1(const struct ast_aeap_message_type *type,
|
||||
const void *params);
|
||||
|
||||
/*!
|
||||
* \brief Create an Asterisk external application message object
|
||||
*
|
||||
* \param type The type of message object to create
|
||||
* \param msg_type The type of message (e.g. request or response)
|
||||
* \param name The name of the message
|
||||
* \param id The message id
|
||||
* \param params Other optional parameter(s) to possibly use
|
||||
*
|
||||
* \returns An ao2 reference counted AEAP message object, or NULL on error
|
||||
*/
|
||||
struct ast_aeap_message *ast_aeap_message_create2(const struct ast_aeap_message_type *type,
|
||||
const char *msg_type, const char *name, const char *id, const void *params);
|
||||
|
||||
/*!
|
||||
* \brief Create an Asterisk external application request object
|
||||
*
|
||||
* \param type The type of message object to create
|
||||
* \param name The name of the message
|
||||
* \param id Optional id (if NULL an id is generated)
|
||||
* \param params Other optional parameter(s) to possibly use
|
||||
*
|
||||
* \returns An ao2 reference counted AEAP request object, or NULL on error
|
||||
*/
|
||||
struct ast_aeap_message *ast_aeap_message_create_request(const struct ast_aeap_message_type *type,
|
||||
const char *name, const char *id, const void *params);
|
||||
|
||||
/*!
|
||||
* \brief Create an Asterisk external application response object
|
||||
*
|
||||
* \param type The type of message object to create
|
||||
* \param name The name of the message
|
||||
* \param id Optional id
|
||||
* \param params Other optional parameter(s) to possibly use
|
||||
*
|
||||
* \returns An ao2 reference counted AEAP response object, or NULL on error
|
||||
*/
|
||||
struct ast_aeap_message *ast_aeap_message_create_response(const struct ast_aeap_message_type *type,
|
||||
const char *name, const char *id, const void *params);
|
||||
|
||||
/*!
|
||||
* \brief Create an Asterisk external application error response object
|
||||
*
|
||||
* \param type The type of message object to create
|
||||
* \param name The name of the message
|
||||
* \param id Optional id
|
||||
* \param error_msg Error message to set
|
||||
* \param params Other optional parameter(s) to possibly use
|
||||
*
|
||||
* \returns An ao2 reference counted AEAP response object, or NULL on error
|
||||
*/
|
||||
struct ast_aeap_message *ast_aeap_message_create_error(const struct ast_aeap_message_type *type,
|
||||
const char *name, const char *id, const char *error_msg);
|
||||
|
||||
/*!
|
||||
* \brief Deserialize the given buffer into an Asterisk external application message object
|
||||
*
|
||||
* \param type The message type to create, and deserialize to
|
||||
* \param buf The buffer to deserialize
|
||||
* \param size The size/length of the buffer
|
||||
*
|
||||
* \returns An ao2 reference counted AEAP message object, or NULL on error
|
||||
*/
|
||||
struct ast_aeap_message *ast_aeap_message_deserialize(const struct ast_aeap_message_type *type,
|
||||
const void *buf, intmax_t size);
|
||||
|
||||
/*!
|
||||
* \brief Serialize the given message object into a byte/char buffer
|
||||
*
|
||||
* \param message The message object to serialize
|
||||
* \param buf [out] The buffer to hold the "packed" data
|
||||
* \param size [out] The size of the data written to the buffer
|
||||
*
|
||||
* \returns 0 on success, -1 on error
|
||||
*/
|
||||
int ast_aeap_message_serialize(const struct ast_aeap_message *message,
|
||||
void **buf, intmax_t *size);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve a message id
|
||||
*
|
||||
* \param message A message object
|
||||
*
|
||||
* \returns The message id, or an empty string
|
||||
*/
|
||||
const char *ast_aeap_message_id(const struct ast_aeap_message *message);
|
||||
|
||||
/*!
|
||||
* \brief Set a message id.
|
||||
*
|
||||
* \param message A message object
|
||||
* \param id The id to set
|
||||
*
|
||||
* \returns 0 on success, -1 on error
|
||||
*/
|
||||
int ast_aeap_message_id_set(struct ast_aeap_message *message, const char *id);
|
||||
|
||||
/*!
|
||||
* \brief Generate an id, and set it for the message
|
||||
*
|
||||
* \param message A message object
|
||||
*
|
||||
* \returns the generated id on success, or NULL on error
|
||||
*/
|
||||
const char *ast_aeap_message_id_generate(struct ast_aeap_message *message);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve a message name
|
||||
*
|
||||
* \param message A message object
|
||||
*
|
||||
* \returns The message name, or an empty string
|
||||
*/
|
||||
const char *ast_aeap_message_name(const struct ast_aeap_message *message);
|
||||
|
||||
/*!
|
||||
* \brief Check whether or not a message's name matches the given one
|
||||
*
|
||||
* \note Case insensitive
|
||||
*
|
||||
* \param message A message object
|
||||
* \param message name The name to check against
|
||||
*
|
||||
* \returns True if matched, false otherwise
|
||||
*/
|
||||
int ast_aeap_message_is_named(const struct ast_aeap_message *message, const char *name);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve the core message data/body
|
||||
*
|
||||
* \param message A message object
|
||||
*/
|
||||
void *ast_aeap_message_data(struct ast_aeap_message *message);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve whether or not this is a request message
|
||||
*
|
||||
* \param message A message object
|
||||
*
|
||||
* \returns True if the message is a request, false otherwise
|
||||
*/
|
||||
int ast_aeap_message_is_request(const struct ast_aeap_message *message);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve whether or not this is a response message
|
||||
*
|
||||
* \param message A message object
|
||||
*
|
||||
* \returns True if the message is a response, false otherwise
|
||||
*/
|
||||
int ast_aeap_message_is_response(const struct ast_aeap_message *message);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve the error message if it has one
|
||||
*
|
||||
* \param message A message object
|
||||
*
|
||||
* \returns The error message if available, or NULL
|
||||
*/
|
||||
const char *ast_aeap_message_error_msg(const struct ast_aeap_message *message);
|
||||
|
||||
/*!
|
||||
* \brief Set an error message.
|
||||
*
|
||||
* \param message A message object
|
||||
* \param error_msg The error string to set
|
||||
*
|
||||
* \returns 0 on success, -1 on error
|
||||
*/
|
||||
int ast_aeap_message_error_msg_set(struct ast_aeap_message *message,
|
||||
const char *error_msg);
|
||||
|
||||
/*!
|
||||
* \brief Asterisk external application JSON message type
|
||||
*/
|
||||
extern const struct ast_aeap_message_type *ast_aeap_message_type_json;
|
||||
|
||||
#endif /* AST_AEAP_MESSAGE_H */
|
||||
@@ -158,6 +158,12 @@ int ast_speech_unregister(const char *engine_name);
|
||||
/*! \brief Unregister a speech recognition engine */
|
||||
struct ast_speech_engine *ast_speech_unregister2(const char *engine_name);
|
||||
|
||||
/*! \brief Retrieve a speech recognition engine */
|
||||
struct ast_speech_engine *ast_speech_find_engine(const char *engine_name);
|
||||
/*! \brief Unregister all speech recognition engines told to by callback */
|
||||
void ast_speech_unregister_engines(
|
||||
int (*should_unregister)(const struct ast_speech_engine *engine, void *data), void *data,
|
||||
void (*on_unregistered)(void *obj));
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user