Samchon Framework for CPP  1.0.0
InvokeHistory.hpp
1 #pragma once
2 #include <samchon/API.hpp>
3 
4 #include <samchon/protocol/Entity.hpp>
5 
6 #include <samchon/library/Date.hpp>
7 #include <samchon/protocol/Invoke.hpp>
8 
9 namespace samchon
10 {
11 namespace templates
12 {
13 namespace slave
14 {
29  : public protocol::Entity<size_t>
30  {
31  private:
33 
34  private:
35  size_t uid_;
36 
37  std::string listener_;
38  library::Date start_time_;
39  library::Date end_time_;
40 
41  public:
42  /* ---------------------------------------------------------
43  CONSTRUCTORS
44  --------------------------------------------------------- */
48  InvokeHistory() : super()
49  {
50  };
51 
57  InvokeHistory(std::shared_ptr<protocol::Invoke> invoke)
58  : super()
59  {
60  uid_ = invoke->get("_History_uid")->getValue<size_t>();
61  listener_ = invoke->getListener();
62 
63  start_time_ = std::chrono::system_clock::now();
64  };
65 
66  virtual ~InvokeHistory() = default;
67 
68  virtual void construct(std::shared_ptr<library::XML> xml) override
69  {
70  // UID AND LISTENER
71  uid_ = xml->getProperty<size_t>("uid");
72  listener_ = xml->getProperty("listener");
73 
74  //--------
75  // START AND END TIME
76  //--------
77  // INIT TIMES TO DEFAULT (0; 1970-01-01 09:00:00
78  start_time_ = std::chrono::system_clock::from_time_t(0);
79  end_time_ = std::chrono::system_clock::from_time_t(0);
80 
81  // ADD NUMBERS WHO REPRESENT LINUX_TIME
82  start_time_ += std::chrono::duration<long long, std::ratio_multiply<std::ratio<100i64, 1i64>, std::nano>>(xml->getProperty<long long>("startTime"));
83  end_time_ += std::chrono::duration<long long, std::ratio_multiply<std::ratio<100i64, 1i64>, std::nano>>(xml->getProperty<long long>("endTime"));
84  };
85 
86  /* ---------------------------------------------------------
87  ACCESSORS
88  --------------------------------------------------------- */
89  virtual auto key() const -> size_t override
90  {
91  return uid_;
92  };
93 
97  auto getUID() const -> size_t
98  {
99  return uid_;
100  };
101 
105  auto getListener() const -> std::string
106  {
107  return listener_;
108  };
109 
110  auto getStartTime() const -> library::Date
111  {
112  return start_time_;
113  };
114  auto getEndTime() const -> library::Date
115  {
116  return end_time_;
117  };
118 
119  void setStartTime(const library::Date &val)
120  {
121  start_time_ = val;
122  };
123  void setEndTime(const library::Date &val)
124  {
125  end_time_ = val;
126  };
127 
133  auto computeElapsedTime() const -> long long
134  {
135  return (end_time_ - start_time_).count();
136  };
137 
143  void complete()
144  {
145  end_time_ = std::chrono::system_clock::now();
146  };
147 
148  /* ---------------------------------------------------------
149  EXPORTERS
150  --------------------------------------------------------- */
151  virtual auto TAG() const -> std::string
152  {
153  return "history";
154  };
155 
156  virtual auto toXML() const -> std::shared_ptr<library::XML> override
157  {
158  std::shared_ptr<library::XML> &xml = super::toXML();
159  xml->setProperty("uid", uid_);
160  xml->setProperty("listener", listener_);
161 
162  xml->setProperty("startTime", start_time_.time_since_epoch().count());
163  xml->setProperty("endTime", end_time_.time_since_epoch().count());
164 
165  return xml;
166  };
167 
168  auto toInvoke() const -> std::shared_ptr<protocol::Invoke>
169  {
170  return std::make_shared<protocol::Invoke>("_Report_history", toXML());
171  };
172  };
173 };
174 };
175 };
An entity, a standard data class.
Definition: Entity.hpp:115
InvokeHistory(std::shared_ptr< protocol::Invoke > invoke)
auto computeElapsedTime() const -> long long
virtual auto key() const -> size_t override
Get a key that can identify the Entity uniquely.
auto getListener() const -> std::string
Date (year, month, day in month)
Definition: Date.hpp:38