From f8a7074051ddfa582c6502adba504aed3c648c25 Mon Sep 17 00:00:00 2001
From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
Date: Mon, 18 Dec 2017 13:26:22 -0500
Subject: [PATCH] debug: add few debug line/helpers

make dev life easier during debugging steps.

Change-Id: I762763436b4aa0800da6d926230c011649a44e88
Tuleap: #1575
Reviewed-by: Philippe Gorley <philippe.gorley@savoirfairelinux.com>
---
 src/account.h               |  7 +++++++
 src/manager.cpp             |  4 +++-
 src/ringdht/ringaccount.cpp | 11 ++++++-----
 src/sip/sipaccount.cpp      |  5 ++++-
 4 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/account.h b/src/account.h
index 331ad3cd48..4b100db831 100644
--- a/src/account.h
+++ b/src/account.h
@@ -477,6 +477,13 @@ class Account : public Serializable, public std::enable_shared_from_this<Account
         void setAllCodecsActive(MediaType mediaType, bool active);
 };
 
+static inline std::ostream&
+operator<< (std::ostream& os, const Account& acc)
+{
+    os << "[Account " << acc.getAccountID() << "] ";
+    return os;
+}
+
 } // namespace ring
 
 #endif
diff --git a/src/manager.cpp b/src/manager.cpp
index b4f30d7a5f..618c2228ef 100644
--- a/src/manager.cpp
+++ b/src/manager.cpp
@@ -851,6 +851,9 @@ Manager::outgoingCall(const std::string& preferred_account_id,
         return {};
     }
 
+    RING_DBG() << "try outgoing call to '" << to << "'"
+               << " with preferred account '" << preferred_account_id << "'";
+
     std::string current_call_id(getCurrentCallId());
     std::string to_cleaned = hookPreference.getNumberAddPrefix() + trim(to);
     std::shared_ptr<Call> call;
@@ -859,7 +862,6 @@ Manager::outgoingCall(const std::string& preferred_account_id,
         /* RING_WARN: after this call the account_id is obsolete
          * as the factory may decide to use another account (like IP2IP).
          */
-        RING_DBG("New outgoing call to %s", to_cleaned.c_str());
         call = newOutgoingCall(to_cleaned, preferred_account_id, volatileCallDetails);
     } catch (const std::exception &e) {
         RING_ERR("%s", e.what());
diff --git a/src/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp
index 88a2141818..52dbce05c0 100644
--- a/src/ringdht/ringaccount.cpp
+++ b/src/ringdht/ringaccount.cpp
@@ -330,10 +330,11 @@ RingAccount::newIncomingCall(const std::string& from, const std::map<std::string
 
 template <>
 std::shared_ptr<SIPCall>
-RingAccount::newOutgoingCall(const std::string& toUrl, const std::map<std::string, std::string>& volatileCallDetails)
+RingAccount::newOutgoingCall(const std::string& toUrl,
+                             const std::map<std::string, std::string>& volatileCallDetails)
 {
-    auto sufix = stripPrefix(toUrl);
-    RING_DBG("Calling DHT peer %s", sufix.c_str());
+    auto suffix = stripPrefix(toUrl);
+    RING_DBG() << *this << "Calling DHT peer " << suffix;
     auto& manager = Manager::instance();
     auto call = manager.callFactory.newCall<SIPCall, RingAccount>(*this, manager.getNewCallID(),
                                                                   Call::CallType::OUTGOING,
@@ -344,12 +345,12 @@ RingAccount::newOutgoingCall(const std::string& toUrl, const std::map<std::strin
     call->initRecFilename(toUrl);
 
     try {
-        const std::string toUri = parseRingUri(sufix);
+        const std::string toUri = parseRingUri(suffix);
         startOutgoingCall(call, toUri);
     } catch (...) {
 #if HAVE_RINGNS
         std::weak_ptr<RingAccount> wthis_ = std::static_pointer_cast<RingAccount>(shared_from_this());
-        NameDirectory::lookupUri(sufix, nameServer_, [wthis_,call](const std::string& result,
+        NameDirectory::lookupUri(suffix, nameServer_, [wthis_,call](const std::string& result,
                                                                    NameDirectory::Response response) {
             // we may run inside an unknown thread, but following code must be called in main thread
             runOnMainThread([=, &result]() {
diff --git a/src/sip/sipaccount.cpp b/src/sip/sipaccount.cpp
index b388337fa2..c296abb015 100644
--- a/src/sip/sipaccount.cpp
+++ b/src/sip/sipaccount.cpp
@@ -170,11 +170,14 @@ SIPAccount::newIncomingCall(const std::string& from UNUSED, const std::map<std::
 
 template <>
 std::shared_ptr<SIPCall>
-SIPAccount::newOutgoingCall(const std::string& toUrl, const std::map<std::string, std::string>& volatileCallDetails)
+SIPAccount::newOutgoingCall(const std::string& toUrl,
+                            const std::map<std::string, std::string>& volatileCallDetails)
 {
     std::string to;
     int family;
 
+    RING_DBG() << *this << "Calling SIP peer " << toUrl;
+
     auto& manager = Manager::instance();
     auto call = manager.callFactory.newCall<SIPCall, SIPAccount>(*this, manager.getNewCallID(),
                                                                  Call::CallType::OUTGOING,
-- 
GitLab