Samchon Framework for CPP  1.0.0
ExternalClientArray.hpp
1 #pragma once
2 #include <samchon/API.hpp>
3 
4 #include <samchon/templates/external/ExternalSystemArray.hpp>
5 
6 #include <samchon/protocol/Server.hpp>
7 #include <samchon/protocol/ClientDriver.hpp>
8 
9 namespace samchon
10 {
11 namespace templates
12 {
13 namespace external
14 {
29  template <class System = ExternalSystem>
31  : public virtual ExternalSystemArray<System>,
32  public virtual protocol::Server
33  {
34  public:
35  /* =========================================================
36  CONSTRUCTORS
37  - DEFAULT
38  - FACTORY METHODS FOR CHILDREN
39  ============================================================
40  CONSTRUCTORS
41  --------------------------------------------------------- */
46  : ExternalSystemArray<System>(),
47  protocol::Server()
48  {
49  };
50 
51  virtual ~ExternalClientArray() = default;
52 
53  protected:
54  /* ---------------------------------------------------------
55  FACTORY METHODS FOR CHILDREN
56  --------------------------------------------------------- */
66  virtual void addClient(std::shared_ptr<protocol::ClientDriver> driver) override final
67  {
68  std::shared_ptr<ExternalSystem> system(createExternalClient(driver));
69  if (system == nullptr)
70  return;
71 
72  system->communicator_ = driver;
73  {
74  library::UniqueWriteLock uk(getMutex());
75  push_back(system);
76  }
77  driver->listen(system.get());
78 
79  for (size_t i = 0; i < size(); i++)
80  if (at(i) == system)
81  {
82  library::UniqueWriteLock uk(getMutex());
83 
84  erase(begin() + i);
85  break;
86  }
87  };
88 
100  virtual auto createChild(std::shared_ptr<library::XML> xml) -> System* override
101  {
102  return nullptr;
103  } // = delete;
104 
111  virtual auto createExternalClient(std::shared_ptr<protocol::ClientDriver>) -> System* = 0;
112  };
113 };
114 };
115 };
virtual auto createExternalClient(std::shared_ptr< protocol::ClientDriver >) -> System *=0
Unique lock for writing.
virtual auto createChild(std::shared_ptr< library::XML > xml) -> System *override
virtual void addClient(std::shared_ptr< protocol::ClientDriver > driver) override final