[asterisk-commits] file: branch file/originate_dial r387095 - in /team/file/originate_dial: incl...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 1 07:08:32 CDT 2013


Author: file
Date: Wed May  1 07:08:27 2013
New Revision: 387095

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387095
Log:
Apply some more of the arguments provided to ast_pbx_outgoing_*

Modified:
    team/file/originate_dial/include/asterisk/dial.h
    team/file/originate_dial/main/dial.c
    team/file/originate_dial/main/pbx.c

Modified: team/file/originate_dial/include/asterisk/dial.h
URL: http://svnview.digium.com/svn/asterisk/team/file/originate_dial/include/asterisk/dial.h?view=diff&rev=387095&r1=387094&r2=387095
==============================================================================
--- team/file/originate_dial/include/asterisk/dial.h (original)
+++ team/file/originate_dial/include/asterisk/dial.h Wed May  1 07:08:27 2013
@@ -32,6 +32,9 @@
 
 /*! \brief Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more! */
 struct ast_dial_channel;
+
+/*! \brief Forward declaration for format capabilities, used in prerun */
+struct ast_format_cap;
 
 typedef void (*ast_dial_state_callback)(struct ast_dial *);
 
@@ -70,6 +73,15 @@
  */
 int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device);
 
+/*! \brief Request all appended channels, but do not dial
+ * \param dial Dialing structure
+ * \param chan Optional dialing channel
+ * \param cap Optional requested capabilities
+ * \retval -1 failure
+ * \reval 0 success
+ */
+int ast_dial_prerun(struct ast_dial *dial, struct ast_channel *chan, struct ast_format_cap *cap);
+
 /*! \brief Execute dialing synchronously or asynchronously
  * \note Dials channels in a dial structure.
  * \return Returns dial result code. (TRYING/INVALID/FAILED/ANSWERED/TIMEOUT/UNANSWERED).
@@ -152,6 +164,13 @@
  */
 int ast_dial_reason(struct ast_dial *dial, int num);
 
