Raven Core  3.0.0
P2P Digital Currency
Classes | Namespaces | Macros | Enumerations | Functions | Variables
util.h File Reference
#include "compat.h"
#include "fs.h"
#include "sync.h"
#include "tinyformat.h"
#include "utiltime.h"
#include <atomic>
#include <exception>
#include <map>
#include <stdint.h>
#include <string>
#include <vector>
#include <boost/signals2/signal.hpp>
Include dependency graph for util.h:

Go to the source code of this file.

Classes

class  CTranslationInterface
 Signals for translation. More...
 
struct  CLogCategoryActive
 
class  ArgsManager
 

Namespaces

 BCLog
 

Macros

#define LogPrintf(...)
 
#define LogPrint(category, ...)
 

Enumerations

enum  BCLog::LogFlags : uint32_t {
  BCLog::NONE = 0, BCLog::NET = (1 << 0), BCLog::TOR = (1 << 1), BCLog::MEMPOOL = (1 << 2),
  BCLog::HTTP = (1 << 3), BCLog::BENCH = (1 << 4), BCLog::ZMQ = (1 << 5), BCLog::DB = (1 << 6),
  BCLog::RPC = (1 << 7), BCLog::ESTIMATEFEE = (1 << 8), BCLog::ADDRMAN = (1 << 9), BCLog::SELECTCOINS = (1 << 10),
  BCLog::REINDEX = (1 << 11), BCLog::CMPCTBLOCK = (1 << 12), BCLog::RAND = (1 << 13), BCLog::PRUNE = (1 << 14),
  BCLog::PROXY = (1 << 15), BCLog::MEMPOOLREJ = (1 << 16), BCLog::LIBEVENT = (1 << 17), BCLog::COINDB = (1 << 18),
  BCLog::QT = (1 << 19), BCLog::LEVELDB = (1 << 20), BCLog::ALL = ~(uint32_t) 0
}
 

Functions

int64_t GetStartupTime ()
 Server/client environment: argument handling, config file parsing, logging, thread wrappers, startup time. More...
 
std::string _ (const char *psz)
 Translation function: Call Translate signal on UI interface, which returns a boost::optional result. More...
 
void SetupEnvironment ()
 
bool SetupNetworking ()
 
std::string ListLogCategories ()
 Returns a string with the log categories. More...
 
std::vector< CLogCategoryActiveListActiveLogCategories ()
 Returns a vector of the active log categories. More...
 
bool GetLogCategory (uint32_t *f, const std::string *str)
 Return true if str parses as a log category and set the flags in f. More...
 
int LogPrintStr (const std::string &str)
 Send a string to the log output. More...
 
template<typename... Args>
std::string FormatStringFromLogArgs (const char *fmt, const Args &... args)
 Get format string from VA_ARGS for error reporting. More...
 
template<typename... Args>
bool error (const char *fmt, const Args &... args)
 
void PrintExceptionContinue (const std::exception *pex, const char *pszThread)
 
void FileCommit (FILE *file)
 
bool TruncateFile (FILE *file, unsigned int length)
 
int RaiseFileDescriptorLimit (int nMinFD)
 this function tries to raise the file descriptor limit to the requested number. More...
 
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 is advisory, and the range specified in the arguments will never contain live data More...
 
bool RenameOver (fs::path src, fs::path dest)
 
bool TryCreateDirectories (const fs::path &p)
 Ignores exceptions thrown by Boost's create_directories if the requested directory exists. More...
 
fs::path GetDefaultDataDir ()
 
const fs::path & GetDataDir (bool fNetSpecific=true)
 
void ClearDatadirCache ()
 
fs::path GetConfigFile (const std::string &confPath)
 
fs::path GetPidFile ()
 
void CreatePidFile (const fs::path &path, pid_t pid)
 
void OpenDebugLog ()
 
void ShrinkDebugFile ()
 
void runCommand (const std::string &strCommand)
 
bool IsSwitchChar (char c)
 
std::string HelpMessageGroup (const std::string &message)
 Format a string to be used as group of options in help messages. More...
 
std::string HelpMessageOpt (const std::string &option, const std::string &message)
 Format a string to be used as option description in help messages. More...
 
int GetNumCores ()
 Return the number of physical cores available on the current system. More...
 
void RenameThread (const char *name)
 
template<typename Callable >
void TraceThread (const char *name, Callable func)
 
std::string CopyrightHolders (const std::string &strPrefix)
 
void SetThreadPriority (int nPriority)
 

