util: add isConnected() in signal::Connection and signal::ScopedConnection

Change-Id: Iddf2a084ccf137a691cd85c54003182acf0e5afd
Refs: #2308
diff --git a/src/util/signal-connection.cpp b/src/util/signal-connection.cpp
index 8660e4d..7c74246 100644
--- a/src/util/signal-connection.cpp
+++ b/src/util/signal-connection.cpp
@@ -46,6 +46,12 @@
 }
 
 bool
+Connection::isConnected() const
+{
+  return !m_disconnect.expired();
+}
+
+bool
 Connection::operator==(const Connection& other) const
 {
   shared_ptr<function<void()>> f1 = m_disconnect.lock();
diff --git a/src/util/signal-connection.hpp b/src/util/signal-connection.hpp
index 1276182..f2ac45e 100644
--- a/src/util/signal-connection.hpp
+++ b/src/util/signal-connection.hpp
@@ -45,6 +45,12 @@
   void
   disconnect();
 
+  /** \brief check if connected to the signal
+   *  \return false if disconnected from the signal
+   */
+  bool
+  isConnected() const;
+
   /** \brief compare for equality
    *
    *  Two connections are equal if they both refer to the same connection that isn't disconnected,
diff --git a/src/util/signal-scoped-connection.cpp b/src/util/signal-scoped-connection.cpp
index ae90c5f..a0f2d1c 100644
--- a/src/util/signal-scoped-connection.cpp
+++ b/src/util/signal-scoped-connection.cpp
@@ -61,6 +61,12 @@
   m_connection.disconnect();
 }
 
+bool
+ScopedConnection::isConnected() const
+{
+  return m_connection.isConnected();
+}
+
 void
 ScopedConnection::release()
 {
diff --git a/src/util/signal-scoped-connection.hpp b/src/util/signal-scoped-connection.hpp
index 9104791..80717e5 100644
--- a/src/util/signal-scoped-connection.hpp
+++ b/src/util/signal-scoped-connection.hpp
@@ -61,6 +61,13 @@
   void
   disconnect();
 
+  /** \brief check if the connection is connected to the signal
+   *  \return false when a default-constructed connection is used, the connection is released,
+   *          or the connection is disconnected
+   */
+  bool
+  isConnected() const;
+
   /** \brief releases the connection so that it won't be disconnected
    *         when this ScopedConnection is destructed
    */