Browse Source

[2835] The DataSourceStatus class

Just a thin state holder class
Michal 'vorner' Vaner 12 years ago
parent
commit
2e6d5f8d60
2 changed files with 58 additions and 0 deletions
  1. 49 0
      src/lib/datasrc/client_list.h
  2. 9 0
      src/lib/datasrc/tests/client_list_unittest.cc

+ 49 - 0
src/lib/datasrc/client_list.h

@@ -46,6 +46,55 @@ class InMemoryClient;
 class ZoneWriter;
 }
 
+/// \brief Segment status of the cache
+///
+/// Describes the status in which the memory segment of given data source
+/// is.
+enum MemorySegmentState {
+    /// \brief The segment is local one.
+    MSS_LOCAL,
+    /// \brief No segment used for this data source.
+    MSS_UNUSED,
+    /// \brief It is a mapped segment and we wait for information how to map
+    ///     it.
+    MSS_WAITING,
+    /// \brief A mapped segment and in active use.
+    MSS_MAPPED
+};
+
+/// \brief Status of one data source.
+///
+/// This indicates the status a data soure is in. It is used with segment
+/// and cache management, to discover the data sources than need external
+/// mapping or local loading.
+class DataSourceStatus {
+public:
+    /// \brief Constructor
+    ///
+    /// Sets initial values.
+    DataSourceStatus(const std::string& name, MemorySegmentState state) :
+        name_(name),
+        state_(state)
+    {}
+    /// \brief Change the current segment state
+    void setSegmentState(MemorySegmentState state) {
+        state_ = state;
+    }
+    /// \brief Get the current segment state
+    MemorySegmentState getSegmentState() const {
+        return (state_);
+    }
+    /// \brief Get the current name.
+    ///
+    /// \note The name may not be changed once the object is constructed.
+    const std::string& getName() const {
+        return (name_);
+    }
+private:
+    std::string name_;
+    MemorySegmentState state_;
+};
+
 /// \brief The list of data source clients.
 ///
 /// The purpose of this class is to hold several data source clients and search

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

@@ -1136,4 +1136,13 @@ TYPED_TEST(ReloadTest, reloadMasterFile) {
                                                          RRType::TXT())->code);
 }
 
+// Check the status holds data and can change the segment state
+TEST(DataSourceStatus, status) {
+    DataSourceStatus status("Test", MSS_UNUSED);
+    EXPECT_EQ("Test", status.getName());
+    EXPECT_EQ(MSS_UNUSED, status.getSegmentState());
+    status.setSegmentState(MSS_LOCAL);
+    EXPECT_EQ(MSS_LOCAL, status.getSegmentState());
+}
+
 }