Main Page   Namespace List   Class Hierarchy   Data Structures   File List   Namespace Members   Data Fields   Globals   Related Pages  

DialOp.cpp

Go to the documentation of this file.
00001 /*
00002  * DialOp.cpp
00003  *
00004  * Copyright 2003, MobileSpear Inc. (www.mobilespear.com). All rights reserved.
00005  * Copyright 2003, David Resnick. All rights reserved.
00006  *
00007  * See the file doc\license.txt for the terms of usage and distribution.
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     // this is called when a dtmf has finished playing
00055     // and it means that it is time to play the next one
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         // check if we're finished with all digits
00076         if (m_iCurrDtmf == m_strDtmf.size()) {
00077             // check if the previous digit was not a pause
00078             if (m_iCurrDtmf > 0 && m_strDtmf[m_iCurrDtmf - 1] != ',') {
00079                 // send msg that the previous Dtmf has finished playing
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         // check if we should perform "pause" (silence)
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         // schedule timer for end of Dtmf
00095         setTimer(700, timerType::singleDtmf);
00096 
00097         m_iCurrDtmf++;
00098         g_util->log(9, -1, "%s: Finished", method);
00099     }
00100 
00101     // override terminate so that we can check the target
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     // makes sure that all chars in dial string are valid
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 }

Generated on Tue Aug 12 12:41:29 2003 for bogotel by doxygen 1.3. Hosted by SourceForge.net Logo