Changeset View
Changeset View
Standalone View
Standalone View
src/util/system.h
Show All 13 Lines | |||||
#include <config/bitcoin-config.h> | #include <config/bitcoin-config.h> | ||||
#endif | #endif | ||||
#include <attributes.h> | #include <attributes.h> | ||||
#include <compat.h> | #include <compat.h> | ||||
#include <compat/assumptions.h> | #include <compat/assumptions.h> | ||||
#include <fs.h> | #include <fs.h> | ||||
#include <logging.h> | #include <logging.h> | ||||
#include <optional.h> | |||||
#include <sync.h> | #include <sync.h> | ||||
#include <tinyformat.h> | #include <tinyformat.h> | ||||
#include <util/settings.h> | #include <util/settings.h> | ||||
#include <util/threadnames.h> | #include <util/threadnames.h> | ||||
#include <util/time.h> | #include <util/time.h> | ||||
#include <boost/thread/condition_variable.hpp> // for boost::thread_interrupted | #include <boost/thread/condition_variable.hpp> // for boost::thread_interrupted | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | struct SectionInfo { | ||||
std::string m_name; | std::string m_name; | ||||
std::string m_file; | std::string m_file; | ||||
int m_line; | int m_line; | ||||
}; | }; | ||||
class ArgsManager { | class ArgsManager { | ||||
public: | public: | ||||
enum Flags { | enum Flags { | ||||
NONE = 0x00, | |||||
// Boolean options can accept negation syntax -noOPTION or -noOPTION=1 | // Boolean options can accept negation syntax -noOPTION or -noOPTION=1 | ||||
ALLOW_BOOL = 0x01, | ALLOW_BOOL = 0x01, | ||||
ALLOW_INT = 0x02, | ALLOW_INT = 0x02, | ||||
ALLOW_STRING = 0x04, | ALLOW_STRING = 0x04, | ||||
ALLOW_ANY = ALLOW_BOOL | ALLOW_INT | ALLOW_STRING, | ALLOW_ANY = ALLOW_BOOL | ALLOW_INT | ALLOW_STRING, | ||||
DEBUG_ONLY = 0x100, | DEBUG_ONLY = 0x100, | ||||
/* Some options would cause cross-contamination if values for | /* Some options would cause cross-contamination if values for | ||||
* mainnet were used while running on regtest/testnet (or vice-versa). | * mainnet were used while running on regtest/testnet (or vice-versa). | ||||
* Setting them as NETWORK_ONLY ensures that sharing a config file | * Setting them as NETWORK_ONLY ensures that sharing a config file | ||||
* between mainnet and regtest/testnet won't cause problems due to these | * between mainnet and regtest/testnet won't cause problems due to these | ||||
* parameters by accident. */ | * parameters by accident. */ | ||||
NETWORK_ONLY = 0x200, | NETWORK_ONLY = 0x200, | ||||
}; | }; | ||||
protected: | protected: | ||||
friend class ArgsManagerHelper; | |||||
struct Arg { | struct Arg { | ||||
std::string m_help_param; | std::string m_help_param; | ||||
std::string m_help_text; | std::string m_help_text; | ||||
unsigned int m_flags; | unsigned int m_flags; | ||||
}; | }; | ||||
mutable RecursiveMutex cs_args; | mutable RecursiveMutex cs_args; | ||||
util::Settings m_settings GUARDED_BY(cs_args); | util::Settings m_settings GUARDED_BY(cs_args); | ||||
std::string m_network GUARDED_BY(cs_args); | std::string m_network GUARDED_BY(cs_args); | ||||
std::set<std::string> m_network_only_args GUARDED_BY(cs_args); | std::set<std::string> m_network_only_args GUARDED_BY(cs_args); | ||||
std::map<OptionsCategory, std::map<std::string, Arg>> | std::map<OptionsCategory, std::map<std::string, Arg>> | ||||
m_available_args GUARDED_BY(cs_args); | m_available_args GUARDED_BY(cs_args); | ||||
std::list<SectionInfo> m_config_sections GUARDED_BY(cs_args); | std::list<SectionInfo> m_config_sections GUARDED_BY(cs_args); | ||||
NODISCARD bool ReadConfigStream(std::istream &stream, | NODISCARD bool ReadConfigStream(std::istream &stream, | ||||
const std::string &filepath, | const std::string &filepath, | ||||
std::string &error, | std::string &error, | ||||
bool ignore_invalid_keys = false); | bool ignore_invalid_keys = false); | ||||
/** | |||||
* Returns true if settings values from the default section should be used, | |||||
* depending on the current network and whether the setting is | |||||
* network-specific. | |||||
*/ | |||||
bool UseDefaultSection(const std::string &arg) const | |||||
EXCLUSIVE_LOCKS_REQUIRED(cs_args); | |||||
/** | |||||
* Get setting value. | |||||
* | |||||
* Result will be null if setting was unset, true if "-setting" argument was | |||||
* passed false if "-nosetting" argument was passed, and a string if a | |||||
* "-setting=value" argument was passed. | |||||
*/ | |||||
util::SettingsValue GetSetting(const std::string &arg) const; | |||||
/** | |||||
* Get list of setting values. | |||||
*/ | |||||
std::vector<util::SettingsValue> | |||||
GetSettingsList(const std::string &arg) const; | |||||
public: | public: | ||||
ArgsManager(); | ArgsManager(); | ||||
/** | /** | ||||
* Select the network in use | * Select the network in use | ||||
*/ | */ | ||||
void SelectConfigNetwork(const std::string &network); | void SelectConfigNetwork(const std::string &network); | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | public: | ||||
/** | /** | ||||
* Get the help string | * Get the help string | ||||
*/ | */ | ||||
std::string GetHelpMessage() const; | std::string GetHelpMessage() const; | ||||
/** | /** | ||||
* Return Flags for known arg. | * Return Flags for known arg. | ||||
* Return ArgsManager::NONE for unknown arg. | * Return nullopt for unknown arg. | ||||
*/ | */ | ||||
unsigned int FlagsOfKnownArg(const std::string &key) const; | Optional<unsigned int> GetArgFlags(const std::string &name) const; | ||||
}; | }; | ||||
extern ArgsManager gArgs; | extern ArgsManager gArgs; | ||||
/** | /** | ||||
* @return true if help has been requested via a command-line arg | * @return true if help has been requested via a command-line arg | ||||
*/ | */ | ||||
bool HelpRequested(const ArgsManager &args); | bool HelpRequested(const ArgsManager &args); | ||||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |