3 #include <samchon/protocol/EntityGroup.hpp> 4 #include <samchon/examples/interaction/base/SystemBase.hpp> 6 #include <samchon/protocol/ClientDriver.hpp> 7 #include <samchon/examples/interaction/base/ReporterBase.hpp> 8 #include <samchon/examples/interaction/base/MonitorBase.hpp> 19 :
public protocol::EntityGroup<std::deque<System*>, System, int>,
20 public base::SystemBase
23 typedef protocol::EntityGroup<std::deque<System*>, System,
int> super;
30 std::shared_ptr<protocol::ClientDriver> driver;
39 System(Monitor *monitor, std::shared_ptr<protocol::ClientDriver> driver,
int uid)
42 this->monitor = monitor;
43 this->parent =
nullptr;
45 this->driver = driver;
49 sendData(std::make_shared<protocol::Invoke>(
"set_uid", uid));
55 auto &system_map = ((base::MonitorBase*)monitor)->getSystems();
56 system_map.erase(getUID());
58 if (parent !=
nullptr)
59 for (
size_t i = 0; i < parent->size(); i++)
60 if (parent->at(i) ==
this)
62 parent->erase(parent->begin() + i);
67 base::ReporterBase *reporter = (base::ReporterBase*)(((base::MonitorBase*)monitor)->getReporter());
68 reporter->sendSystems();
71 virtual void construct(std::shared_ptr<library::XML> xml)
override 73 setUID(xml->getProperty<
int>(
"uid"));
74 name = xml->getProperty<std::string>(
"name");
80 virtual auto createChild(std::shared_ptr<library::XML> xml) -> System*
82 auto &system_map = ((base::MonitorBase*)monitor)->getSystems();
83 int uid = xml->getProperty<
int>(
"uid");
85 if (system_map.has(uid) ==
false)
89 System *system = system_map.get(uid);
90 system->parent =
this;
100 virtual auto key() const ->
int override 105 auto getParent() const -> System*
110 void setParent(System *val)
118 virtual void sendData(std::shared_ptr<protocol::Invoke> invoke)
override 120 driver->sendData(invoke);
123 virtual void replyData(std::shared_ptr<protocol::Invoke> invoke)
override 125 if (invoke->getListener() ==
"construct")
127 construct(invoke->front()->getValueAsXML());
128 ((base::MonitorBase*)monitor)->constructSystemTree();
131 Reporter *reporter = ((base::MonitorBase*)monitor)->getReporter();
132 ((base::ReporterBase*)reporter)->sendSystems();
134 System *root = ((base::MonitorBase*)monitor)->getRootSystem();
135 std::cout << root->toXML()->toString() << std::endl;
139 else if (invoke->getListener() ==
"reportSendData")
141 std::string listener = invoke->at(0)->getValue<std::string>();
142 int to = invoke->at(1)->getValue<
int>();
143 int from = invoke->at(2)->getValue<
int>();
145 Reporter *reporter = ((base::MonitorBase*)monitor)->getReporter();
146 auto invoke = std::make_shared<protocol::Invoke>(
"printSendData", listener, from, to);
148 ((protocol::IProtocol*)reporter)->sendData(invoke);
150 std::cout << invoke->toXML()->toString() << std::endl;
156 virtual auto TAG() const ->
std::
string override 160 virtual auto CHILD_TAG() const ->
std::
string override 165 virtual auto toXML() const ->
std::shared_ptr<library::XML>
168 xml->setProperty(
"uid", getUID());
169 xml->setProperty(
"name", name);
virtual void construct(std::shared_ptr< library::XML > xml)
Construct data of the Entity from an XML object.
virtual void replyData(std::shared_ptr< Invoke >)=0
virtual void sendData(std::shared_ptr< Invoke >)=0
virtual auto toXML() const -> std::shared_ptr< library::XML >
Get an XML object represents the EntityGroup.