⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clssmssystem.cpp

📁 set of classes for sms messaging applications
💻 CPP
字号:
#include "clssmssystem.h"#include "clssmsmessage.h"#include "clsconfigfile.h"#include <dirent.h>/*//FOR CFGFILE STYLE MESSAGES#define SMS_MSG_FILE_FILTER     "message."#define SMS_MSG_FILE_FILTER_LEN 8#define SMS_MSG_FILE_NAME_LEN   14*///FOR RAW MESSAGES#define SMS_MSG_FILE_FILTER     "GSM"#define SMS_MSG_FILE_FILTER_LEN 3#define SMS_MSG_FILE_NAME_LEN   11//#############################################################################namespace nsSmsSystem{    int     Select( const dirent *pEntry )    {        int iLen = strlen ( pEntry->d_name );        if ( iLen != SMS_MSG_FILE_NAME_LEN )            return false;        if ( strncmp ( pEntry->d_name , SMS_MSG_FILE_FILTER , SMS_MSG_FILE_FILTER_LEN ) )            return false;        return true;    }};//#############################################################################//#############################################################################//#############################################################################clsSmsSystem::clsSmsSystem ( const std::string& rRootSysDir ):    m_szRootSysDir ( rRootSysDir ){}//#############################################################################clsSmsSystem::~clsSmsSystem(){}//#############################################################################int     clsSmsSystem::Initialize      ( ){    ReadConfigFile  ( m_mapGlobales , m_szRootSysDir + SMS_SYS_GLOBALES_FILE );    ReadConfigFile  ( m_mapLocales , m_szRootSysDir + SMS_SYS_LOCALES_FILE );    return NoError;}//#############################################################################int     clsSmsSystem::SetRootSysDir   ( const std::string& rRootSysDir ){    //Maybe perform some checks?    m_szRootSysDir = rRootSysDir;    return NoError;}//#############################################################################int             clsSmsSystem::EventLoop       ( ){    TryGetMessages();    TryPutMessages();    return NoError;}//#############################################################################const   clsSmsMessage*  clsSmsSystem::PeekInMessage   ( ) const{    const clsSmsMessage* pRet = 0;    std::list<clsSmsMessage*>::const_iterator oIt = m_lstInQue.begin();    if ( oIt != m_lstInQue.end() )    {        pRet = *oIt;    }    return pRet;}//#############################################################################clsSmsMessage*  clsSmsSystem::GetInMessage    ( ){    clsSmsMessage* pRet = 0;    std::list<clsSmsMessage*>::iterator oIt = m_lstInQue.begin();    if ( oIt != m_lstInQue.end() )    {        pRet = *oIt;        m_lstInQue.erase ( oIt );    }    return pRet;}//#############################################################################int             clsSmsSystem::SendMessage     ( const std::string& rNumber , const std::string& rText ){    if ( rNumber.empty() || rText.empty() )        return ErrBadInput;    clsSmsMessage* pNewMsg = new clsSmsMessage ( *this );    if ( ! pNewMsg )        return ErrNoMem;    pNewMsg->SetPeerNumber ( rNumber );    pNewMsg->SetFinalText ( rText );    int iRet = SendMessage ( pNewMsg );    if ( iRet != NoError )        delete pNewMsg;    return iRet;}//#############################################################################int             clsSmsSystem::SendMessage     ( const clsSmsMessage& rMsg ){    clsSmsMessage* pNewMsg = new clsSmsMessage ( rMsg );    if ( ! pNewMsg )        return ErrNoMem;    int iRet = SendMessage ( pNewMsg );    if ( iRet != NoError )        delete pNewMsg;    return iRet;}//#############################################################################int             clsSmsSystem::SendMessage     ( clsSmsMessage* pMsg ){    if ( ! pMsg )        return ErrBadInput;    m_lstOutQue.push_back ( pMsg );    return NoError;}//#############################################################################std::string     clsSmsSystem::Globale     ( const std::string& rGlobalVar ){    std::map<std::string,std::string>::iterator oIt = m_mapGlobales.find ( rGlobalVar );    if ( oIt != m_mapGlobales.end() )        return oIt->second;    return std::string();}//#############################################################################std::string     clsSmsSystem::Locale      ( const std::string& rGlobalVar ){    std::map<std::string,std::string>::iterator oIt = m_mapLocales.find ( rGlobalVar );    if ( oIt != m_mapLocales.end() )        return oIt->second;    return std::string();}//#############################################################################int     clsSmsSystem::TryGetMessages  ( ){    int iRet = 0;    struct dirent** ppFiles;    std::string szScanDir ( m_szRootSysDir + SMS_SYS_IN_QUE_DIR );    std::string szFullName;    int iCount = scandir( szScanDir.c_str() , &ppFiles , nsSmsSystem::Select , alphasort );    if ( iCount >= 0 )    {        const char* cFileName;        while ( iCount-- )        {            cFileName = ppFiles[iCount]->d_name;            if ( cFileName )            {                szFullName = szScanDir + cFileName;                clsSmsMessage* pMsg = new clsSmsMessage ( *this );                if ( pMsg )                {                    if ( pMsg->ReadFromFileRaw ( szFullName ) != clsSmsMessage::NoError )                    {                        delete pMsg;                    }                    else                    {                        m_lstInQue.push_back ( pMsg );                        ++iRet;                    }                }                remove ( szFullName.c_str() ); //Maybe fails but don't care            }            free ( ppFiles[iCount] );        }        free ( ppFiles );    }    return iRet;}//#############################################################################int     clsSmsSystem::TryPutMessages  ( ){    if ( ! m_lstOutQue.size() )        return NoError;    for ( std::list<clsSmsMessage*>::iterator oIt = m_lstOutQue.begin() ;          oIt != m_lstOutQue.end() ; )    {        clsSmsMessage* pMsg = *oIt;        if ( pMsg )        {            pMsg->WriteToFile ( m_szRootSysDir + SMS_SYS_OUT_QUE_DIR + "send_" , true );            //Check return value?            delete pMsg;        }        oIt = m_lstOutQue.erase ( oIt );    }    return NoError;}//#############################################################################int     clsSmsSystem::ReadConfigFile  ( std::map<std::string,std::string>& rStringMap , std::string szFile ){    rStringMap.clear();    clsConfigFile oFile ( szFile.c_str() );    if ( ! oFile.ReadFile() )        return ErrFileIO;    int iVariables = oFile.CountVar("");    std::string szVarValue;    for ( int i = 0 ; i < iVariables ; ++i )    {        const char* cVarName = oFile.GetVarName ( CONFIG_FILE_GLOBAL_SECTION , i );        if ( ! cVarName )            continue;        if ( ! oFile.GetVarValue ( CONFIG_FILE_GLOBAL_SECTION , cVarName , szVarValue ) )            continue;        rStringMap [ cVarName ] = szVarValue;    }    return NoError;}//#############################################################################

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -