Samchon Framework for CPP  1.0.0
Slave.hpp
1 #pragma once
2 #include <samchon/protocol/slave/ParallelClient.hpp>
3 
4 #include <samchon/protocol/Invoke.hpp>
5 #include <iostream>
6 
7 namespace samchon
8 {
9 namespace example
10 {
11 namespace interaction
12 {
13  using namespace std;
14 
15  using namespace library;
16  using namespace protocol;
17 
43  class Slave
44  : public protocol::slave::ParallelClient
45  {
46  private:
47  typedef protocol::slave::ParallelClient super;
48 
49  public:
50  /* ------------------------------------------------------------
51  CONSTRUCTORS
52  ------------------------------------------------------------ */
59  Slave(const string &ip, int port)
60  : super()
61  {
62  this->ip = ip;
63  this->port = port;
64  };
65  virtual ~Slave() = default;
66 
67  /* ------------------------------------------------------------
68  INVOKE MESSAGE CHAIN
69  ------------------------------------------------------------ */
70  virtual void replyPieceData(shared_ptr<Invoke> invoke, size_t index, size_t size) override
71  {
72  if (invoke->getListener() == "optimize")
73  optimize
74  (
75  invoke->at(0)->getValueAsXML(),
76  index,
77  size
78  );
79  };
80 
81  protected:
89  virtual void optimize(shared_ptr<XML> xml, size_t index, size_t size)
90  {
91  cout << "----------------------------------------------------------------------------" << endl;
92  cout << " OPTIMIZE FROM " << index << ", SIZE: " << size << endl;
93  cout << "----------------------------------------------------------------------------" << endl;
94  };
95 
101  void sendOptimization(shared_ptr<XML> xml)
102  {
103  sendData( make_shared<Invoke>("replyOptimization", xml) );
104  };
105  };
106 };
107 };
108 };
Slave(const string &ip, int port)
Construct from ip address and port number of master.
Definition: Slave.hpp:59
virtual void optimize(shared_ptr< XML > xml, size_t index, size_t size)
Optimize something and report the result.
Definition: Slave.hpp:89
void sendOptimization(shared_ptr< XML > xml)
Send (report) optimization result to its master system.
Definition: Slave.hpp:101
A slave system for optimizing something.
Definition: Slave.hpp:43