Branch data Line data Source code
1 : : // Copyright (c) 2023 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 : : #ifndef BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H 6 : : #define BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H 7 : : 8 : : #include <util/translation.h> 9 : : 10 : : #include <cstdint> 11 : : #include <string> 12 : : #include <variant> 13 : : 14 : : class CBlockIndex; 15 : : enum class SynchronizationState; 16 : : 17 : : namespace kernel { 18 : : 19 : : //! Result type for use with std::variant to indicate that an operation should be interrupted. 20 : : struct Interrupted{}; 21 : : 22 : : //! Simple result type for functions that need to propagate an interrupt status and don't have other return values. 23 : : using InterruptResult = std::variant<std::monostate, Interrupted>; 24 : : 25 : : template <typename T> 26 : 0 : bool IsInterrupted(const T& result) 27 : : { 28 : 0 : return std::holds_alternative<kernel::Interrupted>(result); 29 : : } 30 : : 31 : : /** 32 : : * A base class defining functions for notifying about certain kernel 33 : : * events. 34 : : */ 35 : 0 : class Notifications 36 : : { 37 : : public: 38 : 0 : virtual ~Notifications(){}; 39 : : 40 : 0 : [[nodiscard]] virtual InterruptResult blockTip(SynchronizationState state, CBlockIndex& index) { return {}; } 41 : 0 : virtual void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) {} 42 : 0 : virtual void progress(const bilingual_str& title, int progress_percent, bool resume_possible) {} 43 : 0 : virtual void warning(const bilingual_str& warning) {} 44 : : 45 : : //! The flush error notification is sent to notify the user that an error 46 : : //! occurred while flushing block data to disk. Kernel code may ignore flush 47 : : //! errors that don't affect the immediate operation it is trying to 48 : : //! perform. Applications can choose to handle the flush error notification 49 : : //! by logging the error, or notifying the user, or triggering an early 50 : : //! shutdown as a precaution against causing more errors. 51 : 0 : virtual void flushError(const std::string& debug_message) {} 52 : : 53 : : //! The fatal error notification is sent to notify the user when an error 54 : : //! occurs in kernel code that can't be recovered from. After this 55 : : //! notification is sent, whatever function triggered the error should also 56 : : //! return an error code or raise an exception. Applications can choose to 57 : : //! handle the fatal error notification by logging the error, or notifying 58 : : //! the user, or triggering an early shutdown as a precaution against 59 : : //! causing more errors. 60 : 0 : virtual void fatalError(const std::string& debug_message, const bilingual_str& user_message = {}) {} 61 : : }; 62 : : } // namespace kernel 63 : : 64 : : #endif // BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H