LCOV - code coverage report
Current view: top level - src/interfaces - handler.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 4 10 40.0 %
Date: 2020-09-26 01:30:44 Functions: 6 14 42.9 %

          Line data    Source code
       1             : // Copyright (c) 2018-2020 The Bitcoin Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #include <interfaces/handler.h>
       6             : 
       7             : #include <util/memory.h>
       8             : 
       9             : #include <boost/signals2/connection.hpp>
      10             : #include <utility>
      11             : 
      12             : namespace interfaces {
      13             : namespace {
      14             : 
      15           0 : class HandlerImpl : public Handler
      16             : {
      17             : public:
      18           0 :     explicit HandlerImpl(boost::signals2::connection connection) : m_connection(std::move(connection)) {}
      19             : 
      20           0 :     void disconnect() override { m_connection.disconnect(); }
      21             : 
      22             :     boost::signals2::scoped_connection m_connection;
      23             : };
      24             : 
      25             : class CleanupHandler : public Handler
      26             : {
      27             : public:
      28           2 :     explicit CleanupHandler(std::function<void()> cleanup) : m_cleanup(std::move(cleanup)) {}
      29           3 :     ~CleanupHandler() override { if (!m_cleanup) return; m_cleanup(); m_cleanup = nullptr; }
      30           0 :     void disconnect() override { if (!m_cleanup) return; m_cleanup(); m_cleanup = nullptr; }
      31             :     std::function<void()> m_cleanup;
      32             : };
      33             : 
      34             : } // namespace
      35             : 
      36           0 : std::unique_ptr<Handler> MakeHandler(boost::signals2::connection connection)
      37             : {
      38           0 :     return MakeUnique<HandlerImpl>(std::move(connection));
      39             : }
      40             : 
      41           1 : std::unique_ptr<Handler> MakeHandler(std::function<void()> cleanup)
      42             : {
      43           1 :     return MakeUnique<CleanupHandler>(std::move(cleanup));
      44             : }
      45             : 
      46             : } // namespace interfaces

Generated by: LCOV version 1.15