diff options
Diffstat (limited to 'src/common/util.h')
-rw-r--r-- | src/common/util.h | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/common/util.h b/src/common/util.h index 92ce7177a..51f0dad90 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -39,11 +39,41 @@ #include "misc_language.h" #include "p2p/p2p_protocol_defs.h" +/*! \brief Various Tools + * + * + * + */ namespace tools { + /*! \brief Returns the default data directory. + * + * \details Windows < Vista: C:\\Documents and Settings\\Username\\Application Data\\CRYPTONOTE_NAME + * + * Windows >= Vista: C:\\Users\\Username\\AppData\\Roaming\\CRYPTONOTE_NAME + * + * Mac: ~/Library/Application Support/CRYPTONOTE_NAME + * + * Unix: ~/.CRYPTONOTE_NAME + */ std::string get_default_data_dir(); + + /*! \brief Returns the OS version string + * + * \details This is a wrapper around the primitives + * get_windows_version_display_string() and + * get_nix_version_display_string() + */ std::string get_os_version_string(); + + /*! \brief creates directories for a path + * + * wrapper around boost::filesyste::create_directories. + * (ensure-directory-exists): greenspun's tenth rule in action! + */ bool create_directories_if_necessary(const std::string& path); + /*! \brief std::rename wrapper for nix and something strange for windows. + */ std::error_code replace_file(const std::string& replacement_name, const std::string& replaced_name); inline crypto::hash get_proof_of_trust_hash(const nodetool::proof_of_trust& pot) @@ -54,10 +84,12 @@ namespace tools return crypto::cn_fast_hash(s.data(), s.size()); } - + /*! \brief Defines a signal handler for win32 and *nix + */ class signal_handler { public: + /*! \brief installs a signal handler */ template<typename T> static bool install(T t) { @@ -69,6 +101,7 @@ namespace tools } return r; #else + /* Only blocks SIGINT and SIGTERM */ signal(SIGINT, posix_handler); signal(SIGTERM, posix_handler); m_handler = t; @@ -78,12 +111,12 @@ namespace tools private: #if defined(WIN32) + /*! \brief Handler for win */ static BOOL WINAPI win_handler(DWORD type) { if (CTRL_C_EVENT == type || CTRL_BREAK_EVENT == type) { handle_signal(); - return TRUE; } else { @@ -93,12 +126,14 @@ namespace tools return TRUE; } #else + /*! \brief handler for NIX */ static void posix_handler(int /*type*/) { handle_signal(); } #endif + /*! \brief calles m_handler */ static void handle_signal() { static std::mutex m_mutex; @@ -106,7 +141,7 @@ namespace tools m_handler(); } - private: + /*! \brief where the installed handler is stored */ static std::function<void(void)> m_handler; }; } |