10 #ifndef BITCOIN_UTIL_H
11 #define BITCOIN_UTIL_H
13 #if defined(HAVE_CONFIG_H)
14 #include "config/bitcoin-config.h"
28 #include <boost/filesystem/path.hpp>
29 #include <boost/signals2/signal.hpp>
30 #include <boost/thread/exceptions.hpp>
32 static const bool DEFAULT_LOGTIMEMICROS =
false;
33 static const bool DEFAULT_LOGIPS =
false;
34 static const bool DEFAULT_LOGTIMESTAMPS =
true;
41 boost::signals2::signal<std::string (
const char* psz)>
Translate;
44 extern const std::map<std::string, std::vector<std::string> >&
mapMultiArgs;
62 inline std::string
_(
const char* psz)
65 return rv ? (*rv) : psz;
76 #define LogPrint(category, ...) do { \
77 if (LogAcceptCategory((category))) { \
78 LogPrintStr(tfm::format(__VA_ARGS__)); \
82 #define LogPrintf(...) do { \
83 LogPrintStr(tfm::format(__VA_ARGS__)); \
86 template<
typename... Args>
87 bool error(
const char* fmt,
const Args&... args)
99 bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest);
102 const boost::filesystem::path &
GetDataDir(
bool fNetSpecific =
true);
104 boost::filesystem::path
GetConfigFile(
const std::string& confPath);
107 void CreatePidFile(
const boost::filesystem::path &path, pid_t pid);
111 boost::filesystem::path GetSpecialFolderPath(
int nFolder,
bool fCreate =
true);
115 void runCommand(
const std::string& strCommand);
120 return c ==
'-' || c ==
'/';
132 bool IsArgSet(
const std::string& strArg);
141 std::string
GetArg(
const std::string& strArg,
const std::string& strDefault);
150 int64_t
GetArg(
const std::string& strArg, int64_t nDefault);
159 bool GetBoolArg(
const std::string& strArg,
bool fDefault);
168 bool SoftSetArg(
const std::string& strArg,
const std::string& strValue);
180 void ForceSetArg(
const std::string& strArg,
const std::string& strValue);
197 std::string
HelpMessageOpt(
const std::string& option,
const std::string& message);
211 template <
typename Callable>
void TraceThread(
const char* name, Callable func)
213 std::string s =
strprintf(
"dogecoin-%s", name);
221 catch (
const boost::thread_interrupted&)
223 LogPrintf(
"%s thread interrupt\n", name);
226 catch (
const std::exception& e) {
boost::signals2::signal< std::string(const char *psz)> Translate
Translate a message to the native language of the user.
std::atomic< bool > fReopenDebugLog
CTranslationInterface translationInterface
const boost::filesystem::path & GetDataDir(bool fNetSpecific=true)
void CreatePidFile(const boost::filesystem::path &path, pid_t pid)
boost::filesystem::path GetConfigFile(const std::string &confPath)
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
bool LogAcceptCategory(const char *category)
Return true if log accepts specified category.
std::string CopyrightHolders(const std::string &strPrefix)
bool TryCreateDirectory(const boost::filesystem::path &p)
Ignores exceptions thrown by Boost's create_directory if the requested directory exists.
void ParseParameters(int argc, const char *const argv[])
void ReadConfigFile(const std::string &confPath)
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
const std::map< std::string, std::vector< std::string > > & mapMultiArgs
void RenameThread(const char *name)
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...
boost::filesystem::path GetPidFile()
bool error(const char *fmt, const Args &... args)
const char *const BITCOIN_PID_FILENAME
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
void runCommand(const std::string &strCommand)
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 boost::optional result.
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
boost::filesystem::path GetDefaultDataDir()
const char *const BITCOIN_CONF_FILENAME
bool IsSwitchChar(char c)
void TraceThread(const char *name, Callable func)
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
bool TruncateFile(FILE *file, unsigned int length)
bool IsArgSet(const std::string &strArg)
Return true if the given argument has been manually set.
bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
int GetNumCores()
Return the number of physical 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.
void FileCommit(FILE *file)
int LogPrintStr(const std::string &str)
Send a string to the log output.