Browse Source

[5095] Moved the shared callout manager to HooksManager singleton instance

Francis Dupont 8 years ago
parent
commit
5124d5fcc4

+ 4 - 4
src/bin/dhcp4/tests/hooks_unittest.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -112,7 +112,7 @@ public:
         HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts("lease4_release");
         HooksManager::preCalloutsLibraryHandle().deregisterAllCallouts("lease4_decline");
 
-        CalloutManager::getSharedManager().reset();
+        HooksManager::getSharedCalloutManager().reset();
         delete srv_;
     }
 
@@ -1610,7 +1610,7 @@ TEST_F(HooksDhcpv4SrvTest, HooksDecline) {
     IfaceMgr::instance().openSockets4();
 
     // Libraries will be reloaded later
-    CalloutManager::getSharedManager().reset(new CalloutManager(0));
+    HooksManager::getSharedCalloutManager().reset(new CalloutManager(0));
 
     // Install a callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -1659,7 +1659,7 @@ TEST_F(HooksDhcpv4SrvTest, HooksDeclineDrop) {
     IfaceMgr::instance().openSockets4();
 
     // Libraries will be reloaded later
-    CalloutManager::getSharedManager().reset(new CalloutManager(0));
+    HooksManager::getSharedCalloutManager().reset(new CalloutManager(0));
 
     // Install a callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(

+ 7 - 7
src/bin/dhcp6/tests/hooks_unittest.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -115,15 +115,15 @@ public:
         // Clear static buffers
         resetCalloutBuffers();
 
-	// Reset the hook system in its original state
-	HooksManager::unloadLibraries();
+        // Reset the hook system in its original state
+        HooksManager::unloadLibraries();
     }
 
     /// @brief destructor (deletes Dhcpv6Srv)
     ~HooksDhcpv6SrvTest() {
 
         // Clear shared manager
-        CalloutManager::getSharedManager().reset();
+        HooksManager::getSharedCalloutManager().reset();
 
     }
 
@@ -2091,7 +2091,7 @@ TEST_F(HooksDhcpv6SrvTest, basicLease6Decline) {
     IfaceMgrTestConfig test_config(true);
 
     // Libraries will be reloaded later
-    CalloutManager::getSharedManager().reset(new CalloutManager(0));
+    HooksManager::getSharedCalloutManager().reset(new CalloutManager(0));
 
     // Install lease6_decline callout
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2141,7 +2141,7 @@ TEST_F(HooksDhcpv6SrvTest, lease6DeclineSkip) {
     IfaceMgrTestConfig test_config(true);
 
     // Libraries will be reloaded later
-    CalloutManager::getSharedManager().reset(new CalloutManager(0));
+    HooksManager::getSharedCalloutManager().reset(new CalloutManager(0));
 
     // Install lease6_decline callout. It will set the status to skip
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
@@ -2188,7 +2188,7 @@ TEST_F(HooksDhcpv6SrvTest, lease6DeclineDrop) {
     IfaceMgrTestConfig test_config(true);
 
     // Libraries will be reloaded later
-    CalloutManager::getSharedManager().reset(new CalloutManager(0));
+    HooksManager::getSharedCalloutManager().reset(new CalloutManager(0));
 
     // Install lease6_decline callout. It will set the status to skip
     EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(

+ 1 - 3
src/lib/hooks/callout_manager.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -24,8 +24,6 @@ using namespace std;
 namespace isc {
 namespace hooks {
 
-boost::shared_ptr<CalloutManager> CalloutManager::shared_manager_;
-
 // Constructor
 CalloutManager::CalloutManager(int num_libraries)
     : server_hooks_(ServerHooks::getServerHooks()),

+ 1 - 11
src/lib/hooks/callout_manager.h

@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -298,13 +298,6 @@ public:
 
     //@}
 
-    /// @brief Return the shared manager
-    ///
-    /// @return A reference to the shared manager
-    static boost::shared_ptr<CalloutManager>& getSharedManager() {
-        return (shared_manager_);
-    }
-
 private:
     /// @brief Check library index
     ///
@@ -375,9 +368,6 @@ private:
 
     /// Number of libraries.
     int num_libraries_;
-
-    /// Shared manager to survive library reloads
-    static boost::shared_ptr<CalloutManager> shared_manager_;
 };
 
 } // namespace util

+ 7 - 1
src/lib/hooks/hooks_manager.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -199,5 +199,11 @@ HooksManager::validateLibraries(const std::vector<std::string>& libraries) {
     return (LibraryManagerCollection::validateLibraries(libraries));
 }
 
+// Shared callout manager
+boost::shared_ptr<CalloutManager>&
+HooksManager::getSharedCalloutManager() {
+    return (getHooksManager().shared_callout_manager_);
+}
+
 } // namespace util
 } // namespace isc

+ 13 - 1
src/lib/hooks/hooks_manager.h

@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -199,6 +199,14 @@ public:
     static const int CONTEXT_CREATE = ServerHooks::CONTEXT_CREATE;
     static const int CONTEXT_DESTROY = ServerHooks::CONTEXT_DESTROY;
 
+    /// @brief Return the shared callout manager
+    ///
+    /// Declared as static as other methods but only one for the
+    /// singleton will be created.
+    ///
+    /// @return A reference to the shared callout manager
+    static boost::shared_ptr<CalloutManager>& getSharedCalloutManager();
+
 private:
 
     /// @brief Constructor
@@ -312,6 +320,10 @@ private:
 
     /// Callout manager for the set of library managers.
     boost::shared_ptr<CalloutManager> callout_manager_;
+
+    /// Shared callout manager to survive library reloads.
+    boost::shared_ptr<CalloutManager> shared_callout_manager_;
+
 };
 
 } // namespace util

