Fabcoin Core  0.16.2
P2P Digital Currency
IpcServerBase.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16 */
23 #pragma once
24 
25 #include <string>
26 #include <thread>
27 #include <mutex>
28 #include <unordered_set>
29 #include <jsonrpccpp/server/abstractserverconnector.h>
30 
31 namespace dev
32 {
33 template <class S> class IpcServerBase: public jsonrpc::AbstractServerConnector
34 {
35 public:
36  IpcServerBase(std::string const& _path);
37  virtual bool StartListening();
38  virtual bool StopListening();
39  virtual bool SendResponse(std::string const& _response, void* _addInfo = nullptr);
40 
41 protected:
42  virtual void Listen() = 0;
43  virtual void CloseConnection(S _socket) = 0;
44  virtual size_t Write(S _connection, std::string const& _data) = 0;
45  virtual size_t Read(S _connection, void* _data, size_t _size) = 0;
46  void GenerateResponse(S _connection);
47 
48 protected:
49  bool m_running = false;
50  std::string m_path;
51  std::unordered_set<S> m_sockets;
52  std::mutex x_sockets;
53  std::thread m_listeningThread; //TODO use asio for parallel request processing
54 };
55 } // namespace dev
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
IpcServerBase(std::string const &_path)
virtual size_t Write(S _connection, std::string const &_data)=0
virtual bool SendResponse(std::string const &_response, void *_addInfo=nullptr)
virtual void CloseConnection(S _socket)=0
std::mutex x_sockets
Definition: IpcServerBase.h:52
virtual size_t Read(S _connection, void *_data, size_t _size)=0
void GenerateResponse(S _connection)
std::thread m_listeningThread
Definition: IpcServerBase.h:53
std::string m_path
Definition: IpcServerBase.h:50
virtual bool StopListening()
virtual void Listen()=0
virtual bool StartListening()
#define S(a)
Definition: mars.cpp:50
std::unordered_set< S > m_sockets
Definition: IpcServerBase.h:51