14 #if defined(HAVE_CONFIG_H) 31 #include <boost/signals2/signal.hpp> 36 static const bool DEFAULT_LOGTIMEMICROS =
false;
37 static const bool DEFAULT_LOGIPS =
false;
38 static const bool DEFAULT_LOGTIMESTAMPS =
true;
45 boost::signals2::signal<std::string(const char *psz)>
Translate;
66 inline std::string
_(
const char *psz)
68 boost::optional<std::string> rv = translationInterface.
Translate(psz);
69 return rv ? (*rv) : psz;
113 static inline bool LogAcceptCategory(uint32_t category)
115 return (
logCategories.load(std::memory_order_relaxed) & category) != 0;
131 template<
typename... Args>
135 static inline void MarkUsed()
138 template<
typename T,
typename... Args>
139 static inline void MarkUsed(
const T &t,
const Args &... args)
146 #define LogPrintf(...) do { MarkUsed(__VA_ARGS__); } while(0) 147 #define LogPrint(category, ...) do { MarkUsed(__VA_ARGS__); } while(0) 149 #define LogPrintf(...) do { \ 150 std::string _log_msg_; \ 152 _log_msg_ = tfm::format(__VA_ARGS__); \ 153 } catch (tinyformat::format_error &fmterr) { \ 155 _log_msg_ = "Error \"" + std::string(fmterr.what()) + "\" while formatting log message: " + FormatStringFromLogArgs(__VA_ARGS__); \ 157 LogPrintStr(_log_msg_); \ 160 #define LogPrint(category, ...) do { \ 161 if (LogAcceptCategory((category))) { \ 162 LogPrintf(__VA_ARGS__); \ 167 template<
typename... Args>
168 bool error(
const char *fmt,
const Args &... args)
190 const fs::path &
GetDataDir(
bool fNetSpecific =
true);
204 fs::path GetSpecialFolderPath(
int nFolder,
bool fCreate =
true);
211 void runCommand(
const std::string &strCommand);
216 return c ==
'-' || c ==
'/';
229 void ParseParameters(
int argc,
const char *
const argv[]);
231 void ReadConfigFile(
const std::string &confPath);
239 std::vector<std::string> GetArgs(
const std::string &strArg)
const;
247 bool IsArgSet(
const std::string &strArg)
const;
256 std::string GetArg(
const std::string &strArg,
const std::string &strDefault)
const;
265 int64_t GetArg(
const std::string &strArg, int64_t nDefault)
const;
274 bool GetBoolArg(
const std::string &strArg,
bool fDefault)
const;
283 bool SoftSetArg(
const std::string &strArg,
const std::string &strValue);
292 bool SoftSetBoolArg(
const std::string &strArg,
bool fValue);
296 void ForceSetArg(
const std::string &strArg,
const std::string &strValue);
316 std::string
HelpMessageOpt(
const std::string &option,
const std::string &message);
330 template<
typename Callable>
333 std::string s =
strprintf(
"raven-%s", name);
341 catch (
const boost::thread_interrupted &)
343 LogPrintf(
"%s thread interrupt\n", name);
346 catch (
const std::exception &e)
362 #endif // RAVEN_UTIL_H
int64_t GetStartupTime()
Server/client environment: argument handling, config file parsing, logging, thread wrappers...
const QString REINDEX("-reindex")
std::vector< CLogCategoryActive > ListActiveLogCategories()
Returns a vector of the active log categories.
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 ListLogCategories()
Returns a string with the log categories.
void TraceThread(const char *name, Callable func)
boost::signals2::signal< std::string(const char *psz)> Translate
Translate a message to the native language of the user.
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)
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)
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 error(const char *fmt, const Args &... args)
int RaiseFileDescriptorLimit(int nMinFD)
this function tries to raise the file descriptor limit to the requested number.
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)
int LogPrintStr(const std::string &str)
Send a string to the log output.
const char *const RAVEN_CONF_FILENAME
const char *const RAVEN_PID_FILENAME
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 FormatStringFromLogArgs(const char *fmt, const Args &... args)
Get format string from VA_ARGS for error reporting.
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 ...