From: Razvan Becheriu Date: Tue, 12 Mar 2019 14:30:50 +0000 (+0200) Subject: implemented getPage4 and getPage6 using getAll4 and getAll6, sorting and filtering X-Git-Tag: Kea-1.6.0-beta~214 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66968738c08e383b9b574bf75e27fc8d6127c6a4;p=thirdparty%2Fkea.git implemented getPage4 and getPage6 using getAll4 and getAll6, sorting and filtering --- diff --git a/src/lib/dhcpsrv/cql_host_data_source.cc b/src/lib/dhcpsrv/cql_host_data_source.cc index 7e5c974c7a..42e7b91662 100644 --- a/src/lib/dhcpsrv/cql_host_data_source.cc +++ b/src/lib/dhcpsrv/cql_host_data_source.cc @@ -1985,19 +1985,47 @@ CqlHostDataSourceImpl::getAll6(const SubnetID& subnet_id) const { // paging at the API level. ConstHostCollection -CqlHostDataSourceImpl::getPage4(const SubnetID& /*subnet_id*/, - uint64_t /*lower_host_id*/, - const HostPageSize& /*page_size*/) const { - isc_throw(NotImplemented, - "reservation-get-page is not supported by Cassandra"); +CqlHostDataSourceImpl::getPage4(const SubnetID& subnet_id, + uint64_t lower_host_id, + const HostPageSize& page_size) const { + ConstHostCollection hosts = getAll4(subnet_id); + std::sort(hosts.begin(), hosts.end(), [](ConstHostPtr a, ConstHostPtr b) { + return a->getHostId() > b->getHostId(); + }); + ConstHostCollection result; + size_t count = 0; + for (auto host : hosts) { + if (host->getHostId() > lower_host_id) { + result.push_back(host); + count++; + if (count == page_size.page_size_) { + break; + } + } + } + return (result); } ConstHostCollection -CqlHostDataSourceImpl::getPage6(const SubnetID& /*subnet_id*/, - uint64_t /*lower_host_id*/, - const HostPageSize& /*page_size*/) const { - isc_throw(NotImplemented, - "reservation-get-page is not supported by Cassandra"); +CqlHostDataSourceImpl::getPage6(const SubnetID& subnet_id, + uint64_t lower_host_id, + const HostPageSize& page_size) const { + ConstHostCollection hosts = getAll6(subnet_id); + std::sort(hosts.begin(), hosts.end(), [](ConstHostPtr a, ConstHostPtr b) { + return a->getHostId() > b->getHostId(); + }); + ConstHostCollection result; + size_t count = 0; + for (auto host : hosts) { + if (host->getHostId() > lower_host_id) { + result.push_back(host); + count++; + if (count == page_size.page_size_) { + break; + } + } + } + return (result); } ConstHostCollection