From: Michal 'vorner' Vaner Date: Fri, 15 Mar 2013 10:20:02 +0000 (+0100) Subject: [2835] The DataSourceStatus class X-Git-Tag: bind10-1.1.0beta1-release~23^2~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2e6d5f8d602a632d8a770c13d7ccbc09a25825ad;p=thirdparty%2Fkea.git [2835] The DataSourceStatus class Just a thin state holder class --- diff --git a/src/lib/datasrc/client_list.h b/src/lib/datasrc/client_list.h index e97ee46948..28c0e2054f 100644 --- a/src/lib/datasrc/client_list.h +++ b/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 diff --git a/src/lib/datasrc/tests/client_list_unittest.cc b/src/lib/datasrc/tests/client_list_unittest.cc index fe42ebfdc3..445bc22cf5 100644 --- a/src/lib/datasrc/tests/client_list_unittest.cc +++ b/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()); +} + }