Samchon Framework for CPP  1.0.0
ExternalSystemArray.cpp
1 #include <samchon/protocol/ExternalSystemArray.hpp>
2 
3 #include <samchon/protocol/ExternalSystem.hpp>
4 #include <samchon/protocol/ExternalSystemRole.hpp>
5 #include <samchon/protocol/SystemRole.hpp>
6 
7 #include <thread>
8 #include <samchon/library/XML.hpp>
9 #include <samchon/protocol/Invoke.hpp>
10 
11 using namespace std;
12 using namespace samchon::library;
13 using namespace samchon::protocol;
14 
15 /* ------------------------------------------------------------------
16  CONSTRUCTORS
17 ------------------------------------------------------------------ */
18 ExternalSystemArray::ExternalSystemArray()
19  : super()
20 {
21 }
22 
23 /* ------------------------------------------------------------------
24  GETTERS
25 ------------------------------------------------------------------ */
26 auto ExternalSystemArray::hasRole(const std::string &name) const -> bool
27 {
28  for(size_t i = 0; i < size(); i++)
29  if (at(i)->has(name) == true)
30  return true;
31 
32  return false;
33 }
34 auto ExternalSystemArray::getRole(const std::string &name) const -> shared_ptr<ExternalSystemRole>
35 {
36  for(size_t i = 0; i < size(); i++)
37  if (at(i)->has(name) == true)
38  return at(i)->get(name);
39 
40  throw exception("out of range");
41 }
42 
43 /* ------------------------------------------------------------------
44  CHAIN OF INVOKE MESSAGE
45 ------------------------------------------------------------------ */
46 void ExternalSystemArray::sendData(shared_ptr<Invoke> invoke)
47 {
48  bool has = false;
49 
50  for(size_t i = 0; i < size(); i++)
51  for(size_t j = 0; j < at(i)->size(); j++)
52  if (at(i)->at(j)->hasSendListener(invoke->getListener()) == true)
53  {
54  thread(&ExternalSystemRole::sendData, at(i)->at(j).get(), invoke).detach();
55  has = true;
56  }
57 
58  if(has == true)
59  return;
60 
61  for(size_t i = 0; i < size(); i++)
62  for(size_t j = 0; j < at(i)->size(); j++)
63  thread(&ExternalSystemRole::sendData, at(i)->at(j).get(), invoke).detach();
64 }
65 void ExternalSystemArray::replyData(shared_ptr<Invoke>)
66 {
67  //NOTHING'S DEFINED
68 }
69 
70 /* ------------------------------------------------------------------
71  XML TAG
72 ------------------------------------------------------------------ */
73 auto ExternalSystemArray::TAG() const -> string
74 {
75  return "systemArray";
76 }
77 auto ExternalSystemArray::CHILD_TAG() const -> string
78 {
79  return "system";
80 }
auto has(const std::string &key) const -> bool
Indicates whether a container has an object having the specified identifier.
auto getRole(const std::string &) const -> std::shared_ptr< ExternalSystemRole >
Get a role.
virtual void replyData(std::shared_ptr< Invoke >) override
Handle replied Invoke message.
Definition: RWMutex.hpp:4
Package of libraries.
Definition: library.hpp:84
virtual auto TAG() const -> std::string override
A tag name when represented by XML.
virtual void sendData(std::shared_ptr< Invoke >) override
Send a message.
An Entity and a container of children Entity objects.
Definition: EntityGroup.hpp:52
Package of network protocol and libraries.
Definition: protocol.hpp:185
virtual auto CHILD_TAG() const -> std::string override
A tag name of children.
auto hasRole(const std::string &) const -> bool
Test whether has a role.
virtual void sendData(std::shared_ptr< Invoke >) override
Sends an Invoke message to related ExternalSystem(s).