Fabcoin Core  0.16.2
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 <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
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, ...)
 
#define LogPrintChar(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::HTTPPOLL = (1 << 22), BCLog::POW = (1 << 30),
  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 ()
 
bool LogAcceptCategoryChar (const char *category)
 Return true if log accepts specified category. More...
 
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, bool useVMLog=false)
 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 SetThreadPriority (int nPriority)
 
void RenameThread (const char *name)
 
template<typename Callable >
void TraceThread (const char *name, Callable func)
 
std::string CopyrightHolders (const std::string &strPrefix)
 
bool CheckHex (const std::string &str)
 

Variables

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

Macro Definition Documentation

#define LogPrint (   category,
  ... 
)
Value:
do { \
if (LogAcceptCategory((category))) { \
LogPrintf(__VA_ARGS__); \
} \
} while(0)
if(a.IndicesBefore(b, len, lenIndices))
Definition: equihash.cpp:243
#define LogPrintf(...)
Definition: util.h:153

Definition at line 164 of file util.h.

#define LogPrintChar (   category,
  ... 
)
Value:
do { \
if (LogAcceptCategoryChar((category))) { \
LogPrintStr(tfm::format(__VA_ARGS__)); \
} \
} while(0)
int LogPrintStr(const std::string &str, bool useVMLog=false)
Send a string to the log output.
Definition: util.cpp:388
if(a.IndicesBefore(b, len, lenIndices))
Definition: equihash.cpp:243
bool LogAcceptCategoryChar(const char *category)
Return true if log accepts specified category.
Definition: util.cpp:321
uint8_t format

Definition at line 171 of file util.h.

#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)
int LogPrintStr(const std::string &str, bool useVMLog=false)
Send a string to the log output.
Definition: util.cpp:388
std::string FormatStringFromLogArgs(const char *fmt, const Args &...args)
Get format string from VA_ARGS for error reporting.
Definition: util.h:140
uint8_t format

Definition at line 153 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 71 of file util.h.

Here is the call graph for this function:

Here is the caller graph for this function:

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 796 of file util.cpp.

Here is the caller graph for this function:

bool CheckHex ( const std::string &  str)

Definition at line 985 of file util.cpp.

Here is the caller graph for this function:

void ClearDatadirCache ( )

Definition at line 652 of file util.cpp.

Here is the caller graph for this function:

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

Definition at line 968 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 703 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 178 of file util.h.

Here is the call graph for this function:

void FileCommit ( FILE *  file)

Definition at line 744 of file util.cpp.

Here is the caller graph for this function:

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

Get format string from VA_ARGS for error reporting.

Definition at line 140 of file util.h.

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

Definition at line 660 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 623 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

fs::path GetDefaultDataDir ( )

Definition at line 593 of file util.cpp.

Here is the caller graph for this function:

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 274 of file util.cpp.

Here is the caller graph for this function:

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 959 of file util.cpp.

Here is the caller graph for this function:

fs::path GetPidFile ( )

Definition at line 696 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int64_t GetStartupTime ( )

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

Definition at line 980 of file util.cpp.

Here is the caller graph for this function:

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 559 of file util.cpp.

Here is the caller graph for this function:

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 563 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool IsSwitchChar ( char  c)
inline

Definition at line 206 of file util.h.

Here is the caller graph for this function:

std::vector<CLogCategoryActive> ListActiveLogCategories ( )

Returns a vector of the active log categories.

Definition at line 306 of file util.cpp.

Here is the caller graph for this function:

std::string ListLogCategories ( )

Returns a string with the log categories.

Definition at line 291 of file util.cpp.

Here is the caller graph for this function:

bool LogAcceptCategoryChar ( const char *  category)

Return true if log accepts specified category.

Definition at line 321 of file util.cpp.

Here is the call graph for this function:

int LogPrintStr ( const std::string &  str,
bool  useVMLog = false 
)

Send a string to the log output.

Definition at line 388 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void OpenDebugLog ( )

Definition at line 198 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 586 of file util.cpp.

Here is the caller graph for this function:

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 773 of file util.cpp.

Here is the caller graph for this function:

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

Definition at line 714 of file util.cpp.

Here is the caller graph for this function:

void RenameThread ( const char *  name)

Definition at line 888 of file util.cpp.

Here is the caller graph for this function:

void runCommand ( const std::string &  strCommand)

Definition at line 881 of file util.cpp.

Here is the caller graph for this function:

void SetThreadPriority ( int  nPriority)

Definition at line 945 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void SetupEnvironment ( )

Definition at line 904 of file util.cpp.

Here is the caller graph for this function:

bool SetupNetworking ( )

Definition at line 933 of file util.cpp.

Here is the caller graph for this function:

void ShrinkDebugFile ( )

Definition at line 838 of file util.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

. and a wrapper that just calls func once

Definition at line 316 of file util.h.

Here is the call graph for this function:

Here is the caller graph for this function:

bool TruncateFile ( FILE *  file,
unsigned int  length 
)

Definition at line 761 of file util.cpp.

Here is the caller graph for this function:

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 730 of file util.cpp.

Here is the caller graph for this function:

Variable Documentation

const char* const FABCOIN_CONF_FILENAME

Definition at line 91 of file util.cpp.

const char* const FABCOIN_PID_FILENAME

Definition at line 92 of file util.cpp.

bool fLogIPs

Definition at line 100 of file util.cpp.

bool fLogTimeMicros

Definition at line 99 of file util.cpp.

bool fLogTimestamps

Definition at line 98 of file util.cpp.

bool fPrintToConsole

Definition at line 95 of file util.cpp.

bool fPrintToDebugLog

Definition at line 96 of file util.cpp.

std::atomic<bool> fReopenDebugLog
ArgsManager gArgs

Definition at line 94 of file util.cpp.

std::atomic<uint32_t> logCategories
CTranslationInterface translationInterface

Definition at line 102 of file util.cpp.