[asterisk-commits] file: branch file/dialing_api r49213 - in
/team/file/dialing_api: include/ast...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Jan 2 12:58:47 MST 2007
Author: file
Date: Tue Jan 2 13:58:47 2007
New Revision: 49213
URL: http://svn.digium.com/view/asterisk?view=rev&rev=49213
Log:
Add what I have hashed out so far for the dialing API. Structures are not directly accessible outside of the API, you have to use the API functions to manipulate them. This shouldn't be bad though as there isn't too much you need to manipulate. Here is how I picture it working: You create a dial structure. You can then enable/disable options on a global scale. You can then append channels to be dialed to the dial structure. As you append them you get back a reference number that can then be used to enable/disable options on a per channel basis. After all that you can then run the dial structure in an async or regular sync state. Options themselves are abstracted out in the dialing API so it will be easy to add new ones.
Modified:
team/file/dialing_api/include/asterisk/dial.h
team/file/dialing_api/main/dial.c
Modified: team/file/dialing_api/include/asterisk/dial.h
URL: http://svn.digium.com/view/asterisk/team/file/dialing_api/include/asterisk/dial.h?view=diff&rev=49213&r1=49212&r2=49213
==============================================================================
--- team/file/dialing_api/include/asterisk/dial.h (original)
+++ team/file/dialing_api/include/asterisk/dial.h Tue Jan 2 13:58:47 2007
@@ -27,6 +27,64 @@
extern "C" {
#endif
+/*! \brief Main dialing structure. Contains global options, channels being dialed, and more! */
+struct ast_dial;
+
+/*! \brief Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more! */
+struct ast_dial_channel;
+
+/*! \brief List of options that are applicable either globally or per dialed channel */
+enum ast_dial_option {
+ AST_DIAL_OPTION_DUMMY = 0, /*! Test option */
+ AST_DIAL_OPTION_MAX, /*! End terminator -- must always remain last */
+};
+
+/*! \brief New dialing structure
+ * \note Create a dialing structure
+ * \return Returns a calloc'd ast_dial structure, NULL on failure
+ */
+struct ast_dial *ast_dial_create(void);
+
+/*! \brief Append a channel
+ * \note Appends a channel to a dialing structure
+ * \return Returns channel reference number on success, -1 on failure
+ */
+int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device);
+
+/*! \brief Execute dialing synchronously
+ * \note Dials channels in a dial structure and does not return until one is answered or timeout is reached. Will also forward progress/ringing.
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_dial_run(struct ast_dial *dial, struct ast_channel *chan, struct ast_channel *answered, int timeout);
+
+/*! \brief Execute dialing asynchronously
+ * \note Dials channels in a dial structure in a separate thread, returns almost immediately
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_dial_run_async(struct ast_dial *dial);
+
+/*! \brief Destroys a dialing structure
+ * \note Cancels dialing and destroys (free's) the given ast_dial structure
+ * \param dial Dialing structure to free
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_dial_destroy(struct ast_dial *dial);
+
+/*! \brief Enables an option globally
+ * \param dial Dial structure to enable option on
+ * \param option Option to enable
+ * \param data Data to pass to this option (not always needed)
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_dial_option_global_enable(struct ast_dial *dial, enum ast_dial_option option, void *data);
+
+/*! \brief Disables an option globally
+ * \param dial Dial structure to disable option on
+ * \param option Option to disable
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_dial_option_global_disable(struct ast_dial *dial, enum ast_dial_option option);
+
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
Modified: team/file/dialing_api/main/dial.c
URL: http://svn.digium.com/view/asterisk/team/file/dialing_api/main/dial.c?view=diff&rev=49213&r1=49212&r2=49213
==============================================================================
--- team/file/dialing_api/main/dial.c (original)
+++ team/file/dialing_api/main/dial.c Tue Jan 2 13:58:47 2007
@@ -42,3 +42,163 @@
#include "asterisk/lock.h"
#include "asterisk/linkedlists.h"
#include "asterisk/dial.h"
+
+/*! \brief Main dialing structure. Contains global options, channels being dialed, and more! */
+struct ast_dial {
+ int num; /*! Current number to give to next dialed channel */
+ void *options[AST_DIAL_OPTION_MAX]; /*! Global options */
+ AST_LIST_HEAD_NOLOCK(, ast_dial_channel) channels; /*! Channels being dialed */
+};
+
+/*! \brief Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more! */
+struct ast_dial_channel {
+ int num; /*! Unique number for dialed channel */
+ const char *tech; /*! Technology being dialed */
+ const char *device; /*! Device being dialed */
+ void *options[AST_DIAL_OPTION_MAX]; /*! Channel specific options */
+ struct ast_channel *owner; /*! Asterisk channel */
+ AST_LIST_ENTRY(ast_dial_channel) list; /*! Linked list information */
+};
+
+/*! \brief Typedef for dial option enable */
+typedef void *(*ast_dial_option_cb_enable)(void *data);
+
+/*! \brief Typedef for dial option disable */
+typedef int (*ast_dial_option_cb_disable)(void *data);
+
+/*! \brief Options structure - maps options to respective handlers (enable/disable). This list MUST be perfectly kept in order, or else madness will happen. */
+static const struct ast_option_types {
+ enum ast_dial_option option;
+ ast_dial_option_cb_enable enable;
+ ast_dial_option_cb_disable disable;
+} option_types[] = {
+ { AST_DIAL_OPTION_DUMMY, NULL, NULL }, /*! Dummy option for testing */
+ { AST_DIAL_OPTION_MAX, NULL, NULL }, /*! Terminator of list */
+};
+
+
+/*! \brief Macro for finding the option structure to use on a dialed channel */
+#define FIND_RELATIVE_OPTION(dial, dial_channel, ast_dial_option) (dial_channel->options[ast_dial_option] ? dial_channel->options[ast_dial_option] : dial->options[ast_dial_option])
+
+/*! \brief New dialing structure
+ * \note Create a dialing structure
+ * \return Returns a calloc'd ast_dial structure, NULL on failure
+ */
+struct ast_dial *ast_dial_create(void)
+{
+ struct ast_dial *dial = NULL;
+
+ /* Allocate new memory for structure */
+ if (!(dial = ast_calloc(1, sizeof(*dial))))
+ return NULL;
+
+ /* Initialize list of channels */
+ AST_LIST_HEAD_INIT_NOLOCK(&dial->channels);
+
+ return dial;
+}
+
+/*! \brief Append a channel
+ * \note Appends a channel to a dialing structure
+ * \return Returns channel reference number on success, -1 on failure
+ */
+int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device)
+{
+ struct ast_dial_channel *channel = NULL;
+
+ /* Make sure we have required arguments */
+ if (!dial || !tech || !device)
+ return -1;
+
+ /* Allocate new memory for dialed channel structure */
+ if (!(channel = ast_calloc(1, sizeof(*dial))))
+ return -1;
+
+ /* Record technology and device for when we actually dial */
+ channel->tech = tech;
+ channel->device = device;
+
+ /* Grab reference number from dial structure */
+ channel->num = ast_atomic_fetchadd_int(&dial->num, +1);
+
+ /* Insert into channels list */
+ AST_LIST_INSERT_TAIL(&dial->channels, channel, list);
+
+ return channel->num;
+}
+
+/*! \brief Execute dialing synchronously
+ * \note Dials channels in a dial structure and does not return until one is answered or timeout is reached. Will also forward progress/ringing.
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_dial_run(struct ast_dial *dial, struct ast_channel *chan, struct ast_channel *answered, int timeout)
+{
+ return 0;
+}
+
+/*! \brief Execute dialing asynchronously
+ * \note Dials channels in a dial structure in a separate thread, returns almost immediately
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_dial_run_async(struct ast_dial *dial)
+{
+ return 0;
+}
+
+/*! \brief Destroys a dialing structure
+ * \note Destroys (free's) the given ast_dial structure
+ * \param dial Dialing structure to free
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_dial_destroy(struct ast_dial *dial)
+{
+ /* Abort any dialing */
+
+ /* Disable any enabled options globally */
+
+ /* Free structure */
+
+ return 0;
+}
+
+/*! \brief Enables an option globally
+ * \param dial Dial structure to enable option on
+ * \param option Option to enable
+ * \param data Data to pass to this option (not always needed)
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_dial_option_global_enable(struct ast_dial *dial, enum ast_dial_option option, void *data)
+{
+ /* If the option is already enabled, return failure */
+ if (dial->options[option])
+ return -1;
+
+ /* Execute enable callback if it exists, if not simply make sure the value is set */
+ if (option_types[option].enable)
+ dial->options[option] = option_types[option].enable(data);
+ else
+ dial->options[option] = (void*)1;
+
+ return 0;
+}
+
+/*! \brief Disables an option globally
+ * \param dial Dial structure to disable option on
+ * \param option Option to disable
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_dial_option_global_disable(struct ast_dial *dial, enum ast_dial_option option)
+{
+ /* If the option is not enabled, return failure */
+ if (!dial->options[option])
+ return -1;
+
+ /* Execute callback of option to disable if it exists */
+ if (option_types[option].disable)
+ option_types[option].disable(dial->options[option]);
+
+ /* Finally disable option on the structure */
+ dial->options[option] = NULL;
+
+ return 0;
+}
More information about the asterisk-commits
mailing list