From 2c4cef2a2c928d922bc387a1c558327ae906cde4 Mon Sep 17 00:00:00 2001
From: yanmorin <yanmorin>
Date: Fri, 30 Sep 2005 18:21:39 +0000
Subject: [PATCH] Correct two calls in the same time hold the first one

---
 src/gui/server/guiserverimpl.cpp | 13 +++++++++++++
 src/gui/server/guiserverimpl.h   |  1 +
 src/gui/server/request.cpp       | 22 +++++++++++++++++++++-
 src/gui/server/request.h         |  4 +++-
 src/managerimpl.cpp              | 17 ++++++++++++++---
 src/managerimpl.h                |  2 ++
 6 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/src/gui/server/guiserverimpl.cpp b/src/gui/server/guiserverimpl.cpp
index e8c1641ec6..c9fc79525d 100644
--- a/src/gui/server/guiserverimpl.cpp
+++ b/src/gui/server/guiserverimpl.cpp
@@ -162,6 +162,19 @@ GUIServerImpl::refuseCall(const std::string& callId)
   }
   return false;
 }
+bool 
+GUIServerImpl::transferCall(const std::string& callId, const std::string& to)
+{
+  try {
+    short id = getIdFromCallId(callId);
+    if (GuiFramework::transferCall(id, to)) {
+      return true;
+    }
+  } catch(...) {
+    return false;
+  }
+  return false;
+}
 
 bool
 GUIServerImpl::holdCall(const std::string& callId) 
diff --git a/src/gui/server/guiserverimpl.h b/src/gui/server/guiserverimpl.h
index 6f4e952462..0d16532d36 100644
--- a/src/gui/server/guiserverimpl.h
+++ b/src/gui/server/guiserverimpl.h
@@ -75,6 +75,7 @@ arg);
   bool holdCall(const std::string& callId);
   bool unholdCall(const std::string& callId);
   bool hangupCall(const std::string& callId);
+  bool transferCall(const std::string& callId, const std::string& to);
   bool dtmfCall(const std::string& callId, const std::string& dtmfKey);
   bool hangupAll();
   bool getCurrentCallId(std::string& callId);
diff --git a/src/gui/server/request.cpp b/src/gui/server/request.cpp
index bf08c80669..8c29137917 100644
--- a/src/gui/server/request.cpp
+++ b/src/gui/server/request.cpp
@@ -66,10 +66,30 @@ RequestUnhold::execute()
   return message("500","Server Error");
 }
 
+RequestTransfer::RequestTransfer(const std::string &sequenceId, 
+    const TokenList& argList) : RequestGlobalCall(sequenceId, argList)
+{
+  TokenList::iterator iter = _argList.begin();
+
+  // check for the transfer destination
+  bool argsAreValid = false;
+  if (iter != _argList.end()) {
+    _destination = *iter;
+    _argList.pop_front();
+    argsAreValid = true;
+  }
+  if (!argsAreValid) {
+    throw RequestConstructorException();
+  }
+}
+
 ResponseMessage
 RequestTransfer::execute()
 {
-  return message("200","TODO");
+  if ( GUIServer::instance().transferCall(_callId, _destination) ) {
+    return message("200", "OK");
+  }
+  return message("500","Server Error");
 }
 
 ResponseMessage
diff --git a/src/gui/server/request.h b/src/gui/server/request.h
index d8f131764f..4d2663f407 100644
--- a/src/gui/server/request.h
+++ b/src/gui/server/request.h
@@ -136,8 +136,10 @@ public:
 };
 class RequestTransfer : public RequestGlobalCall {
 public:
-  RequestTransfer(const std::string &sequenceId, const TokenList& argList) : RequestGlobalCall(sequenceId,argList) {}
+  RequestTransfer(const std::string &sequenceId, const TokenList& argList);
   ResponseMessage execute();
+private:
+  std::string _destination;
 };
 class RequestHangup : public RequestGlobalCall {
 public:
diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp
index 0dc578b259..3e1910d37b 100644
--- a/src/managerimpl.cpp
+++ b/src/managerimpl.cpp
@@ -405,7 +405,8 @@ ManagerImpl::answerCall (short id)
 	call->setStatus(string(CONNECTED_STATUS));
 	call->setState(Answered);
 	ringtone(false);
-  setCurrentCallId(id);
+
+  switchCall(id);
 	return call->answer();
 }
 
@@ -676,8 +677,8 @@ ManagerImpl::peerAnsweredCall (short id)
 
 	call->setState(Answered);
 	//if (isCurrentId(id)) {
-    setCurrentCallId(id);
-		_gui->peerAnsweredCall(id);
+  switchCall(id);
+  _gui->peerAnsweredCall(id);
 	//}
 }
 
@@ -1297,4 +1298,14 @@ ManagerImpl::getConfigList(const std::string& sequenceId, const std::string& nam
   return returnValue;
 }
 
+void 
+ManagerImpl::switchCall(short id)
+{
+  short currentCallId = getCurrentCallId();
+  if (currentCallId!=0 && id!=currentCallId) {
+    onHoldCall(currentCallId);
+  }
+  setCurrentCallId(id);
+}
+
 // EOF
diff --git a/src/managerimpl.h b/src/managerimpl.h
index 5ba2947b11..88589f6670 100644
--- a/src/managerimpl.h
+++ b/src/managerimpl.h
@@ -379,6 +379,8 @@ private:
 
   Conf::ConfigTree _config;
 
+  void switchCall(short id);
+
 #ifdef USE_ZEROCONF
   // DNSService contain every zeroconf services
   //  configuration detected on the network
-- 
GitLab