SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
ColumnList.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_broker_Protocol_handlers_ColumnList_h
8 #define swcdb_broker_Protocol_handlers_ColumnList_h
9 
10 
12 
13 
14 namespace SWC { namespace Comm { namespace Protocol {
15 namespace Bkr { namespace Handler {
16 
17 
18 struct ColumnList {
19 
25  ColumnList(const ConnHandlerPtr& a_conn, const Event::Ptr& a_ev) noexcept
26  : conn(a_conn), ev(a_ev), remain(0), processed(false) {
27  }
28 
29  ~ColumnList() noexcept { }
30 
33  return Env::Clients::get();
34  }
35 
37  bool valid() {
38  return !ev->expired() && conn->is_open() && Env::Bkr::is_accepting();
39  }
40 
43  int err, const Mngr::Params::ColumnListRsp& rsp) {
44  bool last = true;
45  if(!ev->expired() && conn->is_open()) {
48  Buffers::Ptr cbp;
49  if(err) {
50  cbp = Buffers::make(ev, 4);
51  } else {
52  cbp = Buffers::make(ev, rsp, 4);
53  if(rsp.expected) {
54  uint64_t at = 0;
56  if(remain.sub_rslt(rsp.schemas.size())) {
57  cbp->header.flags |= Header::FLAG_RESPONSE_PARTIAL_BIT;
58  last = false;
59  }
60  }
61  }
62  cbp->append_i32(err);
63  conn->send_response(cbp);
64  }
65  if(!err)
66  Env::Clients::get()->schemas.set(rsp.schemas);
67  if(last && !processed.running())
69  }
70 
71 };
72 
73 
74 void column_list(const ConnHandlerPtr& conn, const Event::Ptr& ev) {
75  try {
76  const uint8_t *ptr = ev->data.base;
77  size_t remain = ev->data.size;
78 
80  params.decode(&ptr, &remain);
81 
83  params, ev->header.timeout_ms, conn, ev);
84 
85  } catch(...) {
88 
89  auto cbp = Buffers::make(ev, 4);
90  cbp->append_i32(e.code());
91  conn->send_response(cbp);
93  }
94 }
95 
96 
97 
98 }}}}}
99 
100 #endif // swcdb_broker_Protocol_handlers_ColumnList_h
SWC::Comm::Protocol::Bkr::Handler::ColumnList::get_clients
SWC_CAN_INLINE SWC::client::Clients::Ptr & get_clients() noexcept
Definition: ColumnList.h:32
SWC::Core::AtomicBase::compare_exchange_weak
constexpr SWC_CAN_INLINE bool compare_exchange_weak(T &at, T value) noexcept
Definition: Atomic.h:52
SWC::Comm::Protocol::Bkr::Handler::ColumnList::processed
Core::StateRunning processed
Definition: ColumnList.h:23
SWC::Comm::Protocol::Mngr::Params::ColumnListReq
Definition: ColumnList.h:18
SWC::Error::Exception::code
constexpr SWC_CAN_INLINE int code() const noexcept
Definition: Exception.h:51
SWC_LOG_OSTREAM
#define SWC_LOG_OSTREAM
Definition: Logger.h:44
SWC::Error::SERVER_SHUTTING_DOWN
@ SERVER_SHUTTING_DOWN
Definition: Error.h:84
SWC::Env::Clients::get
static SWC_CAN_INLINE client::Clients::Ptr & get() noexcept
Definition: Clients.h:299
SWC::Comm::Buffers::Ptr
std::shared_ptr< Buffers > Ptr
Definition: Buffers.h:23
SWC_LOG_OUT
#define SWC_LOG_OUT(pr, _code_)
Definition: Logger.h:178
SWC::Core::Atomic< size_t >
SWC::client::Clients::Ptr
ClientsPtr Ptr
Definition: Clients.h:58
SWC::Comm::Protocol::Bkr::Handler::ColumnList::remain
Core::Atomic< size_t > remain
Definition: ColumnList.h:22
SWC::Comm::Protocol::Bkr::Handler::ColumnList::ColumnList
SWC_CAN_INLINE ColumnList(const ConnHandlerPtr &a_conn, const Event::Ptr &a_ev) noexcept
Definition: ColumnList.h:25
SWC::Comm::Header::FLAG_RESPONSE_PARTIAL_BIT
static const uint8_t FLAG_RESPONSE_PARTIAL_BIT
Definition: Header.h:29
SWC::Comm::Protocol::Bkr::Handler::column_list
void column_list(const ConnHandlerPtr &conn, const Event::Ptr &ev)
Definition: ColumnList.h:74
SWC::Env::Bkr::is_accepting
static SWC_CAN_INLINE bool is_accepting() noexcept
Definition: BrokerEnv.h:37
SWC::Core::Atomic::sub_rslt
constexpr SWC_CAN_INLINE T sub_rslt(T v) noexcept
Definition: Atomic.h:115
SWC::Comm::Protocol::Bkr::Handler::ColumnList::valid
SWC_CAN_INLINE bool valid()
Definition: ColumnList.h:37
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::Comm::Protocol::Mngr::Req::ColumnList::request
static SWC_CAN_INLINE void request(const Params::ColumnListReq &params, const uint32_t timeout, DataArgsT &&... args)
Definition: ColumnList.h:36
SWC_CURRENT_EXCEPTION
#define SWC_CURRENT_EXCEPTION(_msg_)
Definition: Exception.h:119
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Comm::Protocol::Bkr::Handler::ColumnList::callback
SWC_CAN_INLINE void callback(const client::ConnQueue::ReqBase::Ptr &, int err, const Mngr::Params::ColumnListRsp &rsp)
Definition: ColumnList.h:42
ColumnList.h
SWC::Comm::Protocol::Bkr::Handler::ColumnList::conn
ConnHandlerPtr conn
Definition: ColumnList.h:20
SWC::Core::StateRunning::running
constexpr SWC_CAN_INLINE bool running() noexcept
Definition: StateRunning.h:37
SWC::Error::CLIENT_STOPPING
@ CLIENT_STOPPING
Definition: Error.h:127
SWC::LOG_ERROR
@ LOG_ERROR
Definition: Logger.h:32
SWC::Comm::ConnHandlerPtr
std::shared_ptr< ConnHandler > ConnHandlerPtr
Definition: AppContext.h:17
SWC::Comm::Protocol::Bkr::Handler::ColumnList
Definition: ColumnList.h:18
SWC::Comm::Protocol::Bkr::Handler::ColumnList::~ColumnList
~ColumnList() noexcept
Definition: ColumnList.h:29
SWC::Comm::Buffers::make
static SWC_CAN_INLINE Ptr make(uint32_t reserve=0)
Definition: Buffers.h:27
SWC::Comm::Protocol::Bkr::Handler::ColumnList::ev
Event::Ptr ev
Definition: ColumnList.h:21
SWC::Comm::Serializable::decode
void decode(const uint8_t **bufp, size_t *remainp)
Definition: Serializable.h:59
SWC::Core::StateRunning
Definition: StateRunning.h:16
SWC::Comm::Event::Ptr
std::shared_ptr< Event > Ptr
Definition: Event.h:33
SWC::Comm::client::ConnQueueReqBase::Ptr
std::shared_ptr< ConnQueueReqBase > Ptr
Definition: ClientConnQueue.h:25
SWC::Comm::Protocol::Mngr::Params::ColumnListRsp::expected
uint64_t expected
Definition: ColumnList.h:55
SWC::Env::Bkr::processed
static SWC_CAN_INLINE void processed() noexcept
Definition: BrokerEnv.h:55
SWC::Core::Vector::size
constexpr SWC_CAN_INLINE size_type size() const noexcept
Definition: Vector.h:189
SWC::Error::Exception
Definition: Exception.h:21
SWC::Comm::Protocol::Mngr::Params::ColumnListRsp
Definition: ColumnList.h:46
SWC::Comm::Protocol::Mngr::Params::ColumnListRsp::schemas
DB::SchemasVec schemas
Definition: ColumnList.h:56