Browse Source

[2835] Use string for segment type

Instead of hard-coded enum type. The data source should be agnostic to
the type.
Michal 'vorner' Vaner 12 years ago
parent
commit
946126b36d

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

@@ -483,7 +483,7 @@ ConfigurableClientList::getStatus() const {
         // SEGMENT_WAITING.
         result.push_back(DataSourceStatus(info.name_, info.cache_ ?
                                           SEGMENT_INUSE : SEGMENT_UNUSED,
-                                          SEGMENT_LOCAL));
+                                          "local"));
     }
     return (result);
 }

+ 5 - 14
src/lib/datasrc/client_list.h

@@ -64,15 +64,6 @@ enum MemorySegmentState {
     SEGMENT_INUSE
 };
 
-/// \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
@@ -88,10 +79,10 @@ public:
     /// 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) :
+                     const std::string& type) :
         name_(name),
-        state_(state),
-        type_(type)
+        type_(type),
+        state_(state)
     {}
 
     /// \brief Get the segment state
@@ -102,7 +93,7 @@ public:
     /// \brief Get the segment type
     ///
     /// \throw isc::InvalidOperation if called and state is SEGMENT_UNUSED.
-    MemorySegmentType getSegmentType() const {
+    const std::string& getSegmentType() const {
         if (getSegmentState() == SEGMENT_UNUSED) {
             isc_throw(isc::InvalidOperation,
                       "No segment used, no type therefore.");
@@ -116,8 +107,8 @@ public:
     }
 private:
     std::string name_;
+    std::string type_;
     MemorySegmentState state_;
-    MemorySegmentType type_;
 };
 
 /// \brief The list of data source clients.

+ 5 - 5
src/lib/datasrc/tests/client_list_unittest.cc

@@ -579,7 +579,7 @@ TEST_F(ListTest, status) {
     EXPECT_THROW(statuses[0].getSegmentType(), isc::InvalidOperation);
     EXPECT_EQ("Test name", statuses[1].getName());
     EXPECT_EQ(SEGMENT_INUSE, statuses[1].getSegmentState());
-    EXPECT_EQ(SEGMENT_LOCAL, statuses[1].getSegmentType());
+    EXPECT_EQ("local", statuses[1].getSegmentType());
 }
 
 TEST_F(ListTest, wrongConfig) {
@@ -1163,14 +1163,14 @@ TYPED_TEST(ReloadTest, reloadMasterFile) {
                                                          RRType::TXT())->code);
 }
 
-// Check the status holds data and the data can be extracted
+// Check the status holds data and can change the segment state
 TEST(DataSourceStatus, status) {
-    const DataSourceStatus status("Test", SEGMENT_INUSE, SEGMENT_LOCAL);
+    const DataSourceStatus status("Test", SEGMENT_INUSE, "local");
     EXPECT_EQ("Test", status.getName());
     EXPECT_EQ(SEGMENT_INUSE, status.getSegmentState());
-    EXPECT_EQ(SEGMENT_LOCAL, status.getSegmentType());
+    EXPECT_EQ("local", status.getSegmentType());
     const DataSourceStatus statusUnused("Unused", SEGMENT_UNUSED,
-                                        SEGMENT_FILE);
+                                        "");
     EXPECT_EQ("Unused", statusUnused.getName());
     EXPECT_EQ(SEGMENT_UNUSED, statusUnused.getSegmentState());
     EXPECT_THROW(statusUnused.getSegmentType(), isc::InvalidOperation);