Electroneum
rpc.h
Go to the documentation of this file.
1 // Copyrights(c) 2017-2019, The Electroneum Project
2 // Copyrights(c) 2014-2017, The Monero Project
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without modification, are
7 // permitted provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code must retain the above copyright notice, this list of
10 // conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 // of conditions and the following disclaimer in the documentation and/or other
14 // materials provided with the distribution.
15 //
16 // 3. Neither the name of the copyright holder nor the names of its contributors may be
17 // used to endorse or promote products derived from this software without specific
18 // prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
31 
32 #pragma once
33 
34 #include "rpc/core_rpc_server.h"
35 
36 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY
37 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "daemon"
38 
39 namespace daemonize
40 {
41 
42 class t_rpc final
43 {
44 public:
45  static void init_options(boost::program_options::options_description & option_spec)
46  {
48  }
49 private:
51 public:
53  boost::program_options::variables_map const & vm
54  , t_core & core
55  , t_p2p & p2p
56  )
57  : m_server{core.get(), p2p.get()}
58  {
59  MGINFO("Initializing core rpc server...");
60  if (!m_server.init(vm))
61  {
62  throw std::runtime_error("Failed to initialize core rpc server.");
63  }
64  MGINFO("Core rpc server initialized OK on port: " << m_server.get_binded_port());
65  }
66 
67  void run()
68  {
69  MGINFO("Starting core rpc server...");
70  if (!m_server.run(2, false))
71  {
72  throw std::runtime_error("Failed to start core rpc server.");
73  }
74  MGINFO("Core rpc server started ok");
75  }
76 
77  void stop()
78  {
79  MGINFO("Stopping core rpc server...");
80  m_server.send_stop_signal();
81  m_server.timed_wait_server_stop(5000);
82  }
83 
85  {
86  return &m_server;
87  }
88 
90  {
91  MGINFO("Deinitializing rpc server...");
92  try {
93  m_server.deinit();
94  } catch (...) {
95  MERROR("Failed to deinitialize rpc server...");
96  }
97  }
98 };
99 
100 }
void run()
Definition: rpc.h:67
void stop()
Definition: rpc.h:77
Definition: command_parser_executor.cpp:36
Definition: rpc.h:42
cryptonote::core_rpc_server * get_server()
Definition: rpc.h:84
Definition: p2p.h:44
t_node_server & get()
Definition: p2p.h:72
Definition: core.h:43
t_rpc(boost::program_options::variables_map const &vm, t_core &core, t_p2p &p2p)
Definition: rpc.h:52
bool init(const boost::program_options::variables_map &vm)
Definition: core_rpc_server.cpp:76
cryptonote::core & get()
Definition: core.h:83
static void init_options(boost::program_options::options_description &option_spec)
Definition: rpc.h:45
cryptonote::core_rpc_server m_server
Definition: rpc.h:50
Definition: core_rpc_server.h:52
static void init_options(boost::program_options::options_description &desc)
Definition: core_rpc_server.cpp:60
~t_rpc()
Definition: rpc.h:89