hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
server_runner.hpp
Go to the documentation of this file.
1 
6 #ifndef MAIN_SERVER_RUNNER_HPP
7 #define MAIN_SERVER_RUNNER_HPP
8 
9 #include <condition_variable>
10 
11 #include <grpc++/grpc++.h>
12 #include <grpc++/impl/codegen/service_type.h>
13 #include "common/result.hpp"
14 #include "logger/logger_fwd.hpp"
15 
16 namespace iroha {
17  namespace network {
18  struct TlsCredentials;
19 
23  class ServerRunner {
24  public:
32  explicit ServerRunner(
33  const std::string &address,
35  bool reuse = true,
36  const boost::optional<std::shared_ptr<const TlsCredentials>>
37  &my_tls_creds = boost::none);
38 
39  ~ServerRunner();
40 
46  ServerRunner &append(std::shared_ptr<grpc::Service> service);
47 
53 
57  void waitForServersReady();
58 
62  void shutdown();
63 
67  void shutdown(const std::chrono::system_clock::time_point &deadline);
68 
69  private:
70  logger::LoggerPtr log_;
71 
72  std::unique_ptr<grpc::Server> server_instance_;
73  std::mutex wait_for_server_;
74  std::condition_variable server_instance_cv_;
75 
76  std::string server_address_;
77  std::shared_ptr<grpc::ServerCredentials> credentials_;
78  bool reuse_;
79  std::vector<std::shared_ptr<grpc::Service>> services_;
80  };
81 
82  } // namespace network
83 } // namespace iroha
84 
85 #endif // MAIN_SERVER_RUNNER_HPP
void waitForServersReady()
Definition: server_runner.cpp:86
void shutdown()
Definition: server_runner.cpp:93
Definition: result_fwd.hpp:27
Definition: server_runner.hpp:23
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
ServerRunner & append(std::shared_ptr< grpc::Service > service)
Definition: server_runner.cpp:53
Definition: block_query.hpp:15
ServerRunner(const std::string &address, logger::LoggerPtr log, bool reuse=true, const boost::optional< std::shared_ptr< const TlsCredentials >> &my_tls_creds=boost::none)
Definition: server_runner.cpp:39
iroha::expected::Result< int, std::string > run()
Definition: server_runner.cpp:58
~ServerRunner()
Definition: server_runner.cpp:49