Variables

bool fPrintToConsole
 
bool fPrintToDebugLog
 
bool fLogTimestamps
 
bool fLogTimeMicros
 
bool fLogIPs
 
std::atomic< bool > fReopenDebugLog
 
CTranslationInterface translationInterface
 
const char *const RAVEN_CONF_FILENAME
 
const char *const RAVEN_PID_FILENAME
 
std::atomic< uint32_t > logCategories
 
ArgsManager gArgs
 

Macro Definition Documentation

◆ LogPrint

#define LogPrint (   category,
  ... 
)
Value:
do { \
if (LogAcceptCategory((category))) { \
LogPrintf(__VA_ARGS__); \
} \
} while(0)

Definition at line 160 of file util.h.

◆ LogPrintf

#define LogPrintf (   ...)
Value:
do { \
std::string _log_msg_; /* Unlikely name to avoid shadowing variables */ \
try { \
_log_msg_ = tfm::format(__VA_ARGS__); \
} catch (tinyformat::format_error &fmterr) { \
/* Original format string will have newline so don't add one here */ \
_log_msg_ = "Error \"" + std::string(fmterr.what()) + "\" while formatting log message: " + FormatStringFromLogArgs(__VA_ARGS__); \
} \
LogPrintStr(_log_msg_); \
} while(0)
void format(std::ostream &out, const char *fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
Definition: tinyformat.h:955
std::string FormatStringFromLogArgs(const char *fmt, const Args &... args)
Get format string from VA_ARGS for error reporting.
Definition: util.h:132

Definition at line 149 of file util.h.

Function Documentation

◆ _()

std::string _ ( const char *  psz)
inline

Translation function: Call Translate signal on UI interface, which returns a boost::optional result.

If no translation slot is registered, nothing is returned, and simply return the input.

Definition at line 66 of file util.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AllocateFileRange()

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 is advisory, and the range specified in the arguments will never contain live data

Definition at line 755 of file util.cpp.

Here is the caller graph for this function:

◆ ClearDatadirCache()

void ClearDatadirCache ( )

Definition at line 604 of file util.cpp.

Here is the caller graph for this function:

◆ CopyrightHolders()

std::string CopyrightHolders ( const std::string &  strPrefix)

Definition at line 917 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreatePidFile()

void CreatePidFile ( const fs::path &  path,
pid_t  pid 
)

Definition at line 656 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ error()

template<typename... Args>
bool error ( const char *  fmt,
const Args &...  args 
)

Definition at line 168 of file util.h.

Here is the call graph for this function:

◆ FileCommit()

void FileCommit ( FILE *  file)

Definition at line 699 of file util.cpp.

Here is the caller graph for this function:

◆ FormatStringFromLogArgs()

template<typename... Args>
std::string FormatStringFromLogArgs ( const char *  fmt,
const Args &...  args 
)

Get format string from VA_ARGS for error reporting.

Definition at line 132 of file util.h.

◆ GetConfigFile()

fs::path GetConfigFile ( const std::string &  confPath)

Definition at line 612 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDataDir()

const fs::path& GetDataDir ( bool  fNetSpecific = true)

Definition at line 572 of file util.cpp.

Here is the caller graph for this function:

◆ GetDefaultDataDir()

fs::path GetDefaultDataDir ( )

Definition at line 542 of file util.cpp.

Here is the caller graph for this function:

◆ GetLogCategory()

bool GetLogCategory ( uint32_t *  f,
const std::string *  str 
)

Return true if str parses as a log category and set the flags in f.

Definition at line 256 of file util.cpp.

Here is the caller graph for this function:

◆ GetNumCores()

int GetNumCores ( )

Return the number of physical cores available on the current system.

Note
This does not count virtual cores, such as those provided by HyperThreading when boost is newer than 1.56.

Definition at line 908 of file util.cpp.

Here is the caller graph for this function:

◆ GetPidFile()

fs::path GetPidFile ( )

Definition at line 649 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetStartupTime()

int64_t GetStartupTime ( )

Server/client environment: argument handling, config file parsing, logging, thread wrappers, startup time.

Definition at line 930 of file util.cpp.

Here is the caller graph for this function:

◆ HelpMessageGroup()

std::string HelpMessageGroup ( const std::string &  message)

Format a string to be used as group of options in help messages.

Parameters
messageGroup name (e.g. "RPC server options:")
Returns
the formatted string

Definition at line 506 of file util.cpp.

Here is the caller graph for this function:

◆ HelpMessageOpt()

std::string HelpMessageOpt ( const std::string &  option,
const std::string &  message 
)

Format a string to be used as option description in help messages.

Parameters
optionOption message (e.g. "-rpcuser=<user>")
messageOption description (e.g. "Username for JSON-RPC connections")
Returns
the formatted string

Definition at line 511 of file util.cpp.

Here is the caller graph for this function:

◆ IsSwitchChar()

bool IsSwitchChar ( char  c)
inline

Definition at line 213 of file util.h.

Here is the caller graph for this function:

◆ ListActiveLogCategories()

std::vector<CLogCategoryActive> ListActiveLogCategories ( )

Returns a vector of the active log categories.

Definition at line 294 of file util.cpp.

Here is the caller graph for this function:

◆ ListLogCategories()

std::string ListLogCategories ( )

Returns a string with the log categories.

Definition at line 277 of file util.cpp.

Here is the caller graph for this function:

◆ LogPrintStr()

int LogPrintStr ( const std::string &  str)

Send a string to the log output.

Definition at line 346 of file util.cpp.

Here is the caller graph for this function:

◆ OpenDebugLog()

void OpenDebugLog ( )

Definition at line 198 of file util.cpp.

Here is the caller graph for this function:

◆ PrintExceptionContinue()

void PrintExceptionContinue ( const std::exception *  pex,
const char *  pszThread 
)

Definition at line 535 of file util.cpp.

Here is the caller graph for this function:

◆ RaiseFileDescriptorLimit()

int RaiseFileDescriptorLimit ( int  nMinFD)

this function tries to raise the file descriptor limit to the requested number.

It returns the actual file descriptor limit (which may be more or less than nMinFD)

Definition at line 729 of file util.cpp.

Here is the caller graph for this function:

◆ RenameOver()

bool RenameOver ( fs::path  src,
fs::path  dest 
)

Definition at line 668 of file util.cpp.

Here is the caller graph for this function:

◆ RenameThread()

void RenameThread ( const char *  name)

Definition at line 849 of file util.cpp.

Here is the caller graph for this function:

◆ runCommand()

void runCommand ( const std::string &  strCommand)

Definition at line 841 of file util.cpp.

Here is the caller graph for this function:

◆ SetThreadPriority()

void SetThreadPriority ( int  nPriority)

Definition at line 935 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetupEnvironment()

void SetupEnvironment ( )

Definition at line 865 of file util.cpp.

Here is the caller graph for this function:

◆ SetupNetworking()

bool SetupNetworking ( )

Definition at line 896 of file util.cpp.

Here is the caller graph for this function:

◆ ShrinkDebugFile()

void ShrinkDebugFile ( )

Definition at line 799 of file util.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TraceThread()

template<typename Callable >
void TraceThread ( const char *  name,
Callable  func 
)

. and a wrapper that just calls func once

Definition at line 331 of file util.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TruncateFile()

bool TruncateFile ( FILE *  file,
unsigned int  length 
)

Definition at line 716 of file util.cpp.

Here is the caller graph for this function:

◆ TryCreateDirectories()

bool TryCreateDirectories ( const fs::path &  p)

Ignores exceptions thrown by Boost's create_directories if the requested directory exists.

Specifically handles case where path p exists, but it wasn't possible for the user to write to the parent directory.

Definition at line 684 of file util.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ fLogIPs

bool fLogIPs

Definition at line 100 of file util.cpp.

◆ fLogTimeMicros

bool fLogTimeMicros

Definition at line 99 of file util.cpp.

◆ fLogTimestamps

bool fLogTimestamps

Definition at line 98 of file util.cpp.

◆ fPrintToConsole

bool fPrintToConsole

Definition at line 95 of file util.cpp.

◆ fPrintToDebugLog

bool fPrintToDebugLog

Definition at line 96 of file util.cpp.

◆ fReopenDebugLog

std::atomic<bool> fReopenDebugLog

◆ gArgs

ArgsManager gArgs

Definition at line 94 of file util.cpp.

◆ logCategories

std::atomic<uint32_t> logCategories

◆ RAVEN_CONF_FILENAME

const char* const RAVEN_CONF_FILENAME

Definition at line 91 of file util.cpp.

◆ RAVEN_PID_FILENAME

const char* const RAVEN_PID_FILENAME

Definition at line 92 of file util.cpp.

◆ translationInterface

CTranslationInterface translationInterface

Definition at line 102 of file util.cpp.