2 #include <samchon/protocol/IProtocol.hpp> 4 #include <samchon/examples/interaction/base/SystemBase.hpp> 5 #include <samchon/protocol/ServerConnector.hpp> 7 #include <samchon/templates/external/base/ExternalSystemArrayBase.hpp> 15 class MonitorDriver :
public protocol::IProtocol
18 base::SystemBase *system;
19 std::unique_ptr<protocol::ServerConnector> connector;
25 MonitorDriver(base::SystemBase *system)
27 this->system = system;
28 connector.reset(
new protocol::ServerConnector(
this));
30 virtual ~MonitorDriver() =
default;
34 connector->connect(
"127.0.0.1", 37900);
40 virtual void sendData(std::shared_ptr<protocol::Invoke> invoke)
override 42 connector->sendData(invoke);
44 void reportSendData(
int to, std::shared_ptr<protocol::Invoke> invoke)
46 if (system->getUID() == -1)
49 sendData(std::make_shared<protocol::Invoke>(
"reportSendData", to, invoke->getListener()));
51 void sendSystemStructure()
53 if (system->getUID() == -1)
56 std::shared_ptr<library::XML> xml = system->toXML();
58 auto system_array =
dynamic_cast<templates::external::base::ExternalSystemArrayBase*
>(system);
59 if (system_array !=
nullptr)
61 auto children = system_array->_Get_children();
62 for (
size_t i = 0; i < children.size(); i++)
64 auto child = (base::SystemBase*)(children.at(i).get());
65 if (child->getUID() == -1)
70 xml->setTag(
"system");
71 sendData(std::make_shared<protocol::Invoke>(
"construct", xml));
74 virtual void replyData(std::shared_ptr<protocol::Invoke> invoke)
override 76 if (invoke->getListener() ==
"set_uid")
77 system->setUID(invoke->front()->getValue<
int>());
virtual void replyData(std::shared_ptr< Invoke >)=0
virtual void sendData(std::shared_ptr< Invoke >)=0