| Kea 3.0.2-git

bulk_lease_query.h
Go to the documentation of this file.
1// Copyright (C) 2022-2025 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef BULK_LEASE_QUERY_H
8#define BULK_LEASE_QUERY_H
9
10#include <config.h>
11
12#include <blq_msg.h>
13#include <boost/enable_shared_from_this.hpp>
14#include <functional>
15
16 namespace isc {
17 namespace lease_query {
18
20 typedef std::function<void ()> BlqPostCbArg;
21
23 typedef std::function<void (const BlqPostCbArg&)> BlqPostCb;
24
26 typedef std::function<bool (BlqResponsePtr)> BlqPushToSendCb;
27
29 typedef std::function<void (Xid)> BlqQueryCompleteCb;
30
32 class BulkLeaseQuery;
33
35 typedef boost::shared_ptr<BulkLeaseQuery> BulkLeaseQueryPtr;
36
38 class BulkLeaseQuery : public boost::enable_shared_from_this<BulkLeaseQuery> {
39 public:
40
48 BulkLeaseQuery(BlqQueryPtr query,
49 const BlqPostCb& post,
50 const BlqPushToSendCb& push_to_send,
51 const BlqQueryCompleteCb& query_complete)
52 : query_(query), post_(post), push_to_send_(push_to_send),
53 query_complete_(query_complete), started_(false), done_(false) {
54 if (!query) {
55 isc_throw(BadValue, "BulkLeaseQuery query is null");
56 }
57 }
58
60 virtual ~BulkLeaseQuery() {
61 }
62
68 virtual void init() = 0;
69
71 virtual void start() = 0;
72
76 static void processStart(BulkLeaseQueryPtr ptr) {
77 if (!ptr) {
78 // Should not happen.
79 return;
80 }
81 ptr->start();
82 }
83
88 bool isProcessing() const {
89 return (started_);
90 }
91
95 bool isProcessed() const {
96 return (done_);
97 }
98
102 BlqQueryPtr getQuery() {
103 return (query_);
104 }
105
109 uint8_t getQueryType() const {
110 return (query_type_);
111 }
112
116 Xid getXid() const {
117 return (query_->getXid());
118 }
119
120 protected:
122 virtual void setDone() {
123 done_ = true;
124 query_complete_(query_->getXid());
125 }
126
128 BlqQueryPtr query_;
129
131 BlqPostCb post_;
132
134 BlqPushToSendCb push_to_send_;
135
137 BlqQueryCompleteCb query_complete_;
138
140 uint8_t query_type_;
141
143 bool started_;
144
146 bool done_;
147};
148
149} // end of namespace isc::lease_query
150} // end of namespace isc
151
152#endif // BULK_LEASE_QUERY_H
blq_msg.h
isc::BadValue
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Definition exceptions/exceptions.h:132
isc::lease_query::BulkLeaseQuery
Base class for providing control flow for processing a bulk query.
Definition bulk_lease_query.h:38
isc::lease_query::BulkLeaseQuery::query_complete_
BlqQueryCompleteCb query_complete_
The queryComplete callback.
Definition bulk_lease_query.h:137
isc::lease_query::BulkLeaseQuery::isProcessing
bool isProcessing() const
Processing in progress predicate.
Definition bulk_lease_query.h:88
isc::lease_query::BulkLeaseQuery::query_type_
uint8_t query_type_
The query type.
Definition bulk_lease_query.h:140
isc::lease_query::BulkLeaseQuery::start
virtual void start()=0
Start processing.
isc::lease_query::BulkLeaseQuery::setDone
virtual void setDone()
Set the done flag.
Definition bulk_lease_query.h:122
isc::lease_query::BulkLeaseQuery::getQuery
BlqQueryPtr getQuery()
Get the query.
Definition bulk_lease_query.h:102
isc::lease_query::BulkLeaseQuery::post_
BlqPostCb post_
The post callback.
Definition bulk_lease_query.h:131
isc::lease_query::BulkLeaseQuery::isProcessed
bool isProcessed() const
Processing finished predicate.
Definition bulk_lease_query.h:95
isc::lease_query::BulkLeaseQuery::~BulkLeaseQuery
virtual ~BulkLeaseQuery()
Destructor.
Definition bulk_lease_query.h:60
isc::lease_query::BulkLeaseQuery::BulkLeaseQuery
BulkLeaseQuery(BlqQueryPtr query, const BlqPostCb &post, const BlqPushToSendCb &push_to_send, const BlqQueryCompleteCb &query_complete)
Constructor.
Definition bulk_lease_query.h:48
isc::lease_query::BulkLeaseQuery::query_
BlqQueryPtr query_
The query.
Definition bulk_lease_query.h:128
isc::lease_query::BulkLeaseQuery::init
virtual void init()=0
Initialization.
isc::lease_query::BulkLeaseQuery::started_
bool started_
The processing is in progress.
Definition bulk_lease_query.h:143
isc::lease_query::BulkLeaseQuery::getQueryType
uint8_t getQueryType() const
Get the query type.
Definition bulk_lease_query.h:109
isc::lease_query::BulkLeaseQuery::push_to_send_
BlqPushToSendCb push_to_send_
The pushToSend callback.
Definition bulk_lease_query.h:134
isc::lease_query::BulkLeaseQuery::processStart
static void processStart(BulkLeaseQueryPtr ptr)
Class/static start processing.
Definition bulk_lease_query.h:76
isc::lease_query::BulkLeaseQuery::done_
bool done_
The processing finished.
Definition bulk_lease_query.h:146
isc::lease_query::BulkLeaseQuery::getXid
Xid getXid() const
Get the transaction id of the query.
Definition bulk_lease_query.h:116
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
isc::lease_query
Definition blq_msg.h:15
isc::lease_query::BlqResponsePtr
boost::shared_ptr< BlqResponse > BlqResponsePtr
Defines a shared pointer to an BlqResponse.
Definition blq_msg.h:143
isc::lease_query::BlqPostCb
std::function< void(const BlqPostCbArg &)> BlqPostCb
Type of BLQ post callback.
Definition bulk_lease_query.h:23
isc::lease_query::BlqQueryCompleteCb
std::function< void(Xid)> BlqQueryCompleteCb
Type of BLQ queryComplete callback.
Definition bulk_lease_query.h:29
isc::lease_query::BlqPostCbArg
std::function< void()> BlqPostCbArg
Type of BLQ post callback argument..
Definition bulk_lease_query.h:20
isc::lease_query::Xid
uint32_t Xid
Defines a Bulk LeaseQuery transaction id.
Definition blq_msg.h:18
isc::lease_query::BlqQueryPtr
boost::shared_ptr< BlqQuery > BlqQueryPtr
Defines a shared pointer to an BlqQuery.
Definition blq_msg.h:116
isc::lease_query::BulkLeaseQueryPtr
boost::shared_ptr< BulkLeaseQuery > BulkLeaseQueryPtr
Defines a shared pointer to a BulkLeaseQuery object.
Definition bulk_lease_query.h:35
isc::lease_query::BlqPushToSendCb
std::function< bool(BlqResponsePtr)> BlqPushToSendCb
Type of BLQ pushToSend callback.
Definition bulk_lease_query.h:26
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148