Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
2
7
10
11#include <boost/exception/diagnostic_information.hpp>
12
13#include <pwd.h>
14#include "config.hpp"
15
16using namespace appbase;
17using namespace sysio;
18
19void configure_logging(const bfs::path& config_path) {
20 try {
21 try {
22 fc::configure_logging(config_path);
23 } catch (...) {
24 elog("Error reloading logging.json");
25 throw;
26 }
27 } catch (const fc::exception& e) { //
28 elog("${e}", ("e", e.to_detail_string()));
29 } catch (const boost::exception& e) {
30 elog("${e}", ("e", boost::diagnostic_information(e)));
31 } catch (const std::exception& e) { //
32 elog("${e}", ("e", e.what()));
33 } catch (...) {
34 // empty
35 }
36}
37
39 auto config_path = app().get_logging_conf();
40 if (fc::exists(config_path)) {
41 ilog("Received HUP. Reloading logging configuration from ${p}.", ("p", config_path.string()));
42 } else {
43 ilog("Received HUP. No log config found at ${p}, setting to default.", ("p", config_path.string()));
44 }
45 configure_logging(config_path);
46 fc::log_config::initialize_appenders(app().get_io_service());
47}
48
50 auto config_path = app().get_logging_conf();
51 if (fc::exists(config_path))
52 fc::configure_logging(config_path); // intentionally allowing exceptions to escape
53 fc::log_config::initialize_appenders(app().get_io_service());
54
56}
57
58
60{
61 bfs::path home;
62 struct passwd* pwd = getpwuid(getuid());
63 if(pwd) {
64 home = pwd->pw_dir;
65 }
66 else {
67 home = getenv("HOME");
68 }
69 if(home.empty())
70 home = "./";
71 return home;
72}
73
74int main(int argc, char** argv)
75{
76 try {
79 bfs::path home = determine_home_directory();
80 app().set_default_data_dir(home / "sysio-wallet");
81 app().set_default_config_dir(home / "sysio-wallet");
83 .default_unix_socket_path = kiod::config::key_store_executable_name + ".sock",
84 .default_http_port = 0
85 });
87 if(!app().initialize<wallet_plugin, wallet_api_plugin, http_plugin>(argc, argv)) {
88 const auto &opts = app().get_options();
89 if (opts.count("help") || opts.count("version") || opts.count("full-version") ||
90 opts.count("print-default-config")) {
91 return 0;
92 }
93 }
95 auto& http = app().get_plugin<http_plugin>();
96 http.add_handler("/v1/" + kiod::config::key_store_executable_name + "/stop", [&a=app()](string, string, url_response_callback cb) { cb(200, fc::variant(fc::variant_object())); a.quit(); } );
97 app().startup();
98 app().exec();
99 } catch (const fc::exception& e) {
100 elog("${e}", ("e",e.to_detail_string()));
101 } catch (const boost::exception& e) {
102 elog("${e}", ("e",boost::diagnostic_information(e)));
103 } catch (const std::exception& e) {
104 elog("${e}", ("e",e.what()));
105 } catch (...) {
106 elog("unknown exception");
107 }
108 return 0;
109}
const bpo::variables_map & get_options() const
void set_version_string(std::string v)
User provided version string for version_string() which overrides git describe value.
abstract_plugin & get_plugin(const string &name) const
void set_default_config_dir(const bfs::path &config_dir="etc")
Set default config directory.
void set_sighup_callback(std::function< void()> callback)
Set function pointer invoked on receipt of SIGHUP.
bfs::path get_logging_conf() const
Get logging configuration path.
void set_full_version_string(std::string v)
User provided full version string for full_version_string()
void set_default_data_dir(const bfs::path &data_dir="data-dir")
Set default data directory.
Used to generate a useful error report when an exception is thrown.
Definition exception.hpp:58
std::string to_detail_string(log_level ll=log_level::all) const
const char * what() const noexcept override
An order-preserving dictionary of variants.
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
void add_handler(const string &url, const url_handler &, int priority=appbase::priority::medium_low)
static void set_defaults(const http_plugin_defaults config)
Defines exception's used by fc.
char ** argv
#define ilog(FORMAT,...)
Definition logger.hpp:118
#define elog(FORMAT,...)
Definition logger.hpp:130
application & app()
bool exists(const path &p)
void configure_logging(const fc::path &log_config)
const std::string & version_client()
< Grab the basic version information of the client; example: v1.8.0-rc1
Definition version.cpp:5
const std::string & version_full()
Definition version.cpp:10
std::function< void(int, fc::variant)> url_response_callback
A callback function provided to a URL handler to allow it to specify the HTTP response code and body.
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
void initialize_logging()
Definition main.cpp:49
void logging_conf_handler()
Definition main.cpp:38
bfs::path determine_home_directory()
Definition main.cpp:59
static void initialize_appenders(boost::asio::io_service &ios)