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

VoiceDev.h

Go to the documentation of this file.
00001 /*
00002  * VoiceDev.h
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 #ifndef _BOGOTEL_VOICEDEV_H
00011 #define _BOGOTEL_VOICEDEV_H
00012 
00013 #include <log4cpp/Portability.hh>
00014 #include <bogotel/devbase.h>
00015 #include <bogotel/observer.h>
00016 #include <bogotel/Properties.h>
00017 
00018 #include <bogotel/StlHelp.h>
00019 
00020 #include <boost/thread/recursive_mutex.hpp>
00021 
00022 #include <string>
00023 #include <map>
00024 #include <queue>
00025 #include <deque>
00026 
00027 namespace bogotel {
00028 
00029     typedef std::map<int, std::string, std::less<int> > MAP_INT2STR;
00030     typedef std::queue<char> QUEUE_CHAR;
00031     typedef std::deque<char> DEQUE_CHAR;
00032 
00033     class CSignalDev;
00034     class CIOOp;
00035 
00036     class CVoiceDev : public CDevBase, public CSubject
00037     {
00038     public:
00039 
00040         static const int invalidHandle;
00041 
00042         enum targetType {
00043             local = 0,
00044             remote
00045         };
00046 
00047         enum speakerState {
00048             UNDEFINED = -1,
00049             SILENT,
00050             WAV,
00051             DTMF
00052         };
00053 
00054         CVoiceDev(CBgtRt *pBgtRt);
00055         int init(std::string strName, long lHandle, long lTimeslot);
00056         int listen(CSignalDev *pVD);
00057         int play(DX_IOTT *pIott,const DV_TPT *pTpt,const DX_XPB *pXpb,unsigned short usMode);
00058         int dial(const char *szDialStr, const DX_CAP *pCAP, unsigned short usMode);
00059         int stop(unsigned short usMode);
00060         int clearDigitBuffer();
00061         int getDigit(const DV_TPT *pTpt, DV_DIGIT *pDigit, unsigned short usMode);
00062 
00063         long getSignalHandle();
00064         long getTimeslot()       { return m_lSCbusTimeslot; }
00065         long getHandle()         { return m_lHandle; }
00066         speakerState getState()  { return m_speakerState; }
00067         char getCurrentDtmf()    { return m_queueDigitValue.front(); }
00068         long getTermMsk()        { return m_lTermMsk; }
00069         unsigned int getStateId() { return m_uiStateId; }
00070 
00071         void truncateDtmfs(int iNumToTruncate);
00072 
00073         int receiveMsg(CMsg *pMsg);
00074         void sendPlayMsg(std::string strFilename);
00075         void sendPlayFinishedMsg();
00076         void sendDtmfMsg(char chDTMF, int iTargetType);
00077         void sendDtmfFinishedMsg(int iTargetType);
00078         void terminateIoOp(long lTermMsk, bool bInternalIoOp = false);
00079 
00080         void eraseDigitHistory();
00081         void eraseFromDigitHistory(unsigned short iToChop);
00082         void eraseFromDigitHistory(DEQUE_CHAR::iterator iterTillToChop);
00083         DEQUE_CHAR getDigitHistory() { return m_dequeDigitHistory; }
00084         static const std::string& getEventName(long lType);
00085 
00086         void getDigits(DV_DIGIT *pDigit, int iNumToGet);
00087 
00088         // stores the filenames of all opened WAV files, indexed by handles
00089         static MAP_INT2STR s_mapHandle2Filename;
00090         static CProperties s_propWav2Dtmfs;
00091         static std::string s_strWavFilenameBase;
00092 
00093     protected:
00094         // stores the digits "heard" from DTMFs
00095         QUEUE_CHAR   m_queueDigitValue;
00096         QUEUE_CHAR   m_queueDigitType;
00097         // used to determine termination conditions
00098         DEQUE_CHAR   m_dequeDigitHistory;
00099 
00100         speakerState m_speakerState;
00101         // Identifies the current state, allowing
00102         // termparm objects to ignore updates to speaker
00103         // state that don't apply to them.
00104         unsigned int m_uiStateId;
00105 
00106         std::string  m_strName;
00107         long         m_lHandle;
00108         long         m_lSCbusTimeslot;
00109         CSignalDev*  m_pSignalDev;
00110         long         m_lTermMsk;
00111 
00112         std::string  m_strCurrPlaybackFilename;
00113         CIOOp*       m_pIoOp;
00114         CIOOp*       m_pInternalIoOp;
00115 
00116         int checkDigits();
00117 
00118         int sendEvent(long lType, long lTermMsk = 0);
00119         int sendMsg(CMsg *pMsg, int targetType = targetType::remote);
00120         void log(int iLevel, char *szFmt, ...);
00121         void getEvtTypeString(long lType, char *szType, int iMaxLen);
00122 
00123     private:
00124 
00125         // manages multithreaded access to the IO op pointers
00126         boost::recursive_mutex m_mtxIoOps; 
00127 
00128         void registerIoOp(CIOOp *pIoOp, bool bInternalIoOp = false);
00129         void stripBaseFromWavFilename(std::string& strFilename);
00130         bool attemptRecognition(std::string& strFilename);
00131 
00132         void updateSpeakerState(speakerState state);
00133         void updateSpeakerState(speakerState state, char chDtmf);
00134         void updateSpeakerState(speakerState state, std::string strFilename);
00135 
00136         static const std::string eventNames[5];
00137     };
00138 
00139 }
00140 
00141 #endif // ! _BOGOTEL_VOICEDEV_H
00142 
00143 

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