]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#103,!289] Hold database id in the StampedElement.
authorMarcin Siodelski <marcin@isc.org>
Wed, 27 Mar 2019 16:47:47 +0000 (17:47 +0100)
committerMarcin Siodelski <marcin@isc.org>
Wed, 10 Apr 2019 14:57:42 +0000 (16:57 +0200)
src/lib/cc/stamped_element.cc
src/lib/cc/stamped_element.h
src/lib/cc/tests/stamped_element_unittest.cc

index 32bf59588ea0cb9f15d0cfe135dd20068aed8d62..0da5aa373577aae74a07d3524b0aa573355aa371 100644 (file)
@@ -12,7 +12,7 @@ namespace data {
 StampedElement::StampedElement()
     /// @todo Change it to microsec_clock once we transition to subsecond
     /// precision.
-    : timestamp_(boost::posix_time::second_clock::local_time()) {
+    : id_(0), timestamp_(boost::posix_time::second_clock::local_time()) {
 }
 
 void
index b6a59e913cc43564b845c1e9b22705f0b0d50dd8..63e69d1bf7b026692f8543b4c7abd5cf2b091129 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2019 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
@@ -8,19 +8,21 @@
 #define STAMPED_ELEMENT_H
 
 #include <boost/date_time/posix_time/posix_time.hpp>
+#include <cstdint>
 
 namespace isc {
 namespace data {
 
 /// @brief This class represents configuration element which is
-/// associated with the modification timestamp.
+/// associated with database identifier and the modification
+/// timestamp.
 ///
 /// Classes storing Kea configuration should derive from this object
-/// to track modification times of the configuration objects. This
-/// is specifically required by the Kea Configuration Backend feature
-/// which stores configuration in the database and must be able
-/// to recognize recently modified objects to fetch incremental
-/// changes.
+/// to track ids and modification times of the configuration objects.
+/// This is specifically required by the Kea Configuration Backend
+/// feature which stores and fetches configuration from the database.
+/// The configuration elements must be accessible by their database
+/// identifiers and modification times.
 ///
 /// @note This class is not derived from @c Element and should not
 /// be confused with the classes being derived from @c Element class.
@@ -36,6 +38,18 @@ public:
     /// Sets timestamp to the current time.
     StampedElement();
 
+    /// @brief Sets element's database identifier.
+    ///
+    /// @param id New id.
+    void setId(const uint64_t id) {
+        id_ = id;
+    }
+
+    /// @brief Returns element's database identifier.
+    uint64_t getId() const {
+        return (id_);
+    }
+
     /// @brief Sets timestamp to the explicitly provided value.
     ///
     /// @param timestamp New timestamp value.
@@ -53,6 +67,12 @@ public:
 
 private:
 
+    /// @brief Database identifier of the configuration element.
+    ///
+    /// The default value of 0 indicates that the identifier is
+    /// not set. 
+    uint64_t id_;
+
     /// @brief Holds timestamp value.
     boost::posix_time::ptime timestamp_;
 
index 402b3811a94088ba29c934dbadb17ba546a87126..8ca5378297a059b178ae7c5023d5eb7787df30aa 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2019 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
@@ -16,10 +16,13 @@ using namespace isc::data;
 namespace {
 
 // Tests that the modification timestamp is by default set to current
-// time.
+// time and the identifier is set to 0.
 TEST(StampedElementTest, create) {
     StampedElement element;
 
+    // Default identifier is 0.
+    EXPECT_EQ(0, element.getId());
+
     // Checking that the delta between now and the timestamp is within
     // 5s range should be sufficient.
     boost::posix_time::time_duration delta =
@@ -28,6 +31,13 @@ TEST(StampedElementTest, create) {
     EXPECT_LT(delta.seconds(), 5);
 }
 
+// Tests that default id can be overriden by a new value.
+TEST(StampedElementTest, setId) {
+    StampedElement element;
+    element.setId(123);
+    EXPECT_EQ(123, element.getId());
+}
+
 // Tests that the modification timestamp can be set to an arbitrary
 // value.
 TEST(StampedElementTest, setModificationTime) {