Dogecoin Core  1.14.2
P2P Digital Currency
Classes | Macros | Functions | Variables
util.h File Reference
#include "compat.h"
#include "tinyformat.h"
#include "utiltime.h"
#include <atomic>
#include <exception>
#include <map>
#include <stdint.h>
#include <string>
#include <vector>
#include <boost/filesystem/path.hpp>
#include <boost/signals2/signal.hpp>
#include <boost/thread/exceptions.hpp>
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  CTranslationInterface
 Signals for translation. More...
 

Macros

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

Functions

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 LogAcceptCategory (const char *category)
 Return true if log accepts specified category. More...
 
int LogPrintStr (const std::string &str)
 Send a string to the log output. More...
 
template<typename... Args>
bool error (const char *fmt, const Args &... args)
 
void PrintExceptionContinue (const std::exception *pex, const char *pszThread)
 
void ParseParameters (int argc, const char *const argv[])
 
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 (boost::filesystem::path src, boost::filesystem::path dest)
 
bool TryCreateDirectory (const boost::filesystem::path &p)
 Ignores exceptions thrown by Boost's create_directory if the requested directory exists. More...
 
boost::filesystem::path GetDefaultDataDir ()
 
const boost::filesystem::path & GetDataDir (bool fNetSpecific=true)
 
void ClearDatadirCache ()
 
boost::filesystem::path GetConfigFile (const std::string &confPath)
 
boost::filesystem::path GetPidFile ()
 
void CreatePidFile (const boost::filesystem::path &path, pid_t pid)
 
void ReadConfigFile (const std::string &confPath)
 
void OpenDebugLog ()
 
void ShrinkDebugFile ()
 
void runCommand (const std::string &strCommand)
 
bool IsSwitchChar (char c)
 
bool IsArgSet (const std::string &strArg)
 Return true if the given argument has been manually set. More...
 
std::string GetArg (const std::string &strArg, const std::string &strDefault)
 Return string argument or default value. More...
 
int64_t GetArg (const std::string &strArg, int64_t nDefault)
 Return integer argument or default value. More...
 
bool GetBoolArg (const std::string &strArg, bool fDefault)
 Return boolean argument or default value. More...
 
bool SoftSetArg (const std::string &strArg, const std::string &strValue)
 Set an argument if it doesn't already have a value. More...
 
bool SoftSetBoolArg (const std::string &strArg, bool fValue)
 Set a boolean argument if it doesn't already have a value. More...
 
void ForceSetArg (const std::string &strArg, const std::string &strValue)
 
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)
 

Variables

const std::map< std::string, std::vector< std::string > > & mapMultiArgs
 
bool fDebug
 
bool fPrintToConsole
 
bool fPrintToDebugLog
 
bool fLogTimestamps
 
bool fLogTimeMicros
 
bool fLogIPs
 
std::atomic< bool > fReopenDebugLog
 
CTranslationInterface translationInterface
 
const char *const BITCOIN_CONF_FILENAME
 
const char *const BITCOIN_PID_FILENAME
 

Macro Definition Documentation

◆ LogPrint

#define LogPrint (   category,
  ... 
)
Value:
do { \
if (LogAcceptCategory((category))) { \
LogPrintStr(tfm::format(__VA_ARGS__)); \
} \
} 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:948
bool LogAcceptCategory(const char *category)
Return true if log accepts specified category.
Definition: util.cpp:234

Definition at line 76 of file util.h.

◆ LogPrintf

#define LogPrintf (   ...)
Value:
do { \
LogPrintStr(tfm::format(__VA_ARGS__)); \
} while(0)

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

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

◆ ClearDatadirCache()

void ClearDatadirCache ( )

Definition at line 543 of file util.cpp.

◆ CopyrightHolders()

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

Definition at line 847 of file util.cpp.

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

◆ CreatePidFile()

void CreatePidFile ( const boost::filesystem::path &  path,
pid_t  pid 
)

Definition at line 594 of file util.cpp.

◆ error()

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

Definition at line 87 of file util.h.

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

◆ FileCommit()

void FileCommit ( FILE *  file)

Definition at line 635 of file util.cpp.

◆ ForceSetArg()

void ForceSetArg ( const std::string &  strArg,
const std::string &  strValue 
)

Definition at line 436 of file util.cpp.

◆ GetArg() [1/2]

std::string GetArg ( const std::string &  strArg,
const std::string &  strDefault 
)

Return string argument or default value.

Parameters
strArgArgument to get (e.g. "-foo")
default(e.g. "1")
Returns
command-line argument or default value

Definition at line 395 of file util.cpp.

Here is the caller graph for this function:

◆ GetArg() [2/2]

int64_t GetArg ( const std::string &  strArg,
int64_t  nDefault 
)

Return integer argument or default value.

Parameters
strArgArgument to get (e.g. "-foo")
default(e.g. 1)
Returns
command-line argument (0 if invalid number) or default value

Definition at line 403 of file util.cpp.

Here is the call graph for this function:

◆ GetBoolArg()

bool GetBoolArg ( const std::string &  strArg,
bool  fDefault 
)

Return boolean argument or default value.

Parameters
strArgArgument to get (e.g. "-foo")
default(true or false)
Returns
command-line argument or default value

Definition at line 411 of file util.cpp.

Here is the caller graph for this function:

◆ GetConfigFile()

boost::filesystem::path GetConfigFile ( const std::string &  confPath)

Definition at line 551 of file util.cpp.

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

◆ GetDataDir()

const boost::filesystem::path& GetDataDir ( bool  fNetSpecific = true)

Definition at line 513 of file util.cpp.

Here is the caller graph for this function:

◆ GetDefaultDataDir()

boost::filesystem::path GetDefaultDataDir ( )

Definition at line 482 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 838 of file util.cpp.

◆ GetPidFile()

boost::filesystem::path GetPidFile ( )

Definition at line 587 of file util.cpp.

Here is the call 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 448 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 452 of file util.cpp.

Here is the caller graph for this function:

◆ IsArgSet()

bool IsArgSet ( const std::string &  strArg)

Return true if the given argument has been manually set.

Parameters
strArgArgument to get (e.g. "-foo")
Returns
true if the argument has been set

Definition at line 389 of file util.cpp.

Here is the caller graph for this function:

◆ IsSwitchChar()

bool IsSwitchChar ( char  c)
inline

Definition at line 117 of file util.h.

Here is the caller graph for this function:

◆ LogAcceptCategory()

bool LogAcceptCategory ( const char *  category)

Return true if log accepts specified category.

Definition at line 234 of file util.cpp.

◆ LogPrintStr()

int LogPrintStr ( const std::string &  str)

Send a string to the log output.

Definition at line 295 of file util.cpp.

Here is the caller graph for this function:

◆ OpenDebugLog()

void OpenDebugLog ( )

Definition at line 212 of file util.cpp.

◆ ParseParameters()

void ParseParameters ( int  argc,
const char *const  argv[] 
)

Definition at line 353 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 475 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 664 of file util.cpp.

◆ ReadConfigFile()

void ReadConfigFile ( const std::string &  confPath)

Definition at line 560 of file util.cpp.

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

◆ RenameOver()

bool RenameOver ( boost::filesystem::path  src,
boost::filesystem::path  dest 
)

Definition at line 605 of file util.cpp.

Here is the caller graph for this function:

◆ RenameThread()

void RenameThread ( const char *  name)

Definition at line 781 of file util.cpp.

Here is the caller graph for this function:

◆ runCommand()

void runCommand ( const std::string &  strCommand)

Definition at line 774 of file util.cpp.

Here is the caller graph for this function:

◆ SetupEnvironment()

void SetupEnvironment ( )

Definition at line 797 of file util.cpp.

Here is the caller graph for this function:

◆ SetupNetworking()

bool SetupNetworking ( )

Definition at line 826 of file util.cpp.

Here is the caller graph for this function:

◆ ShrinkDebugFile()

void ShrinkDebugFile ( )

Definition at line 729 of file util.cpp.

Here is the call graph for this function:

◆ SoftSetArg()

bool SoftSetArg ( const std::string &  strArg,
const std::string &  strValue 
)

Set an argument if it doesn't already have a value.

Parameters
strArgArgument to set (e.g. "-foo")
strValueValue (e.g. "1")
Returns
true if argument gets set, false if it already had a value

Definition at line 419 of file util.cpp.

Here is the caller graph for this function:

◆ SoftSetBoolArg()

bool SoftSetBoolArg ( const std::string &  strArg,
bool  fValue 
)

Set a boolean argument if it doesn't already have a value.

Parameters
strArgArgument to set (e.g. "-foo")
fValueValue (e.g. false)
Returns
true if argument gets set, false if it already had a value

Definition at line 428 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 211 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 652 of file util.cpp.

◆ TryCreateDirectory()

bool TryCreateDirectory ( const boost::filesystem::path &  p)

Ignores exceptions thrown by Boost's create_directory 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 621 of file util.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ BITCOIN_CONF_FILENAME

const char* const BITCOIN_CONF_FILENAME
extern

Definition at line 106 of file util.cpp.

◆ BITCOIN_PID_FILENAME

const char* const BITCOIN_PID_FILENAME
extern

Definition at line 107 of file util.cpp.

◆ fDebug

bool fDebug
extern

Definition at line 113 of file util.cpp.

◆ fLogIPs

bool fLogIPs
extern

Definition at line 119 of file util.cpp.

◆ fLogTimeMicros

bool fLogTimeMicros
extern

Definition at line 118 of file util.cpp.

◆ fLogTimestamps

bool fLogTimestamps
extern

Definition at line 117 of file util.cpp.

◆ fPrintToConsole

bool fPrintToConsole
extern

Definition at line 114 of file util.cpp.

◆ fPrintToDebugLog

bool fPrintToDebugLog
extern

Definition at line 115 of file util.cpp.

◆ fReopenDebugLog

std::atomic<bool> fReopenDebugLog
extern

◆ mapMultiArgs

const std::map<std::string, std::vector<std::string> >& mapMultiArgs
extern

Definition at line 112 of file util.cpp.

◆ translationInterface

CTranslationInterface translationInterface
extern

Definition at line 121 of file util.cpp.