Browse Source

[2205] cleanups: use more specific internal namespaces and reorder code

mainly for better readability.  no functional change.
JINMEI Tatuya 12 years ago
parent
commit
e21b1a26b3

+ 53 - 50
src/bin/auth/datasrc_clients_mgr.h

@@ -33,51 +33,13 @@
 namespace isc {
 namespace auth {
 
-namespace internal {
+namespace datasrc_clientmgr_internal {
 enum CommandID {
     NOOP,                       ///< Do nothing.  Only useful for tests
     SHUTDOWN                    ///< Shutdown the builder.
 };
 typedef std::pair<CommandID, data::ConstElementPtr> Command;
-
-template <typename MutexType, typename CondVarType>
-class DataSrcClientsBuilderBase {
-public:
-    DataSrcClientsBuilderBase(std::list<Command>* command_queue,
-                              CondVarType* cond, MutexType* queue_mutex) :
-        command_queue_(command_queue), cond_(cond), queue_mutex_(queue_mutex)
-    {}
-
-    /// Not sure if we need this.  It depends on test details.
-    /// \brief Destructor.
-    ///
-    /// This does nothing, but explicitly defined to silence 'unused variable'
-    /// warnings from some versions of clang++.
-    ///~DataSrcClientsBuilderBase() {}
-
-    void run();
-
-    /// separated from run() and made public for the purpose of tests.
-    ///
-    /// \return true if it the builder should keep running; false otherwise.
-    bool handleCommand(const Command& command);
-
-private:
-    // NOOP command handler.  We use this so tests can override it.
-    void doNoop() {}
-
-    // end-in, front-out queue
-    std::list<Command>* command_queue_;
-    CondVarType* cond_;
-    MutexType* queue_mutex_;
-    //boost::shared_ptr<DataSrcClientListMap>* map;
-    //MutexType* data_mutex_;
-};
-
-// Shortcut typedef for normal use
-typedef DataSrcClientsBuilderBase<util::thread::Mutex, util::thread::CondVar>
-DataSrcClientsBuilder;
-}
+} // namespace datasrc_clientmgr_internal
 
 template <typename ThreadType, typename BuilderType, typename MutexType,
           typename CondVarType>
@@ -98,7 +60,8 @@ public:
         // is Thread::UncaughtException when the builder thread died due to
         // an exception.  We specifically log it and just ignore others.
         try {
-            sendCommand(internal::SHUTDOWN, data::ConstElementPtr());
+            sendCommand(datasrc_clientmgr_internal::SHUTDOWN,
+                        data::ConstElementPtr());
             builder_thread_.wait();
         } catch (const util::thread::Thread::UncaughtException& ex) {
             LOG_ERROR(auth_logger, AUTH_DATASRC_CLIENTS_SHUTDOWN_ERROR).
@@ -107,22 +70,62 @@ public:
     }
 
 private:
-    void sendCommand(internal::CommandID command, data::ConstElementPtr arg) {
+    void sendCommand(datasrc_clientmgr_internal::CommandID command,
+                     data::ConstElementPtr arg) {
         {
             typename MutexType::Locker locker(queue_mutex_);
-            command_queue_.push_back(internal::Command(command, arg));
+            command_queue_.push_back(
+                datasrc_clientmgr_internal::Command(command, arg));
         }
         cond_.signal();
     }
 
-    std::list<internal::Command> command_queue_;
+    std::list<datasrc_clientmgr_internal::Command> command_queue_;
     CondVarType cond_;
     MutexType queue_mutex_;
     BuilderType builder_;
     ThreadType builder_thread_;
 };
 
-namespace internal {
+namespace datasrc_clientmgr_internal {
+template <typename MutexType, typename CondVarType>
+class DataSrcClientsBuilderBase {
+public:
+    DataSrcClientsBuilderBase(std::list<Command>* command_queue,
+                              CondVarType* cond, MutexType* queue_mutex) :
+        command_queue_(command_queue), cond_(cond), queue_mutex_(queue_mutex)
+    {}
+
+    /// Not sure if we need this.  It depends on test details.
+    /// \brief Destructor.
+    ///
+    /// This does nothing, but explicitly defined to silence 'unused variable'
+    /// warnings from some versions of clang++.
+    ///~DataSrcClientsBuilderBase() {}
+
+    void run();
+
+    /// separated from run() and made public for the purpose of tests.
+    ///
+    /// \return true if it the builder should keep running; false otherwise.
+    bool handleCommand(const Command& command);
+
+private:
+    // NOOP command handler.  We use this so tests can override it.
+    void doNoop() {}
+
+    // end-in, front-out queue
+    std::list<Command>* command_queue_;
+    CondVarType* cond_;
+    MutexType* queue_mutex_;
+    //boost::shared_ptr<DataSrcClientListMap>* map;
+    //MutexType* data_mutex_;
+};
+
+// Shortcut typedef for normal use
+typedef DataSrcClientsBuilderBase<util::thread::Mutex, util::thread::CondVar>
+DataSrcClientsBuilder;
+
 template <typename MutexType, typename CondVarType>
 void
 DataSrcClientsBuilderBase<MutexType, CondVarType>::run() {
@@ -177,16 +180,16 @@ DataSrcClientsBuilderBase<MutexType, CondVarType>::handleCommand(
     }
     return (true);
 }
-} // namespace internal
+} // namespace datasrc_clientmgr_internal
 
 /// \brief Shortcut type for normal data source clients manager.
 ///
 /// In fact, for non test applications this is the only type of this kind
 /// to be considered.
-typedef DataSrcClientsMgrBase<util::thread::Thread,
-                              internal::DataSrcClientsBuilder,
-                              util::thread::Mutex, util::thread::CondVar>
-DataSrcClientsMgr;
+typedef DataSrcClientsMgrBase<
+    util::thread::Thread,
+    datasrc_clientmgr_internal::DataSrcClientsBuilder,
+    util::thread::Mutex, util::thread::CondVar> DataSrcClientsMgr;
 } // namespace auth
 } // namespace isc
 

