Coverage Report

Created: 2024-10-29 12:10

/root/bitcoin/src/node/interface_ui.cpp
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2010-2022 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 <node/interface_ui.h>
6
7
#include <util/string.h>
8
#include <util/translation.h>
9
10
#include <boost/signals2/optional_last_value.hpp>
11
#include <boost/signals2/signal.hpp>
12
13
using util::MakeUnorderedList;
14
15
CClientUIInterface uiInterface;
16
17
struct UISignals {
18
    boost::signals2::signal<CClientUIInterface::ThreadSafeMessageBoxSig, boost::signals2::optional_last_value<bool>> ThreadSafeMessageBox;
19
    boost::signals2::signal<CClientUIInterface::ThreadSafeQuestionSig, boost::signals2::optional_last_value<bool>> ThreadSafeQuestion;
20
    boost::signals2::signal<CClientUIInterface::InitMessageSig> InitMessage;
21
    boost::signals2::signal<CClientUIInterface::InitWalletSig> InitWallet;
22
    boost::signals2::signal<CClientUIInterface::NotifyNumConnectionsChangedSig> NotifyNumConnectionsChanged;
23
    boost::signals2::signal<CClientUIInterface::NotifyNetworkActiveChangedSig> NotifyNetworkActiveChanged;
24
    boost::signals2::signal<CClientUIInterface::NotifyAlertChangedSig> NotifyAlertChanged;
25
    boost::signals2::signal<CClientUIInterface::ShowProgressSig> ShowProgress;
26
    boost::signals2::signal<CClientUIInterface::NotifyBlockTipSig> NotifyBlockTip;
27
    boost::signals2::signal<CClientUIInterface::NotifyHeaderTipSig> NotifyHeaderTip;
28
    boost::signals2::signal<CClientUIInterface::BannedListChangedSig> BannedListChanged;
29
};
30
static UISignals g_ui_signals;
31
32
#define ADD_SIGNALS_IMPL_WRAPPER(signal_name)                                                                 \
33
    boost::signals2::connection CClientUIInterface::signal_name##_connect(std::function<signal_name##Sig> fn) \
34
0
    {                                                                                                         \
35
0
        return g_ui_signals.signal_name.connect(fn);                                                          \
36
0
    }
Unexecuted instantiation: _ZN18CClientUIInterface28ThreadSafeMessageBox_connectESt8functionIFbRK13bilingual_strRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEjEE
Unexecuted instantiation: _ZN18CClientUIInterface26ThreadSafeQuestion_connectESt8functionIFbRK13bilingual_strRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESB_jEE
Unexecuted instantiation: _ZN18CClientUIInterface19InitMessage_connectESt8functionIFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEE
Unexecuted instantiation: _ZN18CClientUIInterface18InitWallet_connectESt8functionIFvvEE
Unexecuted instantiation: _ZN18CClientUIInterface35NotifyNumConnectionsChanged_connectESt8functionIFviEE
Unexecuted instantiation: _ZN18CClientUIInterface34NotifyNetworkActiveChanged_connectESt8functionIFvbEE
Unexecuted instantiation: _ZN18CClientUIInterface26NotifyAlertChanged_connectESt8functionIFvvEE
Unexecuted instantiation: _ZN18CClientUIInterface20ShowProgress_connectESt8functionIFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEibEE
Unexecuted instantiation: _ZN18CClientUIInterface22NotifyBlockTip_connectESt8functionIFv20SynchronizationStatePK11CBlockIndexEE
Unexecuted instantiation: _ZN18CClientUIInterface23NotifyHeaderTip_connectESt8functionIFv20SynchronizationStatellbEE
Unexecuted instantiation: _ZN18CClientUIInterface25BannedListChanged_connectESt8functionIFvvEE
37
38
ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeMessageBox);
39
ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeQuestion);
40
ADD_SIGNALS_IMPL_WRAPPER(InitMessage);
41
ADD_SIGNALS_IMPL_WRAPPER(InitWallet);
42
ADD_SIGNALS_IMPL_WRAPPER(NotifyNumConnectionsChanged);
43
ADD_SIGNALS_IMPL_WRAPPER(NotifyNetworkActiveChanged);
44
ADD_SIGNALS_IMPL_WRAPPER(NotifyAlertChanged);
45
ADD_SIGNALS_IMPL_WRAPPER(ShowProgress);
46
ADD_SIGNALS_IMPL_WRAPPER(NotifyBlockTip);
47
ADD_SIGNALS_IMPL_WRAPPER(NotifyHeaderTip);
48
ADD_SIGNALS_IMPL_WRAPPER(BannedListChanged);
49
50
0
bool CClientUIInterface::ThreadSafeMessageBox(const bilingual_str& message, const std::string& caption, unsigned int style) { return g_ui_signals.ThreadSafeMessageBox(message, caption, style).value_or(false);}
51
0
bool CClientUIInterface::ThreadSafeQuestion(const bilingual_str& message, const std::string& non_interactive_message, const std::string& caption, unsigned int style) { return g_ui_signals.ThreadSafeQuestion(message, non_interactive_message, caption, style).value_or(false);}
52
0
void CClientUIInterface::InitMessage(const std::string& message) { return g_ui_signals.InitMessage(message); }
53
0
void CClientUIInterface::InitWallet() { return g_ui_signals.InitWallet(); }
54
0
void CClientUIInterface::NotifyNumConnectionsChanged(int newNumConnections) { return g_ui_signals.NotifyNumConnectionsChanged(newNumConnections); }
55
0
void CClientUIInterface::NotifyNetworkActiveChanged(bool networkActive) { return g_ui_signals.NotifyNetworkActiveChanged(networkActive); }
56
0
void CClientUIInterface::NotifyAlertChanged() { return g_ui_signals.NotifyAlertChanged(); }
57
0
void CClientUIInterface::ShowProgress(const std::string& title, int nProgress, bool resume_possible) { return g_ui_signals.ShowProgress(title, nProgress, resume_possible); }
58
0
void CClientUIInterface::NotifyBlockTip(SynchronizationState s, const CBlockIndex* i) { return g_ui_signals.NotifyBlockTip(s, i); }
59
0
void CClientUIInterface::NotifyHeaderTip(SynchronizationState s, int64_t height, int64_t timestamp, bool presync) { return g_ui_signals.NotifyHeaderTip(s, height, timestamp, presync); }
60
0
void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListChanged(); }
61
62
bool InitError(const bilingual_str& str)
63
0
{
64
0
    uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR);
65
0
    return false;
66
0
}
67
68
bool InitError(const bilingual_str& str, const std::vector<std::string>& details)
69
0
{
70
    // For now just flatten the list of error details into a string to pass to
71
    // the base InitError overload. In the future, if more init code provides
72
    // error details, the details could be passed separately from the main
73
    // message for rich display in the GUI. But currently the only init
74
    // functions which provide error details are ones that run during early init
75
    // before the GUI uiInterface is registered, so there's no point passing
76
    // main messages and details separately to uiInterface yet.
77
0
    return InitError(details.empty() ? str : strprintf(Untranslated("%s:\n%s"), str, MakeUnorderedList(details)));
78
0
}
79
80
void InitWarning(const bilingual_str& str)
81
0
{
82
0
    uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_WARNING);
83
0
}