mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
commented util.h
This commit is contained in:
parent
bf972c40fc
commit
c085e9294f
5 changed files with 102 additions and 44 deletions
16
.gitignore
vendored
16
.gitignore
vendored
|
@ -1,7 +1,23 @@
|
|||
.DS_Store
|
||||
/doc
|
||||
/build
|
||||
/tags
|
||||
|
||||
# vim swap files
|
||||
*.swp
|
||||
*.swo
|
||||
TAGS
|
||||
!TAGS/
|
||||
tags
|
||||
!tags/
|
||||
gtags.files
|
||||
GTAGS
|
||||
GRTAGS
|
||||
GPATH
|
||||
cscope.files
|
||||
cscope.out
|
||||
cscope.in.out
|
||||
cscope.po.out
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -316,14 +316,16 @@ std::string get_nix_version_display_string()
|
|||
|
||||
std::string get_default_data_dir()
|
||||
{
|
||||
/* Please for the love of god refactor the ifdefs out of this */
|
||||
|
||||
// namespace fs = boost::filesystem;
|
||||
// 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 config_folder;
|
||||
|
||||
#ifdef WIN32
|
||||
// Windows
|
||||
config_folder = get_special_folder_path(CSIDL_APPDATA, true) + "/" + CRYPTONOTE_NAME;
|
||||
#else
|
||||
std::string pathRet;
|
||||
|
|
|
@ -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();
|
||||
|
||||
/*! \breif 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();
|
||||
|
||||
/*! \breif 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());
|
||||
}
|
||||
|
||||
|
||||
/*! \breif 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)
|
||||
/*! \breif 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,20 +126,22 @@ namespace tools
|
|||
return TRUE;
|
||||
}
|
||||
#else
|
||||
/*! \breif handler for NIX */
|
||||
static void posix_handler(int /*type*/)
|
||||
{
|
||||
handle_signal();
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! \breif calles m_handler */
|
||||
static void handle_signal()
|
||||
{
|
||||
static std::mutex m_mutex;
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
/* static std::mutex m_mutex; */
|
||||
/* std::unique_lock<std::mutex> lock(m_mutex); */
|
||||
m_handler();
|
||||
}
|
||||
|
||||
private:
|
||||
/*! \breif where the installed handler is stored */
|
||||
static std::function<void(void)> m_handler;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||
|
||||
// node.cpp : Defines the entry point for the console application.
|
||||
//
|
||||
// Does this file exist?
|
||||
|
||||
|
||||
#include "include_base_utils.h"
|
||||
|
@ -64,7 +64,38 @@ namespace
|
|||
const command_line::arg_descriptor<bool> arg_console = {"no-console", "Disable daemon console commands"};
|
||||
}
|
||||
|
||||
bool command_line_preprocessor(const boost::program_options::variables_map& vm);
|
||||
bool command_line_preprocessor(const boost::program_options::variables_map& vm)
|
||||
{
|
||||
bool exit = false;
|
||||
if (command_line::get_arg(vm, command_line::arg_version))
|
||||
{
|
||||
std::cout << CRYPTONOTE_NAME << " v" << PROJECT_VERSION_LONG << ENDL;
|
||||
exit = true;
|
||||
}
|
||||
if (command_line::get_arg(vm, arg_os_version))
|
||||
{
|
||||
std::cout << "OS: " << tools::get_os_version_string() << ENDL;
|
||||
exit = true;
|
||||
}
|
||||
|
||||
if (exit)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int new_log_level = command_line::get_arg(vm, arg_log_level);
|
||||
if(new_log_level < LOG_LEVEL_MIN || new_log_level > LOG_LEVEL_MAX)
|
||||
{
|
||||
LOG_PRINT_L0("Wrong log level value: ");
|
||||
}
|
||||
else if (log_space::get_set_log_detalisation_level(false) != new_log_level)
|
||||
{
|
||||
log_space::get_set_log_detalisation_level(true, new_log_level);
|
||||
LOG_PRINT_L0("LOG_LEVEL set to " << new_log_level);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
@ -235,35 +266,3 @@ int main(int argc, char* argv[])
|
|||
CATCH_ENTRY_L0("main", 1);
|
||||
}
|
||||
|
||||
bool command_line_preprocessor(const boost::program_options::variables_map& vm)
|
||||
{
|
||||
bool exit = false;
|
||||
if (command_line::get_arg(vm, command_line::arg_version))
|
||||
{
|
||||
std::cout << CRYPTONOTE_NAME << " v" << PROJECT_VERSION_LONG << ENDL;
|
||||
exit = true;
|
||||
}
|
||||
if (command_line::get_arg(vm, arg_os_version))
|
||||
{
|
||||
std::cout << "OS: " << tools::get_os_version_string() << ENDL;
|
||||
exit = true;
|
||||
}
|
||||
|
||||
if (exit)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int new_log_level = command_line::get_arg(vm, arg_log_level);
|
||||
if(new_log_level < LOG_LEVEL_MIN || new_log_level > LOG_LEVEL_MAX)
|
||||
{
|
||||
LOG_PRINT_L0("Wrong log level value: ");
|
||||
}
|
||||
else if (log_space::get_set_log_detalisation_level(false) != new_log_level)
|
||||
{
|
||||
log_space::get_set_log_detalisation_level(true, new_log_level);
|
||||
LOG_PRINT_L0("LOG_LEVEL set to " << new_log_level);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
//
|
||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||
|
||||
|
||||
/* This isn't a header file, may want to refactor this... */
|
||||
#pragma once
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
@ -39,7 +41,11 @@
|
|||
#include "crypto/hash.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
/*!
|
||||
* \brief I don't really know right now
|
||||
*
|
||||
*
|
||||
*/
|
||||
class daemon_cmmands_handler
|
||||
{
|
||||
nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> >& m_srv;
|
||||
|
|
Loading…
Reference in a new issue