Samchon Framework for CPP  1.0.0
Service.hpp
1 #pragma once
2 #include <samchon/API.hpp>
3 
4 #include <samchon/protocol/IProtocol.hpp>
5 
6 #define KEEP_SERVICE_ALIVE auto &__keeper = __keep_alive();
7 
8 namespace samchon
9 {
10 namespace templates
11 {
12 namespace service
13 {
14  class Server;
15  class User;
16  class Client;
17 
33  class Service
34  : public virtual protocol::IProtocol
35  {
36  friend class Server;
37  friend class Client;
38 
39  private:
40  Client *client;
41 
42  std::string path;
43 
44  public:
45  /* ---------------------------------------------------------
46  CONSTRUCTORS
47  --------------------------------------------------------- */
54  Service(Client *client, const std::string &path)
55  {
56  this->client = client;
57  this->path = path;
58  };
59 
67  virtual ~Service() = default;
68 
69  auto __keep_alive() const -> std::pair<std::shared_ptr<User>, std::shared_ptr<Client>>;
70 
71  public:
72  /* ---------------------------------------------------------
73  ACCESSORS
74  --------------------------------------------------------- */
78  auto getClient() const -> Client*
79  {
80  return client;
81  };
82 
86  auto getPath() const -> std::string
87  {
88  return path;
89  };
90 
91  /* ---------------------------------------------------------
92  MESSAGE CHAIN
93  --------------------------------------------------------- */
101  virtual void sendData(std::shared_ptr<protocol::Invoke> invoke) override
102  {
103  ((protocol::IProtocol*)client)->sendData(invoke);
104  };
105 
106  private:
107  std::weak_ptr<User> user_weak_ptr;
108  std::weak_ptr<Client> client_weak_ptr;
109  };
110 }
111 }
112 }
virtual void sendData(std::shared_ptr< protocol::Invoke > invoke) override
Definition: Service.hpp:101
auto getPath() const -> std::string
Definition: Service.hpp:86
auto getClient() const -> Client *
Definition: Service.hpp:78
Service(Client *client, const std::string &path)
Definition: Service.hpp:54