Browse Source

[1522] more cleanup: changed some static member functions to non members
as they don't have to get access to class internal.

JINMEI Tatuya 13 years ago
parent
commit
f02087d579

+ 7 - 8
src/lib/server_common/socket_request.cc

@@ -335,13 +335,7 @@ socketRequestor() {
 }
 
 void
-SocketRequestor::initTest(SocketRequestor* new_requestor) {
-    requestor = new_requestor;
-}
-
-
-void
-SocketRequestor::init(config::ModuleCCSession& session) {
+initSocketReqeustor(config::ModuleCCSession& session) {
     if (requestor != NULL) {
         isc_throw(InvalidOperation,
                   "The socket requestor was already initialized");
@@ -351,7 +345,12 @@ SocketRequestor::init(config::ModuleCCSession& session) {
 }
 
 void
-SocketRequestor::cleanup() {
+initTestSocketRequestor(SocketRequestor* new_requestor) {
+    requestor = new_requestor;
+}
+
+void
+cleanupSocketRequestor() {
     if (requestor != NULL) {
         delete requestor;
         requestor = NULL;

+ 39 - 40
src/lib/server_common/socket_request.h

@@ -145,43 +145,6 @@ public:
     ///     release (like we're trying to release a socket that doesn't
     ///     belong to us or exist at all).
     virtual void releaseSocket(const std::string& token) = 0;
-
-    /// \brief Initialize the singleton object
-    ///
-    /// This creates the object that will be used to request sockets.
-    /// It can be called only once per the life of application.
-    ///
-    /// \param session the CC session that'll be used to talk to the
-    ///                socket creator.
-    /// \throw InvalidOperation when it is called more than once
-    static void init(config::ModuleCCSession& session);
-
-    /// \brief Initialization for tests
-    ///
-    /// This is to support different subclasses in tests. It replaces
-    /// the object used by socketRequestor() function by this one provided
-    /// as parameter. The ownership is not taken, eg. it's up to the caller
-    /// to delete it when necessary.
-    ///
-    /// This is not to be used in production applications. It is meant as
-    /// an replacement of init.
-    ///
-    /// This never throws.
-    ///
-    /// \param requestor the object to be used. It can be NULL to reset to
-    ///     an "virgin" state (which acts as if initTest or init was never
-    ///     called before).
-    static void initTest(SocketRequestor* requestor);
-
-    /// \brief Destroy the singleton instance
-    ///
-    /// Calling this function is not strictly necessary; the socket
-    /// requestor is a singleton anyway. However, for some tests it
-    /// is useful to destroy and recreate it, as well as for programs
-    /// that want to be completely clean on exit.
-    /// After this method has been called, all operations except init
-    /// will fail.
-    static void cleanup();
 };
 
 /// \brief Access the requestor object.
@@ -191,10 +154,46 @@ public:
 /// \return the active socket requestor object.
 /// \throw InvalidOperation if the object was not yet initialized.
 /// \see SocketRequestor::init to initialize the object.
-SocketRequestor&
-socketRequestor();
+SocketRequestor& socketRequestor();
+
+/// \brief Initialize the singleton object
+///
+/// This creates the object that will be used to request sockets.
+/// It can be called only once per the life of application.
+///
+/// \param session the CC session that'll be used to talk to the
+///                socket creator.
+/// \throw InvalidOperation when it is called more than once
+void initSocketReqeustor(config::ModuleCCSession& session);
+
+/// \brief Initialization for tests
+///
+/// This is to support different subclasses in tests. It replaces
+/// the object used by socketRequestor() function by this one provided
+/// as parameter. The ownership is not taken, eg. it's up to the caller
+/// to delete it when necessary.
+///
+/// This is not to be used in production applications. It is meant as
+/// an replacement of init.
+///
+/// This never throws.
+///
+/// \param requestor the object to be used. It can be NULL to reset to
+///     an "virgin" state (which acts as if initTest or init was never
+///     called before).
+void initTestSocketRequestor(SocketRequestor* requestor);
+
+/// \brief Destroy the singleton instance
+///
+/// Calling this function is not strictly necessary; the socket
+/// requestor is a singleton anyway. However, for some tests it
+/// is useful to destroy and recreate it, as well as for programs
+/// that want to be completely clean on exit.
+/// After this function has been called, all operations except init
+/// will fail.
+void cleanupSocketRequestor();
 
 }
 }
 
-#endif
+#endif  // __SOCKET_REQUEST_H

+ 8 - 7
src/lib/server_common/tests/socket_requestor_test.cc

@@ -43,7 +43,7 @@ namespace {
 // Check it throws an exception when it is not initialized
 TEST(SocketRequestorAccess, unitialized) {
     // Make sure it is not initialized
-    SocketRequestor::initTest(NULL);
+    initTestSocketRequestor(NULL);
     EXPECT_THROW(socketRequestor(), InvalidOperation);
 }
 
@@ -62,7 +62,7 @@ TEST(SocketRequestorAccess, initialized) {
     };
     DummyRequestor requestor;
     // Make sure it is initialized (the test way, of course)
-    SocketRequestor::initTest(&requestor);
+    initTestSocketRequestor(&requestor);
     // It returs the same "pointer" as inserted
     // The casts are there as the template system seemed to get confused
     // without them, the types should be correct even without them, but
@@ -70,7 +70,7 @@ TEST(SocketRequestorAccess, initialized) {
     EXPECT_EQ(static_cast<const SocketRequestor*>(&requestor),
               static_cast<const SocketRequestor*>(&socketRequestor()));
     // Just that we don't have an invalid pointer anyway
-    SocketRequestor::initTest(NULL);
+    initTestSocketRequestor(NULL);
 }
 
 // This class contains a fake (module)ccsession to emulate answers from Boss
@@ -79,16 +79,17 @@ public:
     SocketRequestorTest() : session(ElementPtr(new ListElement),
                                     ElementPtr(new ListElement),
                                     ElementPtr(new ListElement)),
-                            specfile(std::string(TEST_DATA_PATH) + "/spec.spec")
+                            specfile(std::string(TEST_DATA_PATH) +
+                                     "/spec.spec")
     {
         session.getMessages()->add(createAnswer());
         cc_session.reset(new ModuleCCSession(specfile, session, NULL, NULL,
                                              false, false));
-        SocketRequestor::init(*cc_session);
-    };
+        initSocketReqeustor(*cc_session);
+    }
 
     ~SocketRequestorTest() {
-        SocketRequestor::cleanup();
+        cleanupSocketRequestor();
     }
 
     // Do a standard request with some default values