From 976a412dc6a3344ea0e9830cb2bbaa1f22bc8fad Mon Sep 17 00:00:00 2001
From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
Date: Fri, 10 Oct 2008 16:23:01 -0400
Subject: [PATCH] add ASSERT macro, change some return values from bool to int

---
 src/account.h       |  4 ++--
 src/global.h        |  5 +++++
 src/iaxaccount.cpp  |  8 ++++++--
 src/iaxaccount.h    |  4 ++--
 src/iaxvoiplink.cpp |  8 +++-----
 src/iaxvoiplink.h   |  4 ++--
 src/managerimpl.cpp | 39 +++++++++++++++++++++------------------
 src/managerimpl.h   |  5 +++--
 src/sipaccount.cpp  | 38 +++++++++++++++++++++++---------------
 src/sipaccount.h    |  4 ++--
 src/sipvoiplink.cpp |  4 ++--
 src/sipvoiplink.h   |  4 ++--
 src/useragent.cpp   |  5 +++--
 src/useragent.h     |  2 +-
 src/voiplink.h      |  4 ++--
 15 files changed, 79 insertions(+), 59 deletions(-)

diff --git a/src/account.h b/src/account.h
index d099e965c6..cd070f6ad9 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 b68c72671d..c03cc43b72 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 461e75019e..d038bab844 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 0d52718e57..cb7a2c861e 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 1629c1a35c..4da2f14b5c 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 3a8c3fbd4a..9f1525afe2 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 b29ce37329..bc16f89cf0 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 57c3b73385..bb16b7134b 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 f7a156ed96..8453b1f29b 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 5c32f1e50a..40ca2c876d 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 fcf568fcf9..040b760e32 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 2b4c6b99c1..f29ceb9e58 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 b703186c54..5e382f9cd8 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 a1bb0b02cb..3ce1649d1b 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 c260cdee4a..3dd2344481 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
-- 
GitLab