From 9efa1abaa0ca14b5ec3c1626e604f37eb07967c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Thu, 4 Mar 2021 19:38:24 -0500
Subject: [PATCH] call factory: remove newCall, cleanup

Change-Id: Ia95bd71499b502f4e6d3df690537a6e1c91422d0
---
 src/call_factory.h          | 19 ++-----------------
 src/jamidht/jamiaccount.cpp | 21 ++++++++++++++-------
 src/sip/sipaccount.cpp      |  4 ++--
 3 files changed, 18 insertions(+), 26 deletions(-)

diff --git a/src/call_factory.h b/src/call_factory.h
index 4a2225c92f..0b2164b600 100644
--- a/src/call_factory.h
+++ b/src/call_factory.h
@@ -41,27 +41,15 @@ public:
     CallFactory(std::mt19937_64& rand) : rand_(rand) {}
 
     /**
-     * Create a new call instance.
+     * Create and register a new SIPCall instance.
      * @param account Account used to create this call
-     * @param id Unique identifier of the call
-     * @param type Set the call type
+     * @param type The call type (incoming/outgoing)
      * @param details Call details
      */
     std::shared_ptr<SIPCall> newSipCall(const std::shared_ptr<SIPAccountBase>& account,
                                         Call::CallType type,
                                         const std::map<std::string, std::string>& details = {});
 
-    template<class C>
-    std::shared_ptr<C> newCall(std::shared_ptr<Account> account,
-                                  Call::CallType type,
-                                  const std::map<std::string, std::string>& details = {})
-    {
-        if (auto base = std::dynamic_pointer_cast<SIPAccountBase>(account)) {
-            return std::dynamic_pointer_cast<C>(newSipCall(base, type, details));
-        }
-        return nullptr;
-    }
-
     std::string getNewCallID() const;
 
     /**
@@ -126,7 +114,6 @@ public:
     std::size_t callCount(Call::LinkType link) const;
 
 private:
-
     /**
      * @brief Get the calls map
      * @param link The call type
@@ -136,10 +123,8 @@ private:
     const CallMap* getMap_(Call::LinkType link) const
     {
         auto const& itermap = callMaps_.find(link);
-
         if (itermap != callMaps_.cend())
             return &itermap->second;
-
         return nullptr;
     }
 
diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp
index 41b799750d..316dd6aea5 100644
--- a/src/jamidht/jamiaccount.cpp
+++ b/src/jamidht/jamiaccount.cpp
@@ -368,7 +368,9 @@ JamiAccount::newIncomingCall(const std::string& from,
                     if (cit->transport != sipTr)
                         continue;
 
-                    auto call = Manager::instance().callFactory.newCall<SIPCall>(shared(), Call::CallType::INCOMING);
+                    auto call = Manager::instance()
+                                    .callFactory.newSipCall(shared(),
+                                                                  Call::CallType::INCOMING);
                     call->setPeerUri(RING_URI_PREFIX + from);
                     call->setPeerNumber(from);
                     call->updateDetails(details);
@@ -407,7 +409,9 @@ JamiAccount::newOutgoingCall(std::string_view toUrl,
     auto suffix = stripPrefix(toUrl);
     JAMI_DBG() << *this << "Calling DHT peer " << suffix;
     auto& manager = Manager::instance();
-    auto call = manager.callFactory.newCall<SIPCall>(shared(), Call::CallType::OUTGOING, volatileCallDetails);
+    auto call = manager.callFactory.newSipCall(shared(),
+                                                     Call::CallType::OUTGOING,
+                                                     volatileCallDetails);
     call->setIPToIP(true);
     call->setSecure(isTlsEnabled());
 
@@ -509,7 +513,9 @@ JamiAccount::startOutgoingCall(const std::shared_ptr<SIPCall>& call, const std::
     // NOTE: dummyCall is a call used to avoid to mark the call as failed if the
     // cached connection is failing with ICE (close event still not detected).
     auto& manager = Manager::instance();
-    auto dummyCall = manager.callFactory.newCall<SIPCall>(shared(), Call::CallType::OUTGOING, call->getDetails());
+    auto dummyCall = manager.callFactory.newSipCall(shared(),
+                                                          Call::CallType::OUTGOING,
+                                                          call->getDetails());
     dummyCall->setIPToIP(true);
     dummyCall->setSecure(isTlsEnabled());
     call->addSubCall(*dummyCall);
@@ -531,7 +537,7 @@ JamiAccount::startOutgoingCall(const std::shared_ptr<SIPCall>& call, const std::
                 return;
 
             auto dev_call = Manager::instance()
-                               .callFactory.newCall<SIPCall>(shared(), Call::CallType::OUTGOING, call->getDetails());
+                               .callFactory.newSipCall(shared(), Call::CallType::OUTGOING, call->getDetails());
             dev_call->setIPToIP(true);
             dev_call->setSecure(isTlsEnabled());
             dev_call->setState(Call::ConnectionState::TRYING);
@@ -575,7 +581,9 @@ JamiAccount::startOutgoingCall(const std::shared_ptr<SIPCall>& call, const std::
         JAMI_WARN("[call %s] A channeled socket is detected with this peer.",
                   call->getCallId().c_str());
 
-        auto dev_call = manager.callFactory.newCall<SIPCall>(shared(), Call::CallType::OUTGOING, call->getDetails());
+        auto dev_call = manager.callFactory.newSipCall(shared(),
+                                                             Call::CallType::OUTGOING,
+                                                             call->getDetails());
         dev_call->setIPToIP(true);
         dev_call->setSecure(isTlsEnabled());
         dev_call->setTransport(transport);
@@ -2397,8 +2405,7 @@ JamiAccount::incomingCall(dht::IceCandidates&& msg,
                           const std::shared_ptr<dht::crypto::Certificate>& from_cert,
                           const dht::InfoHash& from)
 {
-    auto call = Manager::instance()
-                       .callFactory.newCall<SIPCall>(shared(), Call::CallType::INCOMING);
+    auto call = Manager::instance().callFactory.newSipCall(shared(), Call::CallType::INCOMING);
     if (!call) {
         return;
     }
diff --git a/src/sip/sipaccount.cpp b/src/sip/sipaccount.cpp
index 30e2209adc..1375ccd441 100644
--- a/src/sip/sipaccount.cpp
+++ b/src/sip/sipaccount.cpp
@@ -180,7 +180,7 @@ SIPAccount::newIncomingCall(const std::string& from UNUSED,
                             const std::shared_ptr<SipTransport>&)
 {
     auto& manager = Manager::instance();
-    return manager.callFactory.newCall<SIPCall>(shared(), Call::CallType::INCOMING, details);
+    return manager.callFactory.newSipCall(shared(), Call::CallType::INCOMING, details);
 }
 
 template<>
@@ -194,7 +194,7 @@ SIPAccount::newOutgoingCall(std::string_view toUrl,
     JAMI_DBG() << *this << "Calling SIP peer " << toUrl;
 
     auto& manager = Manager::instance();
-    auto call = manager.callFactory.newCall<SIPCall>(shared(), Call::CallType::OUTGOING, volatileCallDetails);
+    auto call = manager.callFactory.newSipCall(shared(), Call::CallType::OUTGOING, volatileCallDetails);
     call->setSecure(isTlsEnabled());
 
     if (isIP2IP()) {
-- 
GitLab