+/*! \brief Get the dialing channel, if prerun has been executed
+ * \param dial Dial structure
+ * \param num Channel number to get channel of
+ * \return Pointer to channel, without reference
+ */
+struct ast_channel *ast_dial_channel(struct ast_dial *dial, int num);
+
 /*! \brief Set a callback for state changes
  * \param dial The dial structure to watch for state changes
  * \param callback the callback

Modified: team/file/originate_dial/main/dial.c
URL: http://svnview.digium.com/svn/asterisk/team/file/originate_dial/main/dial.c?view=diff&rev=387095&r1=387094&r2=387095
==============================================================================
--- team/file/originate_dial/main/dial.c (original)
+++ team/file/originate_dial/main/dial.c Wed May  1 07:08:27 2013
@@ -258,18 +258,19 @@
 	return channel->num;
 }
 
-/*! \brief Helper function that does the beginning dialing per-appended channel */
-static int begin_dial_channel(struct ast_dial_channel *channel, struct ast_channel *chan)
+/*! \brief Helper function that requests all channels */
+static int begin_dial_prerun(struct ast_dial_channel *channel, struct ast_channel *chan, struct ast_format_cap *cap)
 {
 	char numsubst[AST_MAX_EXTENSION];
-	int res = 1;
 	struct ast_format_cap *cap_all_audio = NULL;
 	struct ast_format_cap *cap_request;
 
 	/* Copy device string over */
 	ast_copy_string(numsubst, channel->device, sizeof(numsubst));
 
-	if (chan) {
+	if (!ast_format_cap_is_empty(cap)) {
+		cap_request = cap;
+	} else if (chan) {
 		cap_request = ast_channel_nativeformats(chan);
 	} else {
 		cap_all_audio = ast_format_cap_alloc_nolock();
@@ -309,6 +310,39 @@
 		ast_channel_adsicpe_set(channel->owner, ast_channel_adsicpe(chan));
 		ast_channel_transfercapability_set(channel->owner, ast_channel_transfercapability(chan));
 	}
+
+	return 0;
+}
+
+int ast_dial_prerun(struct ast_dial *dial, struct ast_channel *chan, struct ast_format_cap *cap)
+{
+	struct ast_dial_channel *channel = NULL;
+	int res = -1;
+
+	AST_LIST_LOCK(&dial->channels);
+	AST_LIST_TRAVERSE(&dial->channels, channel, list) {
+		if ((res = begin_dial_prerun(channel, chan, cap))) {
+			break;
+		}
+	}
+	AST_LIST_UNLOCK(&dial->channels);
+
+	return res;
+}
+
+/*! \brief Helper function that does the beginning dialing per-appended channel */
+static int begin_dial_channel(struct ast_dial_channel *channel, struct ast_channel *chan)
+{
+	char numsubst[AST_MAX_EXTENSION];
+	int res = 1;
+
+	/* If no owner channel exists yet execute pre-run */
+	if (!channel->owner && begin_dial_prerun(channel, chan, NULL)) {
+		return 0;
+	}
+
+	/* Copy device string over */
+	ast_copy_string(numsubst, channel->device, sizeof(numsubst));
 
 	/* Attempt to actually call this device */
 	if ((res = ast_call(channel->owner, numsubst, 0))) {
@@ -1117,6 +1151,17 @@
 	return channel->cause;
 }
 
+struct ast_channel *ast_dial_channel(struct ast_dial *dial, int num)
+{
+	struct ast_dial_channel *channel;
+
+	if (!dial || AST_LIST_EMPTY(&dial->channels) | !(channel = find_dial_channel(dial, num))) {
+		return NULL;
+	}
+
+	return channel->owner;
+}
+
 void ast_dial_set_state_callback(struct ast_dial *dial, ast_dial_state_callback callback)
 {
 	dial->state_callback = callback;

Modified: team/file/originate_dial/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/team/file/originate_dial/main/pbx.c?view=diff&rev=387095&r1=387094&r2=387095
==============================================================================
--- team/file/originate_dial/main/pbx.c (original)
+++ team/file/originate_dial/main/pbx.c Wed May  1 07:08:27 2013
@@ -10023,6 +10023,7 @@
 int ast_pbx_outgoing_exten(const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *context, const char *exten, int priority, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **channel, int early_media)
 {
 	RAII_VAR(struct pbx_outgoing *, outgoing, ao2_alloc(sizeof(*outgoing), pbx_outgoing_destroy), ao2_cleanup);
+	struct ast_channel *dialed;
 	pthread_t thread;
 
 	if (!outgoing) {
@@ -10042,6 +10043,18 @@
 	}
 
 	ast_dial_set_global_timeout(outgoing->dial, timeout);
+
+	if (ast_dial_prerun(outgoing->dial, NULL, cap)) {
+		return -1;
+	}
+
+	dialed = ast_dial_channel(outgoing->dial, 0);
+
+	ast_set_variables(dialed, vars);
+
+	if (account) {
+		ast_cdr_setaccount(dialed, account);
+	}
 
 	ast_mutex_init(&outgoing->lock);
 	ast_cond_init(&outgoing->cond, NULL);
@@ -10109,6 +10122,7 @@
 int ast_pbx_outgoing_app(const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *app, const char *appdata, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel)
 {
 	RAII_VAR(struct pbx_outgoing *, outgoing, ao2_alloc(sizeof(*outgoing), pbx_outgoing_destroy), ao2_cleanup);
+	struct ast_channel *dialed;
 	pthread_t thread;
 
 	if (ast_strlen_zero(app) || !outgoing) {
@@ -10127,6 +10141,18 @@
 	}
 
 	ast_dial_set_global_timeout(outgoing->dial, timeout);
+
+	if (ast_dial_prerun(outgoing->dial, NULL, cap)) {
+		return -1;
+	}
+
+	dialed = ast_dial_channel(outgoing->dial, 0);
+
+	ast_set_variables(dialed, vars);
+
+	if (account) {
+		ast_cdr_setaccount(dialed, account);
+	}
 
 	ast_mutex_init(&outgoing->lock);
 	ast_cond_init(&outgoing->cond, NULL);




More information about the asterisk-commits mailing list