Samchon Framework for CPP  1.0.0
SlaveDriver.hpp
1 #pragma once
2 #include <samchon/templates/parallel/ParallelSystem.hpp>
3 #include <samchon/examples/interaction/base/SystemBase.hpp>
4 
5 #include <samchon/examples/interaction/base/MasterBase.hpp>
6 #include <samchon/examples/interaction/base/MonitorBase.hpp>
7 #include <samchon/examples/interaction/TSPRequest.hpp>
8 #include <samchon/examples/interaction/PackerRequest.hpp>
9 
10 namespace samchon
11 {
12 namespace examples
13 {
14 namespace interaction
15 {
16  class SlaveDriver
17  : public templates::parallel::ParallelSystem,
18  public base::SystemBase
19  {
20  private:
21  typedef templates::parallel::ParallelSystem super;
22 
23  public:
24  SlaveDriver(base::MasterBase *master, std::shared_ptr<protocol::ClientDriver> driver)
25  : super(master, driver)
26  {
27  name = "";
28 
29  if (master->getUID() != -1)
30  sendData(std::make_shared<protocol::Invoke>("set_master_uid", master->getUID()));
31  };
32  virtual ~SlaveDriver()
33  {
34  std::cout << "A slave has disconnected" << std::endl;
35 
36  if (getUID() != -1)
37  getSystemArray<base::MasterBase>()->getMonitor()->sendSystemStructure();
38  };
39 
40  virtual void construct(std::shared_ptr<library::XML> xml) override
41  {
42  setUID(xml->getProperty<int>("uid"));
43 
44  super::construct(xml);
45  };
46 
47  protected:
48  virtual auto createChild(std::shared_ptr<library::XML>) -> templates::external::ExternalSystemRole*
49  {
50  return nullptr;
51  };
52 
53  public:
54  virtual void sendData(std::shared_ptr<protocol::Invoke> invoke) override
55  {
56  super::sendData(invoke);
57 
58  // NOTIFY SEND_DATA
59  getSystemArray<base::MasterBase>()->getMonitor()->reportSendData(getUID(), invoke);
60  };
61 
62  virtual void replyData(std::shared_ptr<protocol::Invoke> invoke) override
63  {
64  if (invoke->getListener() == "construct")
65  construct(invoke->front()->getValueAsXML());
66  else if (invoke->getListener() == "replyPackerOptimization")
67  getSystemArray<base::MasterBase>()->getPacker()->replyOptimization(invoke->front()->getValueAsXML());
68  else if (invoke->getListener() == "replyTSPOptimization")
69  getSystemArray<base::MasterBase>()->getTSP()->replyOptimization(invoke->front()->getValueAsXML());
70  };
71 
72  virtual auto TAG() const -> std::string
73  {
74  return super::TAG();
75  }
76  };
77 };
78 };
79 };
virtual void replyData(std::shared_ptr< Invoke >)=0
virtual void construct(std::shared_ptr< library::XML > xml) override
Construct data of the Entity from an XML object.
virtual void sendData(std::shared_ptr< Invoke >)=0
virtual void sendData(std::shared_ptr< protocol::Invoke > invoke) override