+ 1 - 1
src/bin/auth/tests/datasrc_clients_builder_unittest.cc

@@ -22,7 +22,7 @@
 #include <boost/function.hpp>
 
 using isc::data::ConstElementPtr;
-using namespace isc::auth::internal;
+using namespace isc::auth::datasrc_clientmgr_internal;
 
 namespace {
 class DataSrcClientsBuilderTest : public ::testing::Test {

+ 1 - 1
src/bin/auth/tests/datasrc_clients_mgr_unittest.cc

@@ -22,7 +22,7 @@
 #include <boost/function.hpp>
 
 using namespace isc::auth;
-using namespace isc::auth::internal;
+using namespace isc::auth::datasrc_clientmgr_internal;
 
 namespace {
 void

+ 5 - 4
src/bin/auth/tests/test_datasrc_clients_mgr.cc

@@ -18,17 +18,18 @@
 
 namespace isc {
 namespace auth {
+namespace datasrc_clientmgr_internal {
+
 // Define static DataSrcClientsBuilder member variables.
 bool FakeDataSrcClientsBuilder::started = false;
-std::list<internal::Command>* FakeDataSrcClientsBuilder::command_queue = NULL;
-internal::TestCondVar* FakeDataSrcClientsBuilder::cond = NULL;
-internal::TestMutex* FakeDataSrcClientsBuilder::queue_mutex = NULL;
+std::list<Command>* FakeDataSrcClientsBuilder::command_queue = NULL;
+TestCondVar* FakeDataSrcClientsBuilder::cond = NULL;
+TestMutex* FakeDataSrcClientsBuilder::queue_mutex = NULL;
 bool FakeDataSrcClientsBuilder::thread_waited = false;
 FakeDataSrcClientsBuilder::ExceptionFromWait
 FakeDataSrcClientsBuilder::thread_throw_on_wait =
     FakeDataSrcClientsBuilder::NOTHROW;
 
-namespace internal {
 template<>
 void
 TestDataSrcClientsBuilder::doNoop() {

+ 16 - 14
src/bin/auth/tests/test_datasrc_clients_mgr.h

@@ -23,11 +23,11 @@
 
 #include <list>
 
-// Below we extend the isc::auth::internal namespace to specialize
-// the doNoop() method.
+// Below we extend the isc::auth::datasrc_clientmgr_internal namespace to
+// specialize the doNoop() method.
 namespace isc {
 namespace auth {
-namespace internal {
+namespace datasrc_clientmgr_internal {
 class TestMutex {
 public:
     // for throw_from_noop.
@@ -106,8 +106,6 @@ template<>
 void
 TestDataSrcClientsBuilder::doNoop();
 
-} // namespace internal
-
 // A specialization of DataSrcClientsBuilder that allows tests to inspect
 // its internal states via static class variables.  Using static is suboptimal,
 // but DataSrcClientsMgr is highly encapsulated, this seems to be the best
@@ -118,9 +116,9 @@ public:
     static bool started;
 
     // These three correspond to the resource shared with the manager.
-    static std::list<internal::Command>* command_queue;
-    static internal::TestCondVar* cond;
-    static internal::TestMutex* queue_mutex;
+    static std::list<Command>* command_queue;
+    static TestCondVar* cond;
+    static TestMutex* queue_mutex;
 
     // true iff the manager waited on the thread running the builder.
     static bool thread_waited;
@@ -130,9 +128,10 @@ public:
     enum ExceptionFromWait { NOTHROW, THROW_UNCAUGHT_EX, THROW_OTHER };
     static ExceptionFromWait thread_throw_on_wait;
 
-    FakeDataSrcClientsBuilder(std::list<internal::Command>* command_queue,
-                              internal::TestCondVar* cond,
-                              internal::TestMutex* queue_mutex)
+    FakeDataSrcClientsBuilder(
+        std::list<Command>* command_queue,
+        TestCondVar* cond,
+        TestMutex* queue_mutex)
     {
         FakeDataSrcClientsBuilder::started = false;
         FakeDataSrcClientsBuilder::command_queue = command_queue;
@@ -163,11 +162,14 @@ public:
         }
     }
 };
+} // namespace datasrc_clientmgr_internal
 
 // Convenient shortcut
-typedef DataSrcClientsMgrBase<TestThread, FakeDataSrcClientsBuilder,
-                              internal::TestMutex, internal::TestCondVar>
-TestDataSrcClientsMgr;
+typedef DataSrcClientsMgrBase<
+    datasrc_clientmgr_internal::TestThread,
+    datasrc_clientmgr_internal::FakeDataSrcClientsBuilder,
+    datasrc_clientmgr_internal::TestMutex,
+    datasrc_clientmgr_internal::TestCondVar> TestDataSrcClientsMgr;
 
 } // namespace auth
 } // namespace isc