LCOV - code coverage report
Current view: top level - src/common - interfaces.cpp (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 58.3 % 12 7
Test Date: 2026-08-07 06:33:33 Functions: 55.6 % 9 5
Branches: 33.3 % 6 2

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2021-present 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/echo.h>    // IWYU pragma: associated
       6                 :             : #include <interfaces/handler.h> // IWYU pragma: associated
       7                 :             : 
       8                 :             : #include <util/btcsignals.h>
       9                 :             : 
      10                 :             : #include <memory>
      11                 :             : #include <utility>
      12                 :             : 
      13                 :             : namespace common {
      14                 :             : namespace {
      15                 :             : class CleanupHandler : public interfaces::Handler
      16                 :             : {
      17                 :             : public:
      18                 :           1 :     explicit CleanupHandler(std::function<void()> cleanup) : m_cleanup(std::move(cleanup)) {}
      19         [ -  + ]:           2 :     ~CleanupHandler() override { if (!m_cleanup) return; m_cleanup(); m_cleanup = nullptr; }
      20         [ #  # ]:           0 :     void disconnect() override { if (!m_cleanup) return; m_cleanup(); m_cleanup = nullptr; }
      21                 :             :     std::function<void()> m_cleanup;
      22                 :             : };
      23                 :             : 
      24                 :             : class SignalHandler : public interfaces::Handler
      25                 :             : {
      26                 :             : public:
      27                 :           0 :     explicit SignalHandler(btcsignals::connection connection) : m_connection(std::move(connection)) {}
      28                 :             : 
      29                 :           0 :     void disconnect() override { m_connection.disconnect(); }
      30                 :             : 
      31                 :             :     btcsignals::scoped_connection m_connection;
      32                 :             : };
      33                 :             : 
      34                 :           6 : class EchoImpl : public interfaces::Echo
      35                 :             : {
      36                 :             : public:
      37         [ -  + ]:           6 :     std::string echo(const std::string& echo) override { return echo; }
      38                 :             : };
      39                 :             : } // namespace
      40                 :             : } // namespace common
      41                 :             : 
      42                 :             : namespace interfaces {
      43                 :           1 : std::unique_ptr<Handler> MakeCleanupHandler(std::function<void()> cleanup)
      44                 :             : {
      45                 :           1 :     return std::make_unique<common::CleanupHandler>(std::move(cleanup));
      46                 :             : }
      47                 :             : 
      48                 :           0 : std::unique_ptr<Handler> MakeSignalHandler(btcsignals::connection connection)
      49                 :             : {
      50                 :           0 :     return std::make_unique<common::SignalHandler>(std::move(connection));
      51                 :             : }
      52                 :             : 
      53                 :           6 : std::unique_ptr<Echo> MakeEcho() { return std::make_unique<common::EchoImpl>(); }
      54                 :             : } // namespace interfaces
        

Generated by: LCOV version 2.0-1