12 #ifndef PIVX_UTIL_SYSTEM_H
13 #define PIVX_UTIL_SYSTEM_H
15 #if defined(HAVE_CONFIG_H)
35 #include <unordered_set>
39 #include <boost/signals2/signal.hpp>
40 #include <boost/thread/condition_variable.hpp>
47 boost::signals2::signal<std::string (
const char* psz)>
Translate;
65 inline std::string
_(
const char* psz)
69 return rv ? (*rv) : psz;
76 template<
typename... Args>
77 bool error(
const char* fmt,
const Args&... args)
79 LogPrintf(
"ERROR: %s\n",
tfm::format(fmt, args...));
88 bool CheckDiskSpace(
const fs::path& dir, uint64_t additional_bytes = 0);
90 bool LockDirectory(
const fs::path& directory,
const std::string& lockfile_name,
bool probe_only=
false);
102 const fs::path &
GetDataDir(
bool fNetSpecific =
true);
113 fs::path GetSpecialFolderPath(
int nFolder,
bool fCreate =
true);
121 return c ==
'-' || c ==
'/';
165 std::vector<std::string>
GetArgs(
const std::string& strArg)
const;
173 bool IsArgSet(
const std::string& strArg)
const;
191 std::string
GetArg(
const std::string& strArg,
const std::string& strDefault)
const;
200 int64_t
GetArg(
const std::string& strArg, int64_t nDefault)
const;
209 bool GetBoolArg(
const std::string& strArg,
bool fDefault)
const;
218 bool SoftSetArg(
const std::string& strArg,
const std::string& strValue);
231 void ForceSetArg(
const std::string& strArg,
const std::string& strValue);
257 std::string
HelpMessageOpt(
const std::string& option,
const std::string& message);
270 template <
typename Callable>
273 std::string s =
"pivx-" +
name;
276 LogPrintf(
"%s thread start\n",
name);
278 LogPrintf(
"%s thread exit\n",
name);
279 }
catch (boost::thread_interrupted) {
280 LogPrintf(
"%s thread interrupt\n",
name);
282 }
catch (std::exception& e) {
310 std::pair<int, char**> get();
315 std::vector<std::string> args;
Internal helper functions for ArgsManager.
void ReadConfigFile(const std::string &confPath)
bool IsArgNegated(const std::string &strArg) const
Return true if the argument was originally passed as a negated option, i.e.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
void ParseParameters(int argc, const char *const argv[])
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
std::map< std::string, std::vector< std::string > > m_override_args
std::set< std::string > m_network_only_args
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
void SelectConfigNetwork(const std::string &network)
Select the network in use.
std::map< std::string, std::vector< std::string > > m_config_args
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
void WarnForSectionOnlyArgs()
Log warnings for options in m_section_only_args when they are specified in the default section but no...
void ReadConfigStream(std::istream &stream)
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
std::string GetChainName() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
Server/client environment: argument handling, config file parsing, thread wrappers.
boost::signals2::signal< std::string(const char *psz)> Translate
Translate a message to the native language of the user.
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name.
boost::optional< T > Optional
Substitute for C++17 std::optional.
bool LockDirectory(const fs::path &directory, const std::string &lockfile_name, bool probe_only=false)
CTranslationInterface translationInterface
fs::path GetDefaultDataDir()
const char *const PIVX_CONF_FILENAME
bool CheckDataDirOption()
bool DirIsWritable(const fs::path &directory)
bool RenameOver(fs::path src, fs::path dest)
const fs::path & ZC_GetParamsDir()
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
const char *const PIVX_PID_FILENAME
The PID file facilities.
void ReleaseDirectoryLocks()
Release all directory locks.
int ScheduleBatchPriority(void)
On platforms that support it, tell the kernel the calling thread is CPU-intensive and non-interactive...
void SetThreadPriority(int nPriority)
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by Boost's create_directories if the requested directory exists.
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length)
this function tries to make a particular range of a file allocated (corresponding to disk space) it i...
const char *const PIVX_MASTERNODE_CONF_FILENAME
fs::path AbsPathForConfigVal(const fs::path &path, bool net_specific=true)
bool error(const char *fmt, const Args &... args)
std::atomic< bool > fMasterNode
fs::path GetConfigFile(const std::string &confPath)
const char *const DEFAULT_DEBUGLOGFILE
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a Optional result.
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
const fs::path & GetDataDir(bool fNetSpecific=true)
bool IsSwitchChar(char c)
fs::path GetMasternodeConfigFile()
bool TruncateFile(FILE *file, unsigned int length)
const fs::path & GetBlocksDir()
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes=0)
void runCommand(std::string strCommand)
int GetNumCores()
Return the number of cores available on the current system.
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
bool FileCommit(FILE *file)
void TraceThread(const std::string name, Callable func)