From e5437d5222d0916c290f3283e2180ab91ec721ae Mon Sep 17 00:00:00 2001
From: yanmorin <yanmorin>
Date: Mon, 17 Oct 2005 20:28:15 +0000
Subject: [PATCH] Add 103/104 response message to getEvents for registration
 succeed and failed

---
 src/gui/guiframework.cpp         | 26 ++++++++++++++++++++++++++
 src/gui/guiframework.h           |  3 ++-
 src/gui/server/guiserverimpl.cpp |  9 ++++++++-
 src/managerimpl.cpp              |  6 ++++++
 src/managerimpl.h                | 23 +++++++++++------------
 5 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/src/gui/guiframework.cpp b/src/gui/guiframework.cpp
index c927faf083..a85784c95b 100644
--- a/src/gui/guiframework.cpp
+++ b/src/gui/guiframework.cpp
@@ -253,3 +253,29 @@ GuiFramework::hasLoadedSetup()
 {
   return Manager::instance().hasLoadedSetup();
 }
+
+bool 
+GuiFramework::getRegistrationState(std::string& stateCode, std::string& stateMessage) {
+  ManagerImpl::REGISTRATION_STATE state = Manager::instance().getRegistrationState();
+  bool returnValue = false;
+  switch( state ) {
+    case ManagerImpl::REGISTERED:
+      returnValue = true;
+      stateCode    = "103";
+      stateMessage = "Registration succeed";
+    break;
+
+    case ManagerImpl::FAILED:
+      returnValue = true;
+      stateCode    = "104";
+      stateMessage = "Registration failed";
+    break;
+
+    case ManagerImpl::UNREGISTERED:
+      returnValue = false;
+      stateCode    = "";
+      stateMessage = "";
+    break;
+  }
+  return returnValue;
+}
diff --git a/src/gui/guiframework.h b/src/gui/guiframework.h
index ce3e7bc670..47407e3ed7 100644
--- a/src/gui/guiframework.h
+++ b/src/gui/guiframework.h
@@ -91,9 +91,10 @@ public:
 
   bool hasLoadedSetup();
   CALLID getCurrentId();
+  bool getRegistrationState(std::string& stateCode, std::string& stateMessage);
 
 protected:
-	std::string _message;
+  std::string _message;
 };
 
 #endif // __GUI_FRAMEWORK_H__
diff --git a/src/gui/server/guiserverimpl.cpp b/src/gui/server/guiserverimpl.cpp
index 3d31da7a4f..2e17299d9f 100644
--- a/src/gui/server/guiserverimpl.cpp
+++ b/src/gui/server/guiserverimpl.cpp
@@ -132,7 +132,14 @@ GUIServerImpl::getEvents(const std::string& sequenceId)
   percentMic << GuiFramework::getMicVolume();
   tk.push_back(percentMic.str());
   tk.push_back("Microphone volume changed");
-  _requestManager.sendResponse(ResponseMessage("022", sequenceId,tk));
+  _requestManager.sendResponse(ResponseMessage("022", sequenceId, tk));
+
+  std::string stateCode;
+  std::string stateMessage;
+  if (GuiFramework::getRegistrationState(stateCode,stateMessage)) {
+    _requestManager.sendResponse(ResponseMessage(stateCode, sequenceId, stateMessage));
+  }
+
 
   return true;
 }
diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp
index 9f0b0e64bd..45bbce69f9 100644
--- a/src/managerimpl.cpp
+++ b/src/managerimpl.cpp
@@ -90,6 +90,8 @@ ManagerImpl::ManagerImpl (void)
   _nbIncomingWaitingCall=0;
 
   _codecMap = CodecDescriptorMap().getMap();
+
+  _registerState = UNREGISTERED;
 }
 
 // never call if we use only the singleton...
@@ -448,9 +450,13 @@ ManagerImpl::registerVoIPLink (void)
   if ( !useStun() ) {
     if (_voIPLinkVector.at(DFT_VOIP_LINK)->setRegister() >= 0) {
       returnValue = true;
+      _registerState = REGISTERED;
     } else {
       _debug("ManagerImpl::registerVoIPLink: Registration failed\n");
+      _registerState = FAILED;
     }
+  } else {
+    _registerState = UNREGISTERED;
   }
   return returnValue;
 }
diff --git a/src/managerimpl.h b/src/managerimpl.h
index cc5050bbf1..0efb6d458f 100644
--- a/src/managerimpl.h
+++ b/src/managerimpl.h
@@ -228,19 +228,15 @@ name);
    * Write by main thread only
    */
   unsigned short getSpkrVolume(void) { 
-    //ost::MutexLock m(_mutex); 
     return _spkr_volume; 
   }
   void setSpkrVolume(unsigned short spkr_vol) { 
-    //ost::MutexLock m(_mutex); 
     _spkr_volume = spkr_vol;
   }
   unsigned short getMicVolume(void) { 
-    //ost::MutexLock m(_mutex); 
     return _mic_volume;
   }
   void setMicVolume(unsigned short mic_vol) { 
-    //ost::MutexLock m(_mutex); 
     _mic_volume = _mic_volume_before_mute = mic_vol; 
   }
 
@@ -259,19 +255,19 @@ name);
 	inline bool isDriverLoaded (void) const { return _loaded; }
 	inline void loaded (bool l) { _loaded = l; }
 
-	/* 
-	 * Functions about audio device
-	 */
-/*
-	AudioDevice deviceList (int);
-	int deviceCount (void);
-	bool defaultDevice (int);
-*/	
 	/*
 	 * Init default values for the different fields
 	 */
 	void initConfigFile (void);
 
+  enum REGISTRATION_STATE {
+    UNREGISTERED,
+    REGISTERED,
+    FAILED
+  };
+
+  REGISTRATION_STATE getRegistrationState() { return _registerState; }
+
 private:
 
   
@@ -378,6 +374,9 @@ private:
   // Current callid 
 	CALLID _currentCallId;
 
+  // Register state
+  REGISTRATION_STATE _registerState;
+
 	/*
 	 * For the call timer
 	 */
-- 
GitLab