Samchon Framework for CPP  1.0.0
User.hpp
1 #pragma once
2 #include <samchon/API.hpp>
3 
4 #include <samchon/Map.hpp>
5 #include <samchon/SmartPointer.hpp>
6 #include <samchon/protocol/IProtocol.hpp>
7 
8 #include <string>
9 #include <memory>
10 #include <samchon/library/RWMutex.hpp>
11 #include <samchon/protocol/service/ServiceKeeper.hpp>
12 #include <samchon/protocol/Socket.hpp>
13 
19 #define KEEP_USER_ALIVE auto &keeper = SmartPointer<User>(this);
20 
21 namespace samchon
22 {
23 namespace library
24 {
25  class Semaphore;
26 };
27 namespace protocol
28 {
29  class Invoke;
30 
31 namespace service
32 {
33  class Server;
34  class Client;
35 
36  class IPUserPair;
37 
56  class SAMCHON_FRAMEWORK_API User
57  : private Map<size_t, SmartPointer<Client>>,
58  public IProtocol
59  {
60  friend class Server;
61  friend class Client;
62 
63  private:
65 
66  private:
67  /* =========================================================
68  BASIC VARIABLES
69  ========================================================= */
74 
94  std::string sessionID;
95 
96  IPUserPair *ipPair;
97 
98  /* =========================================================
99  VARIABLES FOR CRITICAL SECTION
100  ========================================================= */
105 
119 
123  size_t sequence;
124 
125  /* =========================================================
126  ACCOUNT VARIABLES
127  ========================================================= */
133  std::string id;
134 
201 
202  public:
209  User(Server*);
210  virtual ~User();
211 
212  /* =========================================================
213  ACCESSORS OF MAP
214  ========================================================= */
215  auto size() const->size_t;
216  auto begin() const->const_iterator;
217  auto end() const->const_iterator;
218 
219  /* =========================================================
220  GETTERS
221  ========================================================= */
225  auto getServer() const->Server*;
226 
232  auto getSemaphore() const->library::Semaphore*;
233 
237  auto getID() const->std::string;
238 
244  auto getAuthority() const -> int;
245 
246  protected:
247  /* =========================================================
248  CLIENT FACTORY
249  ========================================================= */
253  virtual auto createClient()->Client* = 0;
254  //void setMember(const std::string &id, int authority);
255 
256  private:
262  void addClient(Socket*);
263 
306  void eraseClient(size_t);
307 
308 
309  /* =========================================================
310  LOGIN AND JOIN
311  ========================================================= */
319  void goLogin(std::shared_ptr<Invoke>);
320 
328  void goJoin(std::shared_ptr<Invoke>);
329 
346  virtual void goLogout();
347 
348  protected:
355  virtual auto doLogin(std::shared_ptr<Invoke>) -> bool = 0;
356 
363  virtual auto doJoin(std::shared_ptr<Invoke>) -> bool = 0;
364 
365  public:
366  /* =========================================================
367  MESSAGE CHAIN
368  ========================================================= */
369  virtual void sendData(std::shared_ptr<Invoke>) override;
370  virtual void replyData(std::shared_ptr<Invoke>) override;
371  };
372 };
373 };
374 };
Customized std::map.
Definition: Map.hpp:88
library::Semaphore * semaphore
Semaphore to limit number of thread.
Definition: User.hpp:118
int authority
Authority allocated to user.
Definition: User.hpp:200
Definition: RWMutex.hpp:4
Server * server
Server containing the user.
Definition: User.hpp:73
Relationship between IP address and User for issuing session.
Definition: IPUserPair.hpp:51
User containing Client(s) with session-id.
Definition: User.hpp:56
A server for (cloud) service.
Definition: Server.hpp:48
std::string sessionID
Session ID of the user.
Definition: User.hpp:94
A network boundary with the client in an User.
Definition: Client.hpp:46
std::string id
Account id.
Definition: User.hpp:133
An interface of Invoke message chain.
Definition: IProtocol.hpp:31
Standard message of network I/O.
Definition: Invoke.hpp:47
library::RWMutex mtx
Mutex for container.
Definition: User.hpp:104
Top level namespace of products built from samchon.
Definition: ByteArray.hpp:7