Samchon Framework for CPP  1.0.0
ChiefDriver.hpp
1 #pragma once
2 #include <samchon/templates/slave/SlaveClient.hpp>
3 
4 #include <samchon/templates/slave/PInvoke.hpp>
5 #include <samchon/examples/interaction/base/MasterBase.hpp>
6 #include <samchon/examples/interaction/TSPRequest.hpp>
7 #include <samchon/examples/interaction/PackerRequest.hpp>
8 
9 namespace samchon
10 {
11 namespace examples
12 {
13 namespace interaction
14 {
15  class ChiefDriver
16  : public templates::slave::SlaveClient
17  {
18  private:
19  typedef templates::slave::SlaveClient super;
20 
21  base::MasterBase *master;
22  int uid;
23 
24  public:
25  /* ---------------------------------------------------------
26  CONSTRUCTORS
27  --------------------------------------------------------- */
28  ChiefDriver(base::MasterBase *master)
29  : super()
30  {
31  this->master = master;
32  this->uid = -1;
33  };
34  virtual ~ChiefDriver() = default;
35 
36  /* ---------------------------------------------------------
37  INVOKE MESSAGE CHAIN
38  --------------------------------------------------------- */
39  virtual void sendData(std::shared_ptr<protocol::Invoke> invoke) override
40  {
41  super::sendData(invoke);
42 
43  if (uid != -1)
44  master->getMonitor()->reportSendData(uid, invoke);
45  };
46  virtual void replyData(std::shared_ptr<protocol::Invoke> invoke) override
47  {
48  if (invoke->getListener() == "set_chief_uid")
49  uid = invoke->front()->getValue<int>();
50  else
51  {
52  auto pInvoke = std::dynamic_pointer_cast<templates::slave::PInvoke>(invoke);
53  if (pInvoke != nullptr)
54  {
55  pInvoke->hold();
56  ((base::MasterBase*)master)->_Get_p_invoke_queue().push(pInvoke);
57  }
58 
59  if (invoke->getListener() == "optimizeTSP")
60  master->getTSP()->optimize(invoke->front()->getValueAsXML());
61  else if (invoke->getListener() == "optimizePacker")
62  master->getPacker()->optimize(invoke->front()->getValueAsXML());
63  }
64  };
65  };
66 };
67 };
68 };
virtual void replyData(std::shared_ptr< Invoke >)=0
virtual void sendData(std::shared_ptr< Invoke >)=0