Samchon Framework for CPP  1.0.0
InvokeHistory.cpp
1 #include <samchon/protocol/InvokeHistory.hpp>
2 
3 #include <samchon/library/XML.hpp>
4 #include <samchon/protocol/Invoke.hpp>
5 
6 using namespace std;
7 using namespace samchon::library;
8 using namespace samchon::protocol;
9 
10 /* -----------------------------------------------------------------
11  CONSTRUCTORS
12 ----------------------------------------------------------------- */
13 InvokeHistory::InvokeHistory()
14  : super()
15 {
16 }
17 InvokeHistory::InvokeHistory(shared_ptr<Invoke> invoke)
18  : super()
19 {
20  this->uid = invoke->get("invoke_history_uid")->getValue<size_t>();
21  this->listener = invoke->getListener();
22 
23  this->startTime = chrono::system_clock::now();
24 }
25 
26 void InvokeHistory::construct(shared_ptr<XML> xml)
27 {
28  this->uid = xml->getProperty<size_t>("uid");
29  this->listener = xml->getProperty("listener");
30 
31  startTime = chrono::system_clock::from_time_t(0);
32  endTime = chrono::system_clock::from_time_t(0);
33 
34  startTime +=
35  chrono::duration
36  <
37  long long,
38  ratio_multiply
39  <
40  ratio<100i64, 1i64>,
41  nano
42  >
43  >(xml->getProperty<long long>("startTime"));
44 
45  endTime +=
46  chrono::duration
47  <
48  long long,
49  ratio_multiply
50  <
51  ratio<100i64, 1i64>,
52  nano
53  >
54  >(xml->getProperty<long long>("endTime"));
55 }
57 {
58  endTime = chrono::system_clock::now();
59 }
60 
61 /* -----------------------------------------------------------------
62  GETTERS
63 ----------------------------------------------------------------- */
64 auto InvokeHistory::key() const -> string
65 {
66  return to_string(uid);
67 }
68 
69 auto InvokeHistory::getUID() const -> size_t
70 {
71  return uid;
72 }
73 auto InvokeHistory::getListener() const -> string
74 {
75  return listener;
76 }
78 {
79  return startTime;
80 }
82 {
83  return endTime;
84 }
85 
86 auto InvokeHistory::calcElapsedTime() const -> long long
87 {
88  return (endTime - startTime).count();
89 }
90 
91 /* -----------------------------------------------------------------
92  EXPORTERS
93 ----------------------------------------------------------------- */
94 auto InvokeHistory::TAG() const -> string
95 {
96  return "invokeHistory";
97 }
98 
99 auto InvokeHistory::toXML() const -> shared_ptr<XML>
100 {
101  shared_ptr<XML> &xml = super::toXML();
102 
103  xml->setProperty("uid", uid);
104  xml->setProperty("listener", listener);
105  xml->setProperty("startTime", startTime.time_since_epoch().count());
106  xml->setProperty("endTime", endTime.time_since_epoch().count());
107 
108  return xml;
109 }
110 auto InvokeHistory::toInvoke() const -> shared_ptr<Invoke>
111 {
112  return shared_ptr<Invoke>(new Invoke("reportInvokeHistory", toXML()));
113 }
auto getStartTime() const -> library::Datetime
Get start time.
An entity, a standard data class.
Definition: Entity.hpp:48
virtual auto toXML() const -> std::shared_ptr< library::XML >
Get an XML object represents the Entity.
Definition: Entity.cpp:30
virtual void construct(std::shared_ptr< library::XML >) override
Construct data of the Entity from an XML object.
Definition: RWMutex.hpp:4
Package of libraries.
Definition: library.hpp:84
library::Datetime endTime
End time of the history.
auto calcElapsedTime() const -> long long
Get elapsed time.
Package of network protocol and libraries.
Definition: protocol.hpp:185
auto getListener() const -> std::string
Get listener.
Standard message of network I/O.
Definition: Invoke.hpp:47
virtual auto TAG() const -> std::string override
A tag name when represented by XML.
virtual void notifyEnd()
Notify end of the process.
std::string listener
A listener of the Invoke message.
auto toInvoke() const -> std::shared_ptr< Invoke >
Get an Invoke message.
auto getUID() const -> size_t
Get uid.
XML is a class representing xml object.
Definition: XML.hpp:72
InvokeHistory()
Default Constructor.
auto getEndTime() const -> library::Datetime
Get end time.
virtual auto toXML() const -> std::shared_ptr< library::XML > override
Get an XML object represents the Entity.
library::Datetime startTime
Start time of the history.
virtual auto key() const -> std::string override
Get a key that can identify the Entity uniquely.