00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <bogotel/portability.h>
00011 #include <bogotel/dialOp.h>
00012
00013 #include <sys/stat.h>
00014 #include <sys/types.h>
00015
00016 #include <bogotel/BgtErrors.h>
00017 #include <bogotel/voicedev.h>
00018 #include <bogotel/util.h>
00019
00020 namespace bogotel {
00021
00022 const char *CDialOp::s_szValidDtmf = "1234567890*#abcd,";
00023 const char *CDialOp::s_szName = "CDialOp";
00024
00025 CDialOp::CDialOp(CVoiceDev* pVD, const char *szDialStr, int iTargetType) throw (std::invalid_argument) :
00026 CIOOp(pVD),
00027 m_iCurrDtmf(0),
00028 m_strDtmf(szDialStr),
00029 m_iTargetType(iTargetType)
00030 {
00031 checkDialString();
00032 }
00033
00034 CDialOp::~CDialOp()
00035 {
00036 CIOOp::~CIOOp();
00037 }
00038
00039 void CDialOp::start()
00040 {
00041 dialSingleDigit();
00042 }
00043
00044 std::string CDialOp::toString()
00045 {
00046 return CTimerTarget::toString() + " " + s_szName;
00047 }
00048
00049 long CDialOp::terminationEvent()
00050 {
00051 return TDX_DIAL;
00052 }
00053
00054
00055
00056 void CDialOp::_timerExpired(int timerType, int stateId)
00057 {
00058 char method[] = "CDialOp::_timerExpired";
00059 switch (timerType) {
00060 case timerType::singleDtmf:
00061 dialSingleDigit();
00062 break;
00063 default:
00064 log(3, "%s: Invalid timerType", method, timerType);
00065 break;
00066 }
00067 }
00068
00069 void CDialOp::dialSingleDigit()
00070 {
00071 char method[] = "CDialOp::dialSingleDigit";
00072 g_util->log(9, -1, "%s: Entered. m_strDtmf='%s', m_iCurrDtmf=%d", method,
00073 m_strDtmf.c_str(), m_iCurrDtmf);
00074
00075
00076 if (m_iCurrDtmf == m_strDtmf.size()) {
00077
00078 if (m_iCurrDtmf > 0 && m_strDtmf[m_iCurrDtmf - 1] != ',') {
00079
00080 m_pVD->sendDtmfFinishedMsg(m_iTargetType);
00081 }
00082 terminate(TM_NORMTERM);
00083 g_util->log(9, -1, "%s: Finished (terminated)", method);
00084 return;
00085 }
00086
00087
00088 if (m_iCurrDtmf > 0 && m_strDtmf[m_iCurrDtmf] == ',' && m_strDtmf[m_iCurrDtmf - 1] != ',') {
00089 m_pVD->sendDtmfFinishedMsg(m_iTargetType);
00090 } else {
00091 m_pVD->sendDtmfMsg(m_strDtmf[m_iCurrDtmf], m_iTargetType);
00092 }
00093
00094
00095 setTimer(700, timerType::singleDtmf);
00096
00097 m_iCurrDtmf++;
00098 g_util->log(9, -1, "%s: Finished", method);
00099 }
00100
00101
00102 void CDialOp::terminate(long lTermMsk)
00103 {
00104 char method[] = "CDialOp::terminate";
00105 switch (m_iTargetType) {
00106 case CVoiceDev::targetType::remote:
00107 CIOOp::terminate(lTermMsk);
00108 break;
00109 case CVoiceDev::targetType::local:
00110 m_pVD->terminateIoOp(lTermMsk, true);
00111 break;
00112 default:
00113 log(3, "%s: Invalid targetType", method, m_iTargetType);
00114 break;
00115 }
00116 }
00117
00118
00119 void CDialOp::checkDialString() throw (std::invalid_argument)
00120 {
00121 if (m_strDtmf.size() == 0) {
00122 throw std::invalid_argument("Dtmf string is empty");
00123 }
00124 for (std::string::size_type i = 0; i < m_strDtmf.size(); i++) {
00125 if (strchr(s_szValidDtmf, m_strDtmf[i]) == NULL) {
00126 throw std::invalid_argument("Invalid char in dial string: " + m_strDtmf);
00127 }
00128 }
00129 }
00130 }