| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- #include "StdAfx.h"
- #include "FaxChannel.h"
- #include "MC.h"
- #include "OneLeg.h"
- #include "IpmChannel.h"
- CFaxChannel::CFaxChannel(int ChanNo) : m_ChanNo(ChanNo), m_Handle(DEV_HANDLE_INVALID), m_state(FS_IDLE), m_pLeg(NULL), m_pIpmChan(NULL)
- {
- }
- CFaxChannel::~CFaxChannel(void)
- {
- }
- /*****************************************************************
- **【函数名称】 __release
- **【函数功能】 资源释放
- **【参数】
- **【返回值】
- ****************************************************************/
- void CFaxChannel::__release( bool FaxResult )
- {
- m_state = FS_IDLE;
- ASSERT(m_pIpmChan != NULL);
- ASSERT(m_pLeg != NULL);
- CMC::GetInstance().bridgeDevice(m_pLeg->routeChannel(), m_pIpmChan, false, false);
- m_pIpmChan->stopFax();
- m_pIpmChan = NULL;
- m_pLeg->onFaxEnd(FaxResult, NULL);
- m_pLeg = NULL;
- }
- /*****************************************************************
- **【函数名称】 __onFaxError
- **【函数功能】 传真出错处理
- **【参数】
- **【返回值】
- ****************************************************************/
- void CFaxChannel::__onFaxError( void )
- {
- __release(false);
- LOGGER(LOG_CLASS_DEV, LOG_LEVEL_WARNING, _T("{FaxCh}: 通道[%d]收发传真失败, %s"),
- m_ChanNo, ISX_ATDV_ERRMSGP(m_Handle));
- }
- /*****************************************************************
- **【函数名称】 __onFaxEnd
- **【函数功能】 传真结束处理
- **【参数】
- **【返回值】
- ****************************************************************/
- void CFaxChannel::__onFaxEnd( void )
- {
- bool Res = false;
- int TermCode = ISX_ATFXS_TERMMSK(m_Handle);
- if(TermCode != AT_FAILURE)
- Res = (TermCode & TM_FXTERM) == TM_FXTERM ? true : false;
- __release(Res);
- LOGGER(LOG_CLASS_DEV, Res ? LOG_LEVEL_NORMAL : LOG_LEVEL_WARNING, _T("{FaxCh}: 通道[%d]收发传真结束, Result = %d"),
- m_ChanNo, Res);
- }
- /*****************************************************************
- **【函数名称】 open
- **【函数功能】 打开通道
- **【参数】
- **【返回值】
- ****************************************************************/
- bool CFaxChannel::open( void )
- {
- if(m_Handle != DEV_HANDLE_INVALID)
- return false;
- m_Handle = ISX_fxs_open(m_ChanNo, this);
- if(m_Handle < 0)
- {
- m_Handle = DEV_HANDLE_INVALID;
- return false;
- }
- return true;
- }
- /*****************************************************************
- **【函数名称】 close
- **【函数功能】 关闭通道
- **【参数】
- **【返回值】
- ****************************************************************/
- void CFaxChannel::close( void )
- {
- if(m_Handle != DEV_HANDLE_INVALID)
- {
- ISX_fxs_close(m_Handle);
- m_Handle = DEV_HANDLE_INVALID;
- }
- }
- /*****************************************************************
- **【函数名称】 send
- **【函数功能】 发送传真
- **【参数】
- **【返回值】
- ****************************************************************/
- bool CFaxChannel::send( COneLeg* pLeg, LPCTSTR FaxFile )
- {
- ASSERT(pLeg != NULL);
- ASSERT(FaxFile != NULL);
- CChannelResource* pDstChanRes = pLeg->routeChannel();
- ASSERT(pDstChanRes != NULL);
- CIpmChannel* pIpmChan = CMC::GetInstance().allocIpmCh4SipCh(pDstChanRes->nodeNo(), pDstChanRes->boardNo());
- if(pIpmChan == NULL)
- return false;
- pIpmChan->startFax();
- if(!CMC::GetInstance().bridgeDevice(pDstChanRes, pIpmChan, true, false))
- {
- pIpmChan->stopFax();
- LOGGER(LOG_CLASS_DEV, LOG_LEVEL_WARNING, _T("{FaxCh}: 通道[%d]发送传真失败, 无法建立IPM与CallLeg间的交换, File = %s"),
- m_ChanNo, FaxFile);
- return false;
- }
- SNDFAX_ITEMS FaxItem;
- memset(&FaxItem, 0, sizeof(SNDFAX_ITEMS));
- FaxItem.io_datatype = DF_TIFF;
- sprintf_s(FaxItem.szFileName, MAX_PATH, _T("%s"), FaxFile);
- if(ISX_fxs_sendfax(m_Handle, &FaxItem, 1, pIpmChan->handle()) == 0)
- {
- m_pLeg = pLeg;
- m_pIpmChan = pIpmChan;
- m_state = FS_SEND;
- LOGGER(LOG_CLASS_DEV, LOG_LEVEL_NORMAL, _T("{FaxCh}: 通道[%d]开始发送传真, File = %s"), m_ChanNo, FaxFile);
- return true;
- }
- else
- {
- CMC::GetInstance().bridgeDevice(pDstChanRes, pIpmChan, false, false);
- pIpmChan->stopFax();
- LOGGER(LOG_CLASS_DEV, LOG_LEVEL_WARNING, _T("{FaxCh}: 通道[%d]发送传真失败, File = %s"), m_ChanNo, FaxFile);
- return false;
- }
- }
- /*****************************************************************
- **【函数名称】 recv
- **【函数功能】 接收传真
- **【参数】
- **【返回值】
- ****************************************************************/
- bool CFaxChannel::recv( COneLeg* pLeg, LPCTSTR FaxFile )
- {
- ASSERT(pLeg != NULL);
- ASSERT(FaxFile != NULL);
- CChannelResource* pDstChanRes = pLeg->routeChannel();
- ASSERT(pDstChanRes != NULL);
- CIpmChannel* pIpmChan = CMC::GetInstance().allocIpmCh4SipCh(pDstChanRes->nodeNo(), pDstChanRes->boardNo());
- if(pIpmChan == NULL)
- return false;
- pIpmChan->stopFax();
- if(!CMC::GetInstance().bridgeDevice(pDstChanRes, pIpmChan, true, false))
- {
- pIpmChan->stopFax();
- LOGGER(LOG_CLASS_DEV, LOG_LEVEL_WARNING, _T("{FaxCh}: 通道[%d]接收传真失败, 无法建立IPM与CallLeg间的交换, File = %s"),
- m_ChanNo, FaxFile);
- return false;
- }
- char FileName[MAX_PATH];
- sprintf_s(FileName, MAX_PATH, _T("%s"), FaxFile);
- if(ISX_fxs_rcvfax(m_Handle, FileName, pIpmChan->handle()) == 0)
- {
- m_pLeg = pLeg;
- m_pIpmChan = pIpmChan;
- m_state = FS_RECV;
- LOGGER(LOG_CLASS_DEV, LOG_LEVEL_NORMAL, _T("{FaxCh}: 通道[%d]开始接收传真, File = %s"),
- m_ChanNo, FaxFile);
- return true;
- }
- else
- {
- CMC::GetInstance().bridgeDevice(pDstChanRes, pIpmChan, false, false);
- pIpmChan->stopFax();
- LOGGER(LOG_CLASS_DEV, LOG_LEVEL_WARNING, _T("{FaxCh}: 通道[%d]接收传真失败, File = %s"),
- m_ChanNo, FaxFile);
- return false;
- }
- }
- /*****************************************************************
- **【函数名称】 stop
- **【函数功能】 接收传真
- **【参数】
- **【返回值】
- ****************************************************************/
- bool CFaxChannel::stop( void )
- {
- LOGGER(LOG_CLASS_DEV, LOG_LEVEL_NORMAL, _T("{FaxCh}: 通道[%d]终止传真收发, State = %d"), m_ChanNo, m_state);
- if(m_state == FS_IDLE)
- return false;
- ISX_fxs_stopch(m_Handle);
- __release(false);
- return true;
- }
- /*****************************************************************
- **【函数名称】 onDevEvent
- **【函数功能】 系统事件处理
- **【参数】
- **【返回值】
- ****************************************************************/
- void CFaxChannel::onDevEvent( METAEVENT* pMetaEvent )
- {
- ASSERT(pMetaEvent != NULL);
- switch(pMetaEvent->evttype)
- {
- case TFX_FAXERROR:
- case TFX_STARTOP_ERR:
- __onFaxError();
- break;
- case TFX_FAXRECV:
- case TFX_FAXSEND:
- __onFaxEnd();
- break;
- }
- }
|