Samchon Framework for CPP  1.0.0
ExternalSystem.hpp
1 #pragma once
2 #include <samchon/API.hpp>
3 
4 #include <samchon/protocol/SharedEntityDeque.hpp>
5 # include <samchon/templates/external/ExternalSystemRole.hpp>
6 #include <samchon/templates/external/base/ExternalSystemBase.hpp>
7 #include <samchon/protocol/IProtocol.hpp>
8 
9 #include <samchon/templates/external/base/ExternalSystemArrayBase.hpp>
10 #include <samchon/templates/external/base/ExternalServerBase.hpp>
11 
12 #include <samchon/protocol/ClientDriver.hpp>
13 
14 namespace samchon
15 {
16 namespace templates
17 {
18 namespace external
19 {
56  : public protocol::SharedEntityDeque<ExternalSystemRole>,
57  public base::ExternalSystemBase,
58  public virtual protocol::IProtocol
59  {
60  private:
62 
63  protected:
64  std::shared_ptr<protocol::Communicator> communicator_;
65 
69  std::string name;
70 
71  public:
72  /* ---------------------------------------------------------
73  CONSTRUCTORS
74  --------------------------------------------------------- */
79  : super()
80  {
81  this->system_array_ = nullptr;
82  }
83 
89  ExternalSystem(base::ExternalSystemArrayBase *systemArray)
90  : super()
91  {
92  this->system_array_ = systemArray;
93  };
94 
101  ExternalSystem(base::ExternalSystemArrayBase *systemArray, std::shared_ptr<protocol::ClientDriver> driver)
102  {
103  this->communicator_ = driver;
104  };
105 
113  virtual ~ExternalSystem() = default;
114 
115  virtual void construct(std::shared_ptr<library::XML> xml) override
116  {
117  name = xml->fetchProperty("name");
118 
119  base::ExternalServerBase *server = dynamic_cast<base::ExternalServerBase*>(this);
120  if (server != nullptr)
121  {
122  server->ip = xml->getProperty<std::string>("ip");
123  server->port = xml->getProperty<int>("port");
124  }
125 
126  super::construct(xml);
127  };
128 
129  public:
130  /* ---------------------------------------------------------
131  ACCESSORS
132  --------------------------------------------------------- */
138  virtual auto key() const -> std::string
139  {
140  return name;
141  };
142 
146  auto getName() const -> std::string
147  {
148  return name;
149  };
150 
151  public:
152  /* ---------------------------------------------------------
153  NETWORK & MESSAGE CHAIN
154  --------------------------------------------------------- */
158  void close()
159  {
160  communicator_->close();
161  };
162 
168  virtual void sendData(std::shared_ptr<protocol::Invoke> invoke) override
169  {
170  communicator_->sendData(invoke);
171  };
172 
178  virtual void replyData(std::shared_ptr<protocol::Invoke> invoke) override
179  {
180  // SHIFT TO ROLES
181  for (size_t i = 0; i < size(); i++)
182  at(i)->replyData(invoke);
183 
184  // SHIFT TO SYSTEM_ARRAY
185  ((IProtocol*)system_array_)->replyData(invoke);
186  };
187 
188  public:
189  /* ---------------------------------------------------------
190  EXPORTERS
191  --------------------------------------------------------- */
192  virtual auto TAG() const -> std::string override
193  {
194  return "system";
195  };
196  virtual auto CHILD_TAG() const -> std::string override
197  {
198  return "role";
199  };
200 
201  virtual auto toXML() const -> std::shared_ptr<library::XML> override
202  {
203  std::shared_ptr<library::XML> &xml = super::toXML();
204  xml->setProperty("name", name);
205 
206  const base::ExternalServerBase *server = dynamic_cast<const base::ExternalServerBase*>(this);
207  if (server != nullptr)
208  {
209  xml->setProperty("ip", server->ip);
210  xml->setProperty("port", server->port);
211  }
212 
213  return xml;
214  };
215  };
216 };
217 };
218 };
virtual auto CHILD_TAG() const -> std::string override
A tag name of children.
virtual void construct(std::shared_ptr< library::XML > xml)
Construct data of the Entity from an XML object.
Definition: EntityGroup.hpp:71
ExternalSystem(base::ExternalSystemArrayBase *systemArray, std::shared_ptr< protocol::ClientDriver > driver)
virtual void construct(std::shared_ptr< library::XML > xml) override
Construct data of the Entity from an XML object.
virtual auto toXML() const -> std::shared_ptr< library::XML > override
Get an XML object represents the EntityGroup.
An Entity and a container of children Entity objects.
Definition: EntityGroup.hpp:40
virtual void replyData(std::shared_ptr< protocol::Invoke > invoke) override
virtual auto key() const -> std::string
ExternalSystem(base::ExternalSystemArrayBase *systemArray)
virtual auto toXML() const -> std::shared_ptr< library::XML >
Get an XML object represents the EntityGroup.
virtual void sendData(std::shared_ptr< protocol::Invoke > invoke) override