比特币源码分析5

专门看一个类CMainSignals

public:

    /** Register a CScheduler to give callbacks which should run in the background (may only be called once) */

    void RegisterBackgroundSignalScheduler(CScheduler& scheduler);

    /** Unregister a CScheduler to give callbacks which should run in the background - these callbacks will now be dropped! */

    void UnregisterBackgroundSignalScheduler();

    /** Call any remaining callbacks on the calling thread */

    void FlushBackgroundCallbacks();

    size_t CallbacksPending();

    /** Register with mempool to call TransactionRemovedFromMempool callbacks */

    void RegisterWithMempoolSignals(CTxMemPool& pool);

    /** Unregister with mempool */

    void UnregisterWithMempoolSignals(CTxMemPool& pool);

    void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload);

    void TransactionAddedToMempool(const CTransactionRef &);

    void BlockConnected(const std::shared_ptr &, const CBlockIndex *pindex, const std::shared_ptr> &);

    void BlockDisconnected(const std::shared_ptr &);

    void ChainStateFlushed(const CBlockLocator &);

    void BlockChecked(const CBlock&, const CValidationState&);

    void NewPoWValidBlock(const CBlockIndex *, const std::shared_ptr&);

这个类里面有许多注册函数:
当然我们可以选择一个注册函数往里看,

void RegisterBackgroundSignalScheduler(CScheduler& scheduler);就这个吧。

他生成了一个struct MainSignalsInstance 实例

这个结构体下边

boost::signals2::signal UpdatedBlockTip;

    boost::signals2::signal TransactionAddedToMempool;

    boost::signals2::signal &, const CBlockIndex *pindex, const std::vector&)> BlockConnected;

    boost::signals2::signal &)> BlockDisconnected;

    boost::signals2::signal TransactionRemovedFromMempool;

    boost::signals2::signal ChainStateFlushed;

    boost::signals2::signal BlockChecked;

    boost::signals2::signal&)> NewPoWValidBlock;

定义了一些信号。这又是传统的信号槽机制。一旦触发信号,所有关联的函数都会被调用

你可能感兴趣的:(比特币源码分析5)