Samchon Framework for CPP  1.0.0
ChiefDriver.hpp
1 #pragma once
2 #include <samchon/protocol/IServer.hpp>
3 #include <samchon/protocol/IClient.hpp>
4 
5 #include <samchon/protocol/Invoke.hpp>
6 
7 #include <mutex>
8 
9 namespace samchon
10 {
11 namespace example
12 {
13 namespace interaction
14 {
15  using namespace std;
16 
17  using namespace library;
18  using namespace protocol;
19 
47  : public IServer,
48  public IClient
49  {
50  private:
51  typedef IServer super;
52 
53  protected:
58 
62  int port;
63 
67  mutex mtx;
68 
69  public:
76  ChiefDriver(IProtocol *master, int port)
77  : super(),
78  IClient()
79  {
80  this->master = master;
81  this->port = port;
82  };
83  virtual ~ChiefDriver() = default;
84 
85  virtual void addClient(Socket *socket) override
86  {
87  unique_lock<mutex> uk(mtx);
88 
89  this->socket = socket;
90  listen();
91  };
92 
93  virtual void replyData(shared_ptr<Invoke> invoke) override
94  {
95  master->replyData(invoke);
96  };
97 
98  protected:
99  virtual auto PORT() const -> int override
100  {
101  return port;
102  };
103  };
104 };
105 };
106 };
An interface of a physical server.
Definition: IServer.hpp:43
virtual void replyData(std::shared_ptr< Invoke >)
Reply a message.
ChiefDriver(IProtocol *master, int port)
Construct from master and port number.
Definition: ChiefDriver.hpp:76
virtual auto PORT() const -> int override
Port number of the server.
Definition: ChiefDriver.hpp:99
IProtocol * master
A Master object containing the ChiefDriver.
Definition: ChiefDriver.hpp:57
Definition: RWMutex.hpp:4
virtual void addClient(Socket *socket) override
Handling connection of a physical client.
Definition: ChiefDriver.hpp:85
int port
A port number to open for the Chief system.
Definition: ChiefDriver.hpp:62
An interface for a client.
Definition: IClient.hpp:53
An interface of Invoke message chain.
Definition: IProtocol.hpp:31
A boundary class interacting with a Chief system.
Definition: ChiefDriver.hpp:46
mutex mtx
A mutex for realizing 1:1 server.
Definition: ChiefDriver.hpp:67
Top level namespace of products built from samchon.
Definition: ByteArray.hpp:7