refactor: Add InitContext function to initialize NodeContext with global pointers

Having InitContext() avoids the need to add duplicate code to src/init/*.cpp
files in the next commit. It also lets these files avoid referencing global
variables like gArgs.

There is no change in behavior in this commit.
This commit is contained in:
Ryan Ofsky
2023-07-07 17:32:54 -04:00
parent feeb7b816a
commit 213542b625
6 changed files with 15 additions and 8 deletions

View File

@@ -192,6 +192,10 @@ static void RemovePidFile(const ArgsManager& args)
} }
} }
void InitContext(NodeContext& node)
{
node.args = &gArgs;
}
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //

View File

@@ -26,6 +26,9 @@ namespace node {
struct NodeContext; struct NodeContext;
} // namespace node } // namespace node
/** Initialize node context variables. */
void InitContext(node::NodeContext& node);
/** Interrupt threads */ /** Interrupt threads */
void Interrupt(node::NodeContext& node); void Interrupt(node::NodeContext& node);
void Shutdown(node::NodeContext& node); void Shutdown(node::NodeContext& node);

View File

@@ -2,7 +2,7 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <common/args.h> #include <init.h>
#include <interfaces/chain.h> #include <interfaces/chain.h>
#include <interfaces/echo.h> #include <interfaces/echo.h>
#include <interfaces/init.h> #include <interfaces/init.h>
@@ -23,7 +23,7 @@ class BitcoinGuiInit : public interfaces::Init
public: public:
BitcoinGuiInit(const char* arg0) : m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this)) BitcoinGuiInit(const char* arg0) : m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this))
{ {
m_node.args = &gArgs; InitContext(m_node);
m_node.init = this; m_node.init = this;
} }
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); } std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }

View File

@@ -2,7 +2,7 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <common/args.h> #include <init.h>
#include <interfaces/chain.h> #include <interfaces/chain.h>
#include <interfaces/echo.h> #include <interfaces/echo.h>
#include <interfaces/init.h> #include <interfaces/init.h>
@@ -25,7 +25,7 @@ public:
: m_node(node), : m_node(node),
m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this)) m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this))
{ {
m_node.args = &gArgs; InitContext(m_node);
m_node.init = this; m_node.init = this;
} }
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); } std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }

View File

@@ -2,7 +2,7 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <common/args.h> #include <init.h>
#include <interfaces/chain.h> #include <interfaces/chain.h>
#include <interfaces/echo.h> #include <interfaces/echo.h>
#include <interfaces/init.h> #include <interfaces/init.h>
@@ -20,7 +20,7 @@ class BitcoinQtInit : public interfaces::Init
public: public:
BitcoinQtInit() BitcoinQtInit()
{ {
m_node.args = &gArgs; InitContext(m_node);
m_node.init = this; m_node.init = this;
} }
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); } std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }

View File

@@ -2,7 +2,7 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <common/args.h> #include <init.h>
#include <interfaces/chain.h> #include <interfaces/chain.h>
#include <interfaces/echo.h> #include <interfaces/echo.h>
#include <interfaces/init.h> #include <interfaces/init.h>
@@ -22,7 +22,7 @@ class BitcoindInit : public interfaces::Init
public: public:
BitcoindInit(NodeContext& node) : m_node(node) BitcoindInit(NodeContext& node) : m_node(node)
{ {
m_node.args = &gArgs; InitContext(m_node);
m_node.init = this; m_node.init = this;
} }
std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); } std::unique_ptr<interfaces::Node> makeNode() override { return interfaces::MakeNode(m_node); }