Verified Commit 7e47dc28 authored by Andrei Pavel's avatar Andrei Pavel 🐧
Browse files

[#562] template adapters to existing qualified names

parent 03452520
......@@ -644,7 +644,7 @@ public:
/// @brief Creates input binding for user context parameter.
///
/// @param T Type of the configuration element to which context belongs.
/// @tparam T Type of the configuration element to which context belongs.
/// @param network Pointer to a shared network, subnet or other configuration
/// element for which binding should be created.
/// @return Pointer to the binding (possibly null binding if context is
......
......@@ -56,6 +56,7 @@ libkea_dhcp___la_SOURCES += pkt_filter.h pkt_filter.cc
libkea_dhcp___la_SOURCES += pkt_filter6.h pkt_filter6.cc
libkea_dhcp___la_SOURCES += pkt_filter_inet.cc pkt_filter_inet.h
libkea_dhcp___la_SOURCES += pkt_filter_inet6.cc pkt_filter_inet6.h
libkea_dhcp___la_SOURCES += pkt_template.h
libkea_dhcp___la_SOURCES += socket_info.h
# Utilize Linux Packet Filtering on Linux.
......@@ -138,6 +139,7 @@ libkea_dhcp___include_HEADERS = \
pkt_filter6.h \
pkt_filter_inet.h \
pkt_filter_inet6.h \
pkt_template.h \
protocol_util.h \
socket_info.h \
std_option_defs.h
......
......@@ -44,7 +44,7 @@ typedef boost::shared_ptr<OptionUint32> OptionUint32Ptr;
/// - int16_t,
/// - int32_t.
///
/// @param T data field type (see above).
/// @tparam T data field type (see above).
template<typename T>
class OptionInt: public Option {
private:
......
......@@ -51,7 +51,7 @@ typedef boost::shared_ptr<OptionUint32Array> OptionUint32ArrayPtr;
/// allow addition of sub-options but they will be ignored during
/// packing and unpacking option data.
///
/// @param T data field type (see above).
/// @tparam T data field type (see above).
template<typename T>
class OptionIntArray: public Option {
private:
......
// Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef ISC_PKT_TEMPLATE_H
#define ISC_PKT_TEMPLATE_H
#include <dhcp/pkt4.h>
#include <dhcp/pkt6.h>
#include <util/dhcp_space.h>
namespace isc {
namespace dhcp {
/// @brief adapters for linking templates to qualified names
/// @{
namespace {
template <isc::util::DhcpSpace D>
struct adapter_Pkt {};
template <>
struct adapter_Pkt<isc::util::DHCPv4> {
using type = Pkt4;
};
template <>
struct adapter_Pkt<isc::util::DHCPv6> {
using type = Pkt6;
};
} // namespace
template <isc::util::DhcpSpace D>
using PktT = typename adapter_Pkt<D>::type;
template <isc::util::DhcpSpace D>
using PktTPtr = boost::shared_ptr<PktT<D>>;
/// @}
} // namespace dhcp
} // namespace isc
#endif // ISC_PKT_TEMPLATE_H
......@@ -15,7 +15,9 @@
#include <dhcpsrv/network.h>
#include <dhcpsrv/pool.h>
#include <dhcpsrv/subnet_id.h>
#include <util/dhcp_space.h>
#include <util/triplet.h>
#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/indexed_by.hpp>
#include <boost/multi_index/ordered_index.hpp>
......@@ -25,6 +27,7 @@
#include <boost/pointer_cast.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <cstdint>
#include <map>
#include <mutex>
......@@ -995,9 +998,33 @@ using SubnetFetcher4 = SubnetFetcher<Subnet4Ptr, Subnet4Collection>;
/// @brief Type of the @c SubnetFetcher used for IPv6.
using SubnetFetcher6 = SubnetFetcher<Subnet6Ptr, Subnet6Collection>;
//@}
/// @brief adapters for linking templates to qualified names
/// @{
namespace {
//@}
template <isc::util::DhcpSpace D>
struct adapter_Subnet {};
template <>
struct adapter_Subnet<isc::util::DHCPv4> {
using type = Subnet4;
};
template <>
struct adapter_Subnet<isc::util::DHCPv6> {
using type = Subnet6;
};
} // namespace
template <isc::util::DhcpSpace D>
using SubnetT = typename adapter_Subnet<D>::type;
template <isc::util::DhcpSpace D>
using SubnetTPtr = boost::shared_ptr<SubnetT<D>>;
/// @}
} // end of isc::dhcp namespace
} // end of isc namespace
......
......@@ -159,5 +159,25 @@ ScopedCalloutHandleState::resetState() {
callout_handle_->setStatus(CalloutHandle::NEXT_STEP_CONTINUE);
}
template <>
char const* queryArgument<isc::util::DHCPv4>() {
return "query4";
}
template <>
char const* queryArgument<isc::util::DHCPv6>() {
return "query6";
}
template <>
char const* subnetArgument<isc::util::DHCPv4>() {
return "subnet4";
}
template <>
char const* subnetArgument<isc::util::DHCPv6>() {
return "subnet6";
}
} // namespace hooks
} // namespace isc
......@@ -10,6 +10,7 @@
#include <exceptions/exceptions.h>
#include <hooks/library_handle.h>
#include <hooks/parking_lots.h>
#include <util/dhcp_space.h>
#include <boost/any.hpp>
#include <boost/shared_ptr.hpp>
......@@ -501,6 +502,12 @@ private:
CalloutHandlePtr callout_handle_;
};
template <isc::util::DhcpSpace D>
char const* queryArgument();
template <isc::util::DhcpSpace D>
char const* subnetArgument();
} // namespace hooks
} // namespace isc
......
......@@ -11,6 +11,7 @@ libkea_util_la_SOURCES = boost_time_utils.h boost_time_utils.cc
libkea_util_la_SOURCES += buffer.h io_utilities.h
libkea_util_la_SOURCES += chrono_time_utils.h chrono_time_utils.cc
libkea_util_la_SOURCES += csv_file.h csv_file.cc
libkea_util_la_SOURCES += dhcp_space.cc dhcp_space.h
libkea_util_la_SOURCES += doubles.h
libkea_util_la_SOURCES += file_utilities.h file_utilities.cc
libkea_util_la_SOURCES += filename.h filename.cc
......@@ -59,6 +60,7 @@ libkea_util_include_HEADERS = \
boost_time_utils.h \
buffer.h \
csv_file.h \
dhcp_space.h \
doubles.h \
file_utilities.h \
filename.h \
......
// Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h>
#include <util/dhcp_space.h>
namespace isc {
namespace util {
template <>
uint16_t integerDhcpSpace<DHCPv4>() {
return 4;
}
template <>
uint16_t integerDhcpSpace<DHCPv6>() {
return 6;
}
template <>
char const* cStringDhcpSpace<DHCPv4>() {
return "4";
}
template <>
char const* cStringDhcpSpace<DHCPv6>() {
return "6";
}
} // namespace util
} // namespace isc
// Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef ISC_DHCP_SPACE_H
#define ISC_DHCP_SPACE_H 1
#include <cstdint>
namespace isc {
namespace util {
enum DhcpSpace {
DHCPv4,
DHCPv6,
};
template <DhcpSpace D>
constexpr uint16_t integerDhcpSpace();
template <DhcpSpace D>
constexpr char const* cStringDhcpSpace();
} // namespace util
} // namespace isc
#endif // ISC_DHCP_SPACE_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment