[asterisk-commits] mnicholson: branch irroot/t38gateway-trunk r324483 - /team/irroot/t38gateway-...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jun 22 13:48:59 CDT 2011
Author: mnicholson
Date: Wed Jun 22 13:48:55 2011
New Revision: 324483
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=324483
Log:
make the gateway reserve a fax session when it is attached to a channel
Modified:
team/irroot/t38gateway-trunk/res/res_fax.c
Modified: team/irroot/t38gateway-trunk/res/res_fax.c
URL: http://svnview.digium.com/svn/asterisk/team/irroot/t38gateway-trunk/res/res_fax.c?view=diff&rev=324483&r1=324482&r2=324483
==============================================================================
--- team/irroot/t38gateway-trunk/res/res_fax.c (original)
+++ team/irroot/t38gateway-trunk/res/res_fax.c Wed Jun 22 13:48:55 2011
@@ -254,6 +254,8 @@
struct fax_gateway {
/*! FAX Session*/
struct ast_fax_session *s;
+ /*! reserved fax session token */
+ struct ast_fax_tech_token *token;
/*! DSP Processor*/
struct ast_dsp *chan_dsp;
struct ast_dsp *peer_dsp;
@@ -2306,13 +2308,20 @@
ast_dsp_free(gateway->peer_dsp);
gateway->peer_dsp = NULL;
}
+
+ if (gateway->s) {
+ fax_session_release(gateway->s, gateway->token);
+ ao2_ref(gateway->s, -1);
+ gateway->s = NULL;
+ gateway->token = NULL;
+ }
}
/*! \brief returns a reference counted gateway structure from the channel's fax gateway datastore.
* \param chan channel to look for the datastore
* \param create flag if set the datastore will be created if not found
* \return fax gateway object or null if it does not exist or cant be created depending on create.*/
-static struct fax_gateway *fax_gateway_new(void)
+static struct fax_gateway *fax_gateway_new(struct ast_fax_session_details *details)
{
struct fax_gateway *gateway = ao2_alloc(sizeof(*gateway), destroy_gateway);
if (!gateway) {
@@ -2338,6 +2347,13 @@
ast_dsp_set_features(gateway->peer_dsp, DSP_FEATURE_FAX_DETECT);
ast_dsp_set_faxmode(gateway->peer_dsp, DSP_FAXMODE_DETECT_CED);
+
+ details->caps = AST_FAX_TECH_GATEWAY;
+ if (!(gateway->s = fax_session_reserve(details, &gateway->token))) {
+ ast_log(LOG_ERROR, "Can't reserve a FAX session, gateway attempt failed.\n");
+ ao2_ref(gateway, -1);
+ return NULL;
+ }
return gateway;
}
@@ -2354,12 +2370,13 @@
}
/* create the FAX session */
- details->caps = AST_FAX_TECH_GATEWAY;
- if (!(gateway->s = fax_session_new(details, chan, NULL, NULL))) {
+ if (!(gateway->s = fax_session_new(details, chan, gateway->s, gateway->token))) {
+ gateway->token = NULL;
ast_log(LOG_ERROR, "Can't create a FAX session, gateway attempt failed.\n");
report_fax_status(chan, details, "No Available Resource");
return -1;
}
+ gateway->token = NULL;
if (gateway->s->tech->start_session(gateway->s) < 0) {
ao2_ref(gateway->s, -1);
@@ -2624,7 +2641,6 @@
ao2_lock(faxregistry.container);
ao2_unlink(faxregistry.container, gateway->s);
ao2_unlock(faxregistry.container);
- ao2_ref(gateway->s, -1);
}
ao2_ref(gateway, -1);
@@ -2764,7 +2780,7 @@
/*! \brief Attach a gateway framehook object to a channel.
* \param chan the channel to attach to
*/
-static int fax_gateway_attach(struct ast_channel *chan)
+static int fax_gateway_attach(struct ast_channel *chan, struct ast_fax_session_details *details)
{
struct fax_gateway *gateway;
struct ast_framehook_interface fr_hook = {
@@ -2774,8 +2790,9 @@
};
/* set up the frame hook*/
- gateway = fax_gateway_new();
+ gateway = fax_gateway_new(details);
if (!gateway) {
+ report_fax_status(chan, details, "No Available Resource");
return -1;
}
@@ -3371,7 +3388,7 @@
const char *val = ast_skip_blanks(value);
if (ast_true(val)) {
if (details->gateway_id < 0) {
- details->gateway_id = fax_gateway_attach(chan);
+ details->gateway_id = fax_gateway_attach(chan, details);
if (details->gateway_id < 0) {
ast_log(LOG_ERROR, "Error attaching T.38 gateway to channel %s.\n", chan->name);
res = -1;
More information about the asterisk-commits
mailing list