10 #ifndef FABCOIN_UTIL_H 11 #define FABCOIN_UTIL_H 13 #if defined(HAVE_CONFIG_H) 30 #include <boost/signals2/signal.hpp> 33 #include <sys/types.h> 35 #include <sys/resource.h> 41 static const bool DEFAULT_LOGTIMEMICROS =
false;
42 static const bool DEFAULT_LOGIPS =
false;
43 static const bool DEFAULT_LOGTIMESTAMPS =
true;
50 boost::signals2::signal<std::string (const char* psz)>
Translate;
71 inline std::string
_(
const char* psz)
73 boost::optional<std::string> rv = translationInterface.
Translate(psz);
74 return rv ? (*rv) : psz;
121 static inline bool LogAcceptCategory(uint32_t category)
123 return (
logCategories.load(std::memory_order_relaxed) & category) != 0;
137 int LogPrintStr(
const std::string &str,
bool useVMLog =
false);
142 static inline void MarkUsed() {}
143 template<
typename T,
typename... Args>
static inline void MarkUsed(
const T& t,
const Args&... args)
150 #define LogPrintf(...) do { MarkUsed(__VA_ARGS__); } while(0) 151 #define LogPrint(category, ...) do { MarkUsed(__VA_ARGS__); } while(0) 153 #define LogPrintf(...) do { \ 154 std::string _log_msg_; \ 156 _log_msg_ = tfm::format(__VA_ARGS__); \ 157 } catch (tinyformat::format_error &fmterr) { \ 159 _log_msg_ = "Error \"" + std::string(fmterr.what()) + "\" while formatting log message: " + FormatStringFromLogArgs(__VA_ARGS__); \ 161 LogPrintStr(_log_msg_); \ 164 #define LogPrint(category, ...) do { \ 165 if (LogAcceptCategory((category))) { \ 166 LogPrintf(__VA_ARGS__); \ 171 #define LogPrintChar(category, ...) do { \ 172 if (LogAcceptCategoryChar((category))) { \ 173 LogPrintStr(tfm::format(__VA_ARGS__)); \ 177 template<
typename... Args>
178 bool error(
const char* fmt,
const Args&... args)
192 const fs::path &
GetDataDir(
bool fNetSpecific =
true);
200 fs::path GetSpecialFolderPath(
int nFolder,
bool fCreate =
true);
204 void runCommand(
const std::string& strCommand);
209 return c ==
'-' || c ==
'/';
222 void ParseParameters(
int argc,
const char*
const argv[]);
223 void ReadConfigFile(
const std::string& confPath);
224 std::vector<std::string> GetArgs(
const std::string& strArg);
232 bool IsArgSet(
const std::string& strArg);
241 std::string GetArg(
const std::string& strArg,
const std::string& strDefault);
250 int64_t GetArg(
const std::string& strArg, int64_t nDefault);
259 bool GetBoolArg(
const std::string& strArg,
bool fDefault);
268 bool SoftSetArg(
const std::string& strArg,
const std::string& strValue);
277 bool SoftSetBoolArg(
const std::string& strArg,
bool fValue);
281 void ForceSetArg(
const std::string& strArg,
const std::string& strValue);
301 std::string
HelpMessageOpt(
const std::string& option,
const std::string& message);
318 std::string s =
strprintf(
"fabcoin-%s", name);
326 catch (
const boost::thread_interrupted&)
328 LogPrintf(
"%s thread interrupt\n", name);
331 catch (
const std::exception&
e) {
343 bool CheckHex(
const std::string& str);
344 #endif // FABCOIN_UTIL_H
bool error(const char *fmt, const Args &...args)
int64_t GetStartupTime()
Server/client environment: argument handling, config file parsing, logging, thread wrappers...
std::vector< CLogCategoryActive > ListActiveLogCategories()
Returns a vector of the active log categories.
int LogPrintStr(const std::string &str, bool useVMLog=false)
Send a string to the log output.
void RenameThread(const char *name)
std::atomic< uint32_t > logCategories
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by Boost's create_directories if the requested directory exists...
bool GetLogCategory(uint32_t *f, const std::string *str)
Return true if str parses as a log category and set the flags in f.
fs::path GetDefaultDataDir()
void CreatePidFile(const fs::path &path, pid_t pid)
std::string FormatStringFromLogArgs(const char *fmt, const Args &...args)
Get format string from VA_ARGS for error reporting.
std::string ListLogCategories()
Returns a string with the log categories.
void TraceThread(const char *name, Callable func)
int GetNumCores()
Return the number of physical cores available on the current system.
const fs::path & GetDataDir(bool fNetSpecific=true)
void runCommand(const std::string &strCommand)
void SetThreadPriority(int nPriority)
bool LogAcceptCategoryChar(const char *category)
Return true if log accepts specified category.
const char *const FABCOIN_CONF_FILENAME
std::map< std::string, std::string > mapArgs
fs::path GetConfigFile(const std::string &confPath)
bool IsSwitchChar(char c)
std::atomic< bool > fReopenDebugLog
void PrintExceptionContinue(const std::exception *pex, const char *pszThread)
void FileCommit(FILE *file)
boost::signals2::signal< std::string(const char *psz)> Translate
Translate a message to the native language of the user.
std::map< std::string, std::vector< std::string > > mapMultiArgs
std::string CopyrightHolders(const std::string &strPrefix)
bool RenameOver(fs::path src, fs::path dest)
bool CheckHex(const std::string &str)
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
const char *const FABCOIN_PID_FILENAME
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...
CTranslationInterface translationInterface
bool TruncateFile(FILE *file, unsigned int length)
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result...
Wrapped boost mutex: supports recursive locking, but no waiting TODO: We should move away from using ...