+ 3 - 2
src/lib/hooks/library_manager_collection.cc

@@ -1,10 +1,11 @@
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 #include <hooks/callout_manager.h>
+#include <hooks/hooks_manager.h>
 #include <hooks/library_manager.h>
 #include <hooks/library_manager_collection.h>
 
@@ -66,7 +67,7 @@ LibraryManagerCollection::loadLibraries() {
     // To survive reloads an attempt to re-use the shared manager
     // is performed when the list of library names is empty.
     if (library_names_.empty()) {
-        callout_manager_ = CalloutManager::getSharedManager();
+        callout_manager_ = HooksManager::getSharedCalloutManager();
     }
     if (!library_names_.empty() || !callout_manager_) {
         callout_manager_.reset(new CalloutManager(library_names_.size()));

+ 5 - 5
src/lib/hooks/tests/hooks_manager_unittest.cc

@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -43,7 +43,7 @@ public:
     /// Unload all libraries and reset the shared manager.
     ~HooksManagerTest() {
         HooksManager::unloadLibraries();
-        CalloutManager::getSharedManager().reset();
+        HooksManager::getSharedCalloutManager().reset();
     }
 
 
@@ -400,7 +400,7 @@ TEST_F(HooksManagerTest, PrePostCalloutShared) {
     HookLibsCollection library_names;
 
     // Initialize the shared manager.
-    CalloutManager::getSharedManager().reset(new CalloutManager(0));
+    HooksManager::getSharedCalloutManager().reset(new CalloutManager(0));
 
     // Load the pre- and post- callouts.
     HooksManager::preCalloutsLibraryHandle().registerCallout("hookpt_two",
@@ -447,7 +447,7 @@ TEST_F(HooksManagerTest, PrePostCalloutSharedNotEmpty) {
                                       data::ConstElementPtr()));
 
     // Initialize the shared manager.
-    CalloutManager::getSharedManager().reset(new CalloutManager(0));
+    HooksManager::getSharedCalloutManager().reset(new CalloutManager(0));
 
     // Load the pre- and post- callouts.
     HooksManager::preCalloutsLibraryHandle().registerCallout("hookpt_two",
@@ -493,7 +493,7 @@ TEST_F(HooksManagerTest, PrePostCalloutSharedTooLate) {
     EXPECT_TRUE(HooksManager::loadLibraries(library_names));
 
     // Initialize the shared manager (after loadLibraries so too late)
-    CalloutManager::getSharedManager().reset(new CalloutManager(0));
+    HooksManager::getSharedCalloutManager().reset(new CalloutManager(0));
 
     // Load the pre- and post- callouts.
     HooksManager::preCalloutsLibraryHandle().registerCallout("hookpt_two",