Samchon Framework for CPP  1.0.0
ExternalServer.hpp
1 #pragma once
2 #include <samchon/API.hpp>
3 
4 #include <samchon/templates/external/ExternalSystem.hpp>
5 #include <samchon/templates/external/base/ExternalServerBase.hpp>
6 
7 #include <samchon/protocol/ServerConnector.hpp>
8 
9 namespace samchon
10 {
11 namespace templates
12 {
13 namespace external
14 {
26  : public virtual ExternalSystem,
27  public base::ExternalServerBase
28  {
29  friend class ExternalSystem;
30 
31  private:
32  typedef ExternalSystem super;
33 
34  public:
35  /* ---------------------------------------------------------
36  CONSTRUCTORS
37  --------------------------------------------------------- */
43  ExternalServer(base::ExternalSystemArrayBase *systemArray)
44  : super(systemArray)
45  {
46  };
47 
48  virtual ~ExternalServer() = default;
49 
50  protected:
64  {
65  return new protocol::ServerConnector(this);
66  };
67 
68  public:
69  /* ---------------------------------------------------------
70  NETWORK
71  --------------------------------------------------------- */
75  virtual void connect()
76  {
77  if (communicator_ != nullptr || ip.empty() == true)
78  return;
79 
80  // CREATE CONNECTOR AND CONNECT
81  std::shared_ptr<protocol::ServerConnector> connector(this->createServerConnector());
82  this->communicator_ = connector;
83 
84  connector->connect(ip, port);
85 
86  // AFTER DISCONNECTION, ERASE THIS OBJECT
88  for (size_t i = 0; i < systemArray->size(); i++)
89  if (systemArray->at(i).get() == this)
90  {
91  systemArray->erase(systemArray->begin() + i);
92  break;
93  }
94  };
95  };
96 };
97 };
98 };
virtual auto createServerConnector() -> protocol::ServerConnector *
auto get(const typename child_type::key_type &key) -> typename container_type::value_type &
Access the element by specified identifier(key).
An Entity and a container of children Entity objects.
Definition: EntityGroup.hpp:40
ExternalServer(base::ExternalSystemArrayBase *systemArray)