Samchon Framework for CPP  1.0.0
ExternalSystemRole.cpp
1 #include <samchon/protocol/ExternalSystemRole.hpp>
2 #include <samchon/protocol/ExternalSystem.hpp>
3 
4 using namespace std;
5 using namespace samchon::library;
6 using namespace samchon::protocol;
7 
8 /* ------------------------------------------------------------------
9  CONSTRUCTORS
10 ------------------------------------------------------------------ */
11 ExternalSystemRole::ExternalSystemRole(ExternalSystem *system)
12  : super()
13 {
14  this->system = system;
15 }
16 
17 void ExternalSystemRole::construct(shared_ptr<XML> xml)
18 {
19  name = xml->getProperty("name");
20 
21  constructListeners( sendListeners, xml->get("sendListeners")->at(0) );
22  constructListeners( replyListeners, xml->get("replyListeners")->at(0) );
23 }
24 void ExternalSystemRole::constructListeners(set<string> &listenerSet, shared_ptr<XML> xml)
25 {
26  listenerSet.clear();
27  if(xml->has("listener") == false)
28  return;
29 
30  shared_ptr<XMLList> &xmlList = xml->get("listener");
31  for (size_t i = 0; i < xmlList->size(); i++)
32  listenerSet.insert( xmlList->at(i)->getValue() );
33 }
34 
35 /* ------------------------------------------------------------------
36  GETTERS
37 ------------------------------------------------------------------ */
39 {
40  return system;
41 }
42 auto ExternalSystemRole::key() const -> string
43 {
44  return name;
45 }
46 
47 auto ExternalSystemRole::hasSendListener(const string &key) const -> bool
48 {
49  return sendListeners.count(key) >= 1;
50 }
51 auto ExternalSystemRole::hasReplyListener(const string &key) const -> bool
52 {
53  return replyListeners.count(key) >= 1;
54 }
55 
56 /* ------------------------------------------------------------------
57  CHAIN OF INVOKE MESSAGE
58 ------------------------------------------------------------------ */
59 void ExternalSystemRole::sendData(shared_ptr<Invoke> invoke)
60 {
61  system->sendData(invoke);
62 }
63 
64 /* ------------------------------------------------------------------
65  EXPORTERS
66 ------------------------------------------------------------------ */
67 auto ExternalSystemRole::TAG() const -> string
68 {
69  return "role";
70 }
71 
72 auto ExternalSystemRole::toXML() const -> shared_ptr<XML>
73 {
74  shared_ptr<XML> &xml = super::toXML();
75  xml->setProperty("name", name);
76 
77  xml->push_back( toListenersXML(sendListeners, "sendListeners") );
78  xml->push_back( toListenersXML(replyListeners, "replyListeners") );
79 
80  return xml;
81 }
82 auto ExternalSystemRole::toListenersXML(const set<string> &listenerSet, const string &tag) const -> shared_ptr<XML>
83 {
84  shared_ptr<XML> xml(new XML());
85  xml->setTag(tag);
86 
87  for (auto it = listenerSet.begin(); it != listenerSet.end(); it++)
88  {
89  shared_ptr<XML> listener(new XML());
90  listener->setTag("listener");
91  listener->setValue(*it);
92 
93  xml->push_back(listener);
94  }
95  return xml;
96 }
auto getSystem() const -> ExternalSystem *
Get an external system driver.
An entity, a standard data class.
Definition: Entity.hpp:48
ExternalSystem * system
A driver of external system containing the ExternalSystemRole.
virtual auto toXML() const -> std::shared_ptr< library::XML >
Get an XML object represents the Entity.
Definition: Entity.cpp:30
virtual auto key() const -> std::string override
Get a key that can identify the Entity uniquely.
std::string name
A name representing the role.
Definition: RWMutex.hpp:4
virtual void construct(std::shared_ptr< library::XML >) override
Construct data of the Entity from an XML object.
Package of libraries.
Definition: library.hpp:84
virtual void sendData(std::shared_ptr< Invoke >)
Sends message to a related system.
Definition: IClient.cpp:309
std::set< std::string > sendListeners
Listeners to send in the role.
auto hasSendListener(const std::string &) const -> bool
Test whether has a listener for send in the role.
virtual void sendData(std::shared_ptr< Invoke >) override
Send a message.
Package of network protocol and libraries.
Definition: protocol.hpp:185
virtual auto TAG() const -> std::string override
A tag name when represented by XML.
A network driver for an external system.
std::set< std::string > replyListeners
Listeners to reply in the role.
XML is a class representing xml object.
Definition: XML.hpp:72
auto hasReplyListener(const std::string &) const -> bool
Test whether has a listener for reply in the role.
virtual auto toXML() const -> std::shared_ptr< library::XML > override
Get an XML object represents the Entity.