- wait for answered line on fax action

This commit is contained in:
MelwareDE 2006-07-08 20:22:15 +00:00
parent d8c24f23e9
commit ca207a4ded
2 changed files with 43 additions and 0 deletions

View File

@ -417,6 +417,31 @@ MESSAGE_EXCHANGE_ERROR _capi_put_cmsg_wait_conf(struct capi_pvt *i, _cmsg *CMSG)
return error;
}
/*
* wait for finishing answering state
*/
static void capi_wait_for_answered(struct capi_pvt *i)
{
struct timespec abstime;
cc_mutex_lock(&i->lock);
if (i->state == CAPI_STATE_ANSWERING) {
i->waitevent = CAPI_WAITEVENT_ANSWER_FINISH;
abstime.tv_sec = time(NULL) + 2;
abstime.tv_nsec = 0;
cc_verbose(4, 1, "%s: wait for finish answer.\n",
i->vname);
if (ast_cond_timedwait(&i->event_trigger, &i->lock, &abstime) != 0) {
cc_log(LOG_WARNING, "%s: timed out waiting for finish answer.\n",
i->vname);
} else {
cc_verbose(4, 1, "%s: cond signal received for finish answer.\n",
i->vname);
}
}
cc_mutex_unlock(&i->lock);
}
/*
* wait some time for a new capi message
*/
@ -2187,6 +2212,8 @@ static int pbx_capi_receive_fax(struct ast_channel *c, char *data)
if (!headline)
headline = emptyid;
capi_wait_for_answered(i);
if ((i->fFax = fopen(filename, "wb")) == NULL) {
cc_log(LOG_WARNING, "can't create fax output file (%s)\n", strerror(errno));
return -1;
@ -2269,6 +2296,8 @@ static int pbx_capi_send_fax(struct ast_channel *c, char *data)
if (!headline)
headline = emptyid;
capi_wait_for_answered(i);
if ((i->fFax = fopen(filename, "rb")) == NULL) {
cc_log(LOG_WARNING, "can't open fax file (%s)\n", strerror(errno));
return -1;
@ -3754,11 +3783,21 @@ static void capidev_post_handling(struct capi_pvt *i, _cmsg *CMSG)
{
unsigned short capicommand = ((CMSG->Subcommand << 8)|(CMSG->Command));
if ((i->waitevent == CAPI_WAITEVENT_ANSWER_FINISH) &&
(i->state != CAPI_STATE_ANSWERING)) {
i->waitevent = 0;
ast_cond_signal(&i->event_trigger);
cc_verbose(4, 1, "%s: found and signal for finished ANSWER state.\n",
i->vname);
return;
}
if (i->waitevent == capicommand) {
i->waitevent = 0;
ast_cond_signal(&i->event_trigger);
cc_verbose(4, 1, "%s: found and signal for %s\n",
i->vname, capi_cmd2str(CMSG->Command, CMSG->Subcommand));
return;
}
}

View File

@ -221,6 +221,10 @@ struct cc_capi_gains {
#define CAPI_CHANNELTYPE_B 0
#define CAPI_CHANNELTYPE_D 1
#define CAPI_CHANNELTYPE_NONE 2
/* the lower word is reserved for capi commands */
#define CAPI_WAITEVENT_ANSWER_FINISH 0x80000000
/* ! Private data for a capi device */
struct capi_pvt {