From: Francis Dupont Date: Wed, 11 Jan 2017 15:16:50 +0000 (+0100) Subject: [5095] Moved the shared callout manager to HooksManager singleton instance X-Git-Tag: trac3590_base~15^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5124d5fcc4b5049a91a9a47f6aba3a207758ff4e;p=thirdparty%2Fkea.git [5095] Moved the shared callout manager to HooksManager singleton instance --- diff --git a/src/bin/dhcp4/tests/hooks_unittest.cc b/src/bin/dhcp4/tests/hooks_unittest.cc index c9cef864cd..d87bbf0f52 100644 --- a/src/bin/dhcp4/tests/hooks_unittest.cc +++ b/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( diff --git a/src/bin/dhcp6/tests/hooks_unittest.cc b/src/bin/dhcp6/tests/hooks_unittest.cc index 82f928e2f6..8a550c8de1 100644 --- a/src/bin/dhcp6/tests/hooks_unittest.cc +++ b/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( diff --git a/src/lib/hooks/callout_manager.cc b/src/lib/hooks/callout_manager.cc index 2ab33d7c23..d41f7df443 100644 --- a/src/lib/hooks/callout_manager.cc +++ b/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::shared_manager_; - // Constructor CalloutManager::CalloutManager(int num_libraries) : server_hooks_(ServerHooks::getServerHooks()), diff --git a/src/lib/hooks/callout_manager.h b/src/lib/hooks/callout_manager.h index d58855580e..843e1b9cc8 100644 --- a/src/lib/hooks/callout_manager.h +++ b/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& 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 shared_manager_; }; } // namespace util diff --git a/src/lib/hooks/hooks_manager.cc b/src/lib/hooks/hooks_manager.cc index 90d7dc1434..14c750103a 100644 --- a/src/lib/hooks/hooks_manager.cc +++ b/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& libraries) { return (LibraryManagerCollection::validateLibraries(libraries)); } +// Shared callout manager +boost::shared_ptr& +HooksManager::getSharedCalloutManager() { + return (getHooksManager().shared_callout_manager_); +} + } // namespace util } // namespace isc diff --git a/src/lib/hooks/hooks_manager.h b/src/lib/hooks/hooks_manager.h index b6080be8eb..bda0563b12 100644 --- a/src/lib/hooks/hooks_manager.h +++ b/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& getSharedCalloutManager(); + private: /// @brief Constructor @@ -312,6 +320,10 @@ private: /// Callout manager for the set of library managers. boost::shared_ptr callout_manager_; + + /// Shared callout manager to survive library reloads. + boost::shared_ptr shared_callout_manager_; + }; } // namespace util diff --git a/src/lib/hooks/library_manager_collection.cc b/src/lib/hooks/library_manager_collection.cc index ea195ce57c..0eb3f8ab1f 100644 --- a/src/lib/hooks/library_manager_collection.cc +++ b/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 +#include #include #include @@ -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())); diff --git a/src/lib/hooks/tests/hooks_manager_unittest.cc b/src/lib/hooks/tests/hooks_manager_unittest.cc index 54aaf86cca..e8397a4362 100644 --- a/src/lib/hooks/tests/hooks_manager_unittest.cc +++ b/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",