Browse Source

[2835] Include the segment type

Specify the segment type used. This is SEGMENT_LOCAL for now with every
segment used, but it is ready for when we have different kinds of
segments too.
Michal 'vorner' Vaner 12 years ago
parent
commit
6e0725b08a

+ 2 - 1
src/lib/datasrc/client_list.cc

@@ -482,7 +482,8 @@ ConfigurableClientList::getStatus() const {
         // TODO: Once we support mapped cache, decide when we need the
         // SEGMENT_WAITING.
         result.push_back(DataSourceStatus(info.name_, info.cache_ ?
-                                          SEGMENT_MAPPED : SEGMENT_UNUSED));
+                                          SEGMENT_MAPPED : SEGMENT_UNUSED,
+                                          SEGMENT_LOCAL));
     }
     return (result);
 }

+ 26 - 6
src/lib/datasrc/client_list.h

@@ -54,7 +54,6 @@ enum MemorySegmentState {
     /// \brief No segment used for this data source.
     ///
     /// This is usually a result of the cache being disabled.
-
     SEGMENT_UNUSED,
 
     /// \brief It is a mapped segment and we wait for information how to map
@@ -65,6 +64,15 @@ enum MemorySegmentState {
     SEGMENT_MAPPED
 };
 
+/// \brief The type of the memory segment in cache
+enum MemorySegmentType {
+    /// \brief A locally loaded, unshared cache. Normal memory.
+    SEGMENT_LOCAL,
+
+    /// \brief A file image mapped into memory
+    SEGMENT_FILE
+};
+
 /// \brief Status of one data source.
 ///
 /// This indicates the status a data soure is in. It is used with segment
@@ -74,10 +82,13 @@ class DataSourceStatus {
 public:
     /// \brief Constructor
     ///
-    /// Sets initial values.
-    DataSourceStatus(const std::string& name, MemorySegmentState state) :
+    /// Sets initial values. It doesn't matter what is provided for the type
+    /// if state is SEGMENT_UNUSED, the value is effectively ignored.
+    DataSourceStatus(const std::string& name, MemorySegmentState state,
+                     MemorySegmentType type) :
         name_(name),
-        state_(state)
+        state_(state),
+        type_(type)
     {}
 
     /// \brief Get the current segment state
@@ -85,15 +96,24 @@ public:
         return (state_);
     }
 
-    /// \brief Get the current name.
+    /// \brief Get the current segment type
     ///
-    /// \note The name may not be changed once the object is constructed.
+    /// \throw isc::BadValue if called and state is SEGMENT_UNUSED.
+    MemorySegmentType getSegmentType() const {
+        if (getSegmentState() == SEGMENT_UNUSED) {
+            isc_throw(isc::BadValue, "No segment used, no type therefore.");
+        }
+        return (type_);
+    }
+
+    /// \brief Get the current name.
     const std::string& getName() const {
         return (name_);
     }
 private:
     std::string name_;
     MemorySegmentState state_;
+    MemorySegmentType type_;
 };
 
 /// \brief The list of data source clients.

+ 9 - 2
src/lib/datasrc/tests/client_list_unittest.cc

@@ -576,8 +576,10 @@ TEST_F(ListTest, status) {
     ASSERT_EQ(2, statuses.size());
     EXPECT_EQ("type1", statuses[0].getName());
     EXPECT_EQ(SEGMENT_UNUSED, statuses[0].getSegmentState());
+    EXPECT_THROW(statuses[0].getSegmentType(), isc::BadValue);
     EXPECT_EQ("Test name", statuses[1].getName());
     EXPECT_EQ(SEGMENT_MAPPED, statuses[1].getSegmentState());
+    EXPECT_EQ(SEGMENT_LOCAL, statuses[1].getSegmentType());
 }
 
 TEST_F(ListTest, wrongConfig) {
@@ -1163,9 +1165,14 @@ TYPED_TEST(ReloadTest, reloadMasterFile) {
 
 // Check the status holds data and can change the segment state
 TEST(DataSourceStatus, status) {
-    DataSourceStatus status("Test", SEGMENT_UNUSED);
+    DataSourceStatus status("Test", SEGMENT_MAPPED, SEGMENT_LOCAL);
     EXPECT_EQ("Test", status.getName());
-    EXPECT_EQ(SEGMENT_UNUSED, status.getSegmentState());
+    EXPECT_EQ(SEGMENT_MAPPED, status.getSegmentState());
+    EXPECT_EQ(SEGMENT_LOCAL, status.getSegmentType());
+    DataSourceStatus statusUnused("Unused", SEGMENT_UNUSED, SEGMENT_FILE);
+    EXPECT_EQ("Unused", statusUnused.getName());
+    EXPECT_EQ(SEGMENT_UNUSED, statusUnused.getSegmentState());
+    EXPECT_THROW(statusUnused.getSegmentType(), isc::BadValue);
 }
 
 }