From 6274896605ba20c795fd42e4ce81b8714af41d10 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Tue, 31 Jul 2018 11:22:40 -0400
Subject: [PATCH] lrc: add the possibility to know if daemon is connected

Change-Id: I1e4e4d9a48a393b91cc62353ce6c0153810881ce
---
 src/api/lrc.h | 14 ++++++++++++++
 src/lrc.cpp   | 29 ++++++++++++++++++++++++++++-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/src/api/lrc.h b/src/api/lrc.h
index ae401962..be69debd 100644
--- a/src/api/lrc.h
+++ b/src/api/lrc.h
@@ -56,6 +56,20 @@ public:
      */
     DataTransferModel& getDataTransferModel() const;
 
+    /**
+     * Inform the daemon that the connectivity changed
+     */
+    void connectivityChanged() const;
+
+    /**
+     * Test connection with daemon
+     */
+    static bool isConnected();
+    /**
+     * Can communicate with the daemon via dbus
+     */
+    static bool dbusIsValid();
+
 private:
     std::unique_ptr<LrcPimpl> lrcPimpl_;
 };
diff --git a/src/lrc.cpp b/src/lrc.cpp
index 15a7a0d0..9ace50f8 100644
--- a/src/lrc.cpp
+++ b/src/lrc.cpp
@@ -1,5 +1,5 @@
 /****************************************************************************
- *   Copyright (C) 2017-2018 Savoir-faire Linux                                  *
+ *   Copyright (C) 2017-2018 Savoir-faire Linux                             *
  *   Author : Nicolas Jäger <nicolas.jager@savoirfairelinux.com>            *
  *   Author : Sébastien Blin <sebastien.blin@savoirfairelinux.com>          *
  *                                                                          *
@@ -24,6 +24,7 @@
 #include "api/behaviorcontroller.h"
 #include "database.h"
 #include "callbackshandler.h"
+#include "dbus/configurationmanager.h"
 #include "dbus/instancemanager.h"
 
 namespace lrc
@@ -75,6 +76,32 @@ Lrc::getDataTransferModel() const
     return *lrcPimpl_->dataTransferModel;
 }
 
+void
+Lrc::connectivityChanged() const
+{
+    ConfigurationManager::instance().connectivityChanged();
+}
+
+bool
+Lrc::isConnected()
+{
+#ifdef ENABLE_LIBWRAP
+    return true;
+#else
+    return ConfigurationManager::instance().connection().isConnected();
+#endif
+}
+
+bool
+Lrc::dbusIsValid()
+{
+#ifdef ENABLE_LIBWRAP
+    return true;
+#else
+    return ConfigurationManager::instance().isValid();
+#endif
+}
+
 LrcPimpl::LrcPimpl(Lrc& linked)
 : linked(linked)
 , behaviorController(std::make_unique<BehaviorController>())
-- 
GitLab