diff --git a/src/account.h b/src/account.h index d099e965c6bd6c00612efef690fff34ba20ae5b9..cd070f6ad93ca8aa5ad48ee2c63fd95ec58c9c3a 100644 --- a/src/account.h +++ b/src/account.h @@ -96,13 +96,13 @@ class Account{ * Register the underlying VoIPLink. Launch the event listener. * This should update the getRegistrationState() return value. */ - virtual void registerVoIPLink() = 0; + virtual int registerVoIPLink() = 0; /** * Unregister the underlying VoIPLink. Stop the event listener. * This should update the getRegistrationState() return value. */ - virtual void unregisterVoIPLink() = 0; + virtual int unregisterVoIPLink() = 0; /** * Tell if the account is enable or not. diff --git a/src/global.h b/src/global.h index b68c72671df938dedfe1ad271fe8c83f1f8f040c..c03cc43b72684909397a9c6944d4903fb39d0964 100644 --- a/src/global.h +++ b/src/global.h @@ -31,6 +31,11 @@ typedef float float32; typedef short int16; +#define SUCCESS 0 + +#define ASSERT( expected , value) if( value == expected ) return SUCCESS; \ + else return 1; + #ifdef DATAFORMAT_IS_FLOAT #define SFLDataFormat float32 #define SFLDataFormatString "Float32" diff --git a/src/iaxaccount.cpp b/src/iaxaccount.cpp index 461e75019eda929c521c10647b0799f8d43fb202..d038bab844664cbcb9e92aa9972772c037a9a616 100644 --- a/src/iaxaccount.cpp +++ b/src/iaxaccount.cpp @@ -35,7 +35,7 @@ IAXAccount::~IAXAccount() _link = NULL; } -void +int IAXAccount::registerVoIPLink() { _link->init(); @@ -50,13 +50,17 @@ IAXAccount::registerVoIPLink() } _link->sendRegister(); + + return SUCCESS; } -void +int IAXAccount::unregisterVoIPLink() { _link->sendUnregister(); _link->terminate(); + + return SUCCESS; } void diff --git a/src/iaxaccount.h b/src/iaxaccount.h index 0d52718e5791b8c76fe4306614a579a78b5ca8ce..cb7a2c861e1eaac58a4572d281717319535f9fd2 100644 --- a/src/iaxaccount.h +++ b/src/iaxaccount.h @@ -42,12 +42,12 @@ public: /** * Register an account */ - void registerVoIPLink(); + int registerVoIPLink(); /** * Unregister an account */ - void unregisterVoIPLink(); + int unregisterVoIPLink(); private: }; diff --git a/src/iaxvoiplink.cpp b/src/iaxvoiplink.cpp index 1629c1a35c598cb31907e24878d76841c334a8ff..4da2f14b5c11c01ec4739b24576a95c94d0f9ef2 100644 --- a/src/iaxvoiplink.cpp +++ b/src/iaxvoiplink.cpp @@ -299,8 +299,7 @@ IAXVoIPLink::getIAXCall(const CallID& id) } - - bool + int IAXVoIPLink::sendRegister() { bool result = false; @@ -353,8 +352,7 @@ IAXVoIPLink::sendRegister() - - bool + int IAXVoIPLink::sendUnregister() { _mutexIAX.enterMutex(); @@ -373,7 +371,7 @@ IAXVoIPLink::sendUnregister() _debug("IAX2 send unregister\n"); setRegistrationState(Unregistered); - return false; + return SUCCESS; } Call* diff --git a/src/iaxvoiplink.h b/src/iaxvoiplink.h index 3a8c3fbd4a11b183e6cd58b4f99a0cce81cc238d..9f1525afe28cffdb6c22a1947b7e81652d5e48f8 100644 --- a/src/iaxvoiplink.h +++ b/src/iaxvoiplink.h @@ -83,7 +83,7 @@ class IAXVoIPLink : public VoIPLink * Send out registration * @return bool The new registration state (are we registered ?) */ - bool sendRegister (void); + int sendRegister (void); /** * Destroy registration session @@ -92,7 +92,7 @@ class IAXVoIPLink : public VoIPLink * @return bool true if we're registered upstream * false otherwise */ - bool sendUnregister (void); + int sendUnregister (void); /** * Create a new outgoing call diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index b29ce3732955c374d2af4f735cec565d88533529..bc16f89cf094533b161ad6a6bb2eeebe4bdfeb52 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -444,28 +444,31 @@ ManagerImpl::saveConfig (void) } //THREAD=Main - bool + int ManagerImpl::initRegisterAccounts() { - _debugInit("Initiate VoIP Links Registration"); - AccountMap::iterator iter = _accountMap.begin(); - while( iter != _accountMap.end() ) { - if ( iter->second) { - iter->second->loadConfig(); - if ( iter->second->isEnabled() ) { - // NOW - iter->second->registerVoIPLink(); - //iter->second->loadContacts(); - //iter->second->publishPresence(PRESENCE_ONLINE); - //iter->second->subscribeContactsPresence(); + + int status; + AccountMap::iterator iter; + + _debugInit("Initiate VoIP Links Registration"); + iter = _accountMap.begin(); + + while( iter != _accountMap.end() ) { + if ( iter->second ) { + iter->second->loadConfig(); + if ( iter->second->isEnabled() ) { + status = iter->second->registerVoIPLink(); + ASSERT( status, SUCCESS ); + } } + iter++; } - iter++; - } - // calls the client notification here in case of errors at startup... - if( _audiodriver -> getErrorMessage() != -1 ) - notifyErrClient( _audiodriver -> getErrorMessage() ); - return true; + // calls the client notification here in case of errors at startup... + if( _audiodriver -> getErrorMessage() != -1 ) + notifyErrClient( _audiodriver -> getErrorMessage() ); + + return SUCCESS; } //THREAD=Main diff --git a/src/managerimpl.h b/src/managerimpl.h index 57c3b733856e75dd29983165ef134c59e6315f1c..bb16b7134ba0f72d5436f7efad8b375614a64e95 100644 --- a/src/managerimpl.h +++ b/src/managerimpl.h @@ -171,9 +171,10 @@ class ManagerImpl { /** * Send registration to all enabled accounts - * @return false if exosip or the network checking fails + * @return 0 on registration success + * 1 otherelse */ - bool initRegisterAccounts(); + int initRegisterAccounts(); /** * @return true if we tried to register once diff --git a/src/sipaccount.cpp b/src/sipaccount.cpp index f7a156ed960c227c5293bcee1414f8cdc8f26680..8453b1f29bb0a7a39a433a203302bfab48777626 100644 --- a/src/sipaccount.cpp +++ b/src/sipaccount.cpp @@ -45,35 +45,43 @@ SIPAccount::~SIPAccount() _cred = NULL; } -void +int SIPAccount::registerVoIPLink() { - _link->setHostName(Manager::instance().getConfigString(_accountID,SIP_HOST)); - int useStun = Manager::instance().getConfigInt(_accountID,SIP_USE_STUN); + + int status, useStun; + SIPVoIPLink *thislink; + + _link->setHostName(Manager::instance().getConfigString(_accountID,SIP_HOST)); + useStun = Manager::instance().getConfigInt(_accountID,SIP_USE_STUN); - SIPVoIPLink* thislink = dynamic_cast<SIPVoIPLink*> (_link); - thislink->setStunServer(Manager::instance().getConfigString(_accountID,SIP_STUN_SERVER)); - thislink->setUseStun( useStun!=0 ? true : false); + thislink = dynamic_cast<SIPVoIPLink*> (_link); + thislink->setStunServer(Manager::instance().getConfigString(_accountID,SIP_STUN_SERVER)); + thislink->setUseStun( useStun!=0 ? true : false); - //SIPVoIPLink* thislink = dynamic_cast<SIPVoIPLink*> (_link); - _link->init(); + _link->init(); - // Stuff needed for SIP registration. - thislink->setProxy (Manager::instance().getConfigString(_accountID,SIP_PROXY)); - thislink->setAuthName(Manager::instance().getConfigString(_accountID,SIP_USER)); - thislink->setPassword(Manager::instance().getConfigString(_accountID,SIP_PASSWORD)); - thislink->setSipServer(Manager::instance().getConfigString(_accountID,SIP_HOST)); + // Stuff needed for SIP registration. + thislink->setProxy (Manager::instance().getConfigString(_accountID,SIP_PROXY)); + thislink->setAuthName(Manager::instance().getConfigString(_accountID,SIP_USER)); + thislink->setPassword(Manager::instance().getConfigString(_accountID,SIP_PASSWORD)); + thislink->setSipServer(Manager::instance().getConfigString(_accountID,SIP_HOST)); - _link->sendRegister(); + status = _link->sendRegister(); + ASSERT( status , SUCCESS ); + + return SUCCESS; } -void +int SIPAccount::unregisterVoIPLink() { _debug("SIPAccount: unregister account %s\n" , getAccountID().c_str()); _link->sendUnregister(); _debug("Terminate SIP account\n"); _link->terminate(); + + return SUCCESS; } void diff --git a/src/sipaccount.h b/src/sipaccount.h index 5c32f1e50acb6a65015c6f8501d6e18c2a28694c..40ca2c876d491e096233b9b12ef2d29ac89609db 100644 --- a/src/sipaccount.h +++ b/src/sipaccount.h @@ -59,12 +59,12 @@ public: /** * Initialize the SIP voip link with the account parameters and send registration */ - void registerVoIPLink(); + int registerVoIPLink(); /** * Send unregistration and clean all related stuff ( calls , thread ) */ - void unregisterVoIPLink(); + int unregisterVoIPLink(); void setUserName(const std::string &name) {_userName = name;} diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp index fcf568fcf99b5cf52f3fc0c1077ebe765754eb64..040b760e323d5ab755119a21c170f3f0b73a9edd 100644 --- a/src/sipvoiplink.cpp +++ b/src/sipvoiplink.cpp @@ -132,7 +132,7 @@ SIPVoIPLink::getEvent() // Nothing anymore. PJSIP is based on asynchronous events } -bool +int SIPVoIPLink::sendRegister() { AccountID id; @@ -178,7 +178,7 @@ SIPVoIPLink::sendSIPAuthentification() return true; } -bool +int SIPVoIPLink::sendUnregister() { _debug("SEND UNREGISTER for account %s\n" , getAccountID().c_str()); diff --git a/src/sipvoiplink.h b/src/sipvoiplink.h index 2b4c6b99c145c07d0640af87cd46b1414fbeed8b..f29ceb9e589354f109c888a5542dc35e95fa2332 100644 --- a/src/sipvoiplink.h +++ b/src/sipvoiplink.h @@ -92,14 +92,14 @@ class SIPVoIPLink : public VoIPLink * @return bool True on success * false otherwise */ - bool sendRegister(void); + int sendRegister(void); /** * Build and send SIP unregistration request * @return bool True on success * false otherwise */ - bool sendUnregister(void); + int sendUnregister(void); /** * Place a new call diff --git a/src/useragent.cpp b/src/useragent.cpp index b703186c540d26eed3ab64f48a127be4016889d3..5e382f9cd87d8aa6ca6458b28de2886deda401ff 100644 --- a/src/useragent.cpp +++ b/src/useragent.cpp @@ -358,7 +358,7 @@ void UserAgent::busy_sleep(unsigned msec) #endif } -bool UserAgent::addAccount(AccountID id, pjsip_regc **regc2, const std::string& server, const std::string& user, const std::string& passwd, +int UserAgent::addAccount(AccountID id, pjsip_regc **regc2, const std::string& server, const std::string& user, const std::string& passwd, const int& timeout UNUSED) { pj_status_t status; AccountID *currentId = new AccountID(id); @@ -435,7 +435,8 @@ bool UserAgent::addAccount(AccountID id, pjsip_regc **regc2, const std::string& *regc2 = regc; pj_mutex_unlock(_mutex); - return true; + + return PJ_SUCCESS; } bool UserAgent::removeAccount(pjsip_regc *regc) diff --git a/src/useragent.h b/src/useragent.h index a1bb0b02cb6a8b8d92b1d215f9ccd02239b51323..3ce1649d1bedb4b70130ffc31ef49d702ceaa329 100644 --- a/src/useragent.h +++ b/src/useragent.h @@ -102,7 +102,7 @@ public: pj_str_t getStunServer() { return _stunHost; } - bool addAccount(AccountID id, pjsip_regc **regc, const std::string& server, const std::string& user, const std::string& passwd + int addAccount(AccountID id, pjsip_regc **regc, const std::string& server, const std::string& user, const std::string& passwd , const int& timeout); bool removeAccount(pjsip_regc *regc); diff --git a/src/voiplink.h b/src/voiplink.h index c260cdee4ae8787f88935272e8628e59e73cfd9c..3dd2344481c38a874ea171b140f37388014d0641 100644 --- a/src/voiplink.h +++ b/src/voiplink.h @@ -90,7 +90,7 @@ class VoIPLink { * @return bool True on success * false otherwise */ - virtual bool sendRegister (void) = 0; + virtual int sendRegister (void) = 0; /** * Virtual method @@ -98,7 +98,7 @@ class VoIPLink { * @return bool True on success * false otherwise */ - virtual bool sendUnregister (void) = 0; + virtual int sendUnregister (void) = 0; /** * Place a new call