SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Event.h
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 
7 #ifndef swcdb_core_comm_Event_h
8 #define swcdb_core_comm_Event_h
9 
10 
11 #include "swcdb/core/Time.h"
12 #include "swcdb/core/Buffer.h"
13 #include "swcdb/core/Exception.h"
15 #include "swcdb/core/comm/Header.h"
16 
17 
18 namespace SWC { namespace Comm {
19 
20 class Event final {
21 
22  private:
23 
25  explicit Event(int a_error) noexcept
26  : expiry_ms(0),
27  data(), data_ext(), header(),
28  error(a_error) {
29  }
30 
31  public:
32 
33  typedef std::shared_ptr<Event> Ptr;
34 
36  static Ptr make(int error) {
37  return Ptr(new Event(error));
38  }
39 
40  ~Event() noexcept;
41 
43  void received() noexcept {
44  if(header.timeout_ms)
46  }
47 
48  void decode_buffers();
49 
51  bool expired(int64_t within=0) const noexcept {
52  return expiry_ms && Time::now_ms() > (expiry_ms - within);
53  }
54 
55  int32_t response_code() const noexcept;
56 
57  void print(std::ostream& out) const;
58 
59  int64_t expiry_ms;
63  int error;
64 
65 };
66 
67 
68 
71  int err = Error::OK;
72  uint8_t n = 1;
73  header.data.decode(err, data);
74  if(!err && header.buffers > 1) {
75  ++n;
77  }
78 
79  if(err) {
81  data.free();
82  data_ext.free();
85  << "decode, REQUEST ENCODER_DECODE: n(" << int(n) << ") ";
87  );
88  }
89 }
90 
91 
92 
93 }} // namespace SWC::Comm
94 
95 
96 #ifdef SWC_IMPL_SOURCE
97 #include "swcdb/core/comm/Event.cc"
98 #endif
99 
100 #endif // swcdb_core_comm_Event_h
SWC::Comm::Event::header
Header header
Definition: Event.h:62
SWC_LOG_OSTREAM
#define SWC_LOG_OSTREAM
Definition: Logger.h:44
SWC::Comm::Event::expiry_ms
int64_t expiry_ms
Definition: Event.h:59
SWC_LOG_OUT
#define SWC_LOG_OUT(pr, _code_)
Definition: Logger.h:178
SWC::Comm::Event::Event
SWC_CAN_INLINE Event(int a_error) noexcept
Definition: Event.h:25
SWC::Comm::Event::decode_buffers
void decode_buffers()
Definition: Event.h:70
SWC::Comm::Event::print
void print(std::ostream &out) const
Definition: Event.cc:36
SWC::Comm::Event::data
StaticBuffer data
Primary data buffer.
Definition: Event.h:60
SWC::Comm::Header::data
BufferInfo data
Data Buffer.
Definition: Header.h:81
SWC::Comm::Event::error
int error
Definition: Event.h:63
SWC::Comm::Event::data_ext
StaticBuffer data_ext
Extended buffer.
Definition: Event.h:61
SWC::Comm::Event::~Event
~Event() noexcept
Definition: Event.cc:15
SWC::Comm::Header::data_ext
BufferInfo data_ext
Data Extended Buffer.
Definition: Header.h:82
SWC::Comm::Event::response_code
int32_t response_code() const noexcept
Definition: Event.cc:17
SWC::Error::OK
@ OK
Definition: Error.h:45
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::Comm::Event::received
SWC_CAN_INLINE void received() noexcept
Definition: Event.h:43
Exception.h
SWC::Comm::Event
Definition: Event.h:20
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Core::Buffer
Definition: Buffer.h:18
Serialization.h
SWC::Comm::BufferInfo::decode
SWC_CAN_INLINE void decode(const uint8_t **bufp, size_t *remainp)
Definition: HeaderBufferInfo.h:53
Buffer.h
Time.h
SWC::Core::Buffer::free
SWC_CAN_INLINE void free() noexcept
Definition: Buffer.h:85
SWC::Comm::Header::buffers
uint8_t buffers
number of buffers from 0 to 2 (data+data_ext)
Definition: Header.h:75
SWC::Comm::Header::timeout_ms
uint32_t timeout_ms
Request timeout.
Definition: Header.h:77
SWC::Comm::Event::make
static SWC_CAN_INLINE Ptr make(int error)
Definition: Event.h:36
SWC::Time::now_ms
SWC_CAN_INLINE int64_t now_ms() noexcept
Definition: Time.h:36
Event.cc
SWC::LOG_WARN
@ LOG_WARN
Definition: Logger.h:33
SWC::Comm::Event::Ptr
std::shared_ptr< Event > Ptr
Definition: Event.h:33
SWC::Comm::Header
Definition: Header.h:18
SWC::Comm::Event::expired
SWC_CAN_INLINE bool expired(int64_t within=0) const noexcept
Definition: Event.h:51
SWC::Error::REQUEST_TRUNCATED_PAYLOAD
@ REQUEST_TRUNCATED_PAYLOAD
Definition: Error.h:72
Header.h