Commit 69ed5766 authored by Francis Dupont's avatar Francis Dupont

[#1282] Addressed comments

parent 973a7aff
// Copyright (C) 2017-2019 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2017-2020 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
......@@ -9,6 +9,7 @@
#include <agent/simple_parser.h>
#include <cc/data.h>
#include <cc/dhcp_config_error.h>
#include <hooks/hooks_manager.h>
#include <hooks/hooks_parser.h>
#include <boost/foreach.hpp>
......@@ -118,9 +119,11 @@ AgentSimpleParser::parse(const CtrlAgentCfgContextPtr& ctx,
// This occurs last as if it succeeds, there is no easy way
// revert it. As a result, the failure to commit a subsequent
// change causes problems when trying to roll back.
HooksManager::prepareUnloadLibraries();
static_cast<void>(HooksManager::unloadLibraries());
libraries.loadLibraries();
}
}
};
};
}
}
// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2018-2020 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
......@@ -10,6 +10,7 @@
#include <netconf/netconf_config.h>
#include <cc/data.h>
#include <cc/dhcp_config_error.h>
#include <hooks/hooks_manager.h>
#include <hooks/hooks_parser.h>
#include <boost/foreach.hpp>
......@@ -183,9 +184,11 @@ NetconfSimpleParser::parse(const NetconfConfigPtr& ctx,
// This occurs last as if it succeeds, there is no easy way
// revert it. As a result, the failure to commit a subsequent
// change causes problems when trying to roll back.
HooksManager::prepareUnloadLibraries();
static_cast<void>(HooksManager::unloadLibraries());
libraries.loadLibraries();
}
}
};
};
}
}
......@@ -206,19 +206,17 @@ CloseHATest::runPartners() {
wthread_->markReady(WatchedThread::READY);
// In fact below only the terminate matters as in fact
// accepts have not the time to be called.
for (;;) {
int nfd;
fd_set fds;
FD_ZERO(&fds);
FD_SET(wthread_->getWatchFd(WatchedThread::TERMINATE), &fds);
nfd = wthread_->getWatchFd(WatchedThread::TERMINATE);
// FD_SET(accept_partner1, &fds);
FD_SET(accept_partner1, &fds);
if (accept_partner1 > nfd) {
nfd = accept_partner1;
}
// FD_SET(accept_partner2, &fds);
FD_SET(accept_partner2, &fds);
if (accept_partner2 > nfd) {
nfd = accept_partner2;
}
......@@ -502,7 +500,6 @@ TEST_F(CloseHATest, close6) {
// Use the query callout handle.
CalloutHandlePtr handle = query->getCalloutHandle();
ScopedCalloutHandleState handle_state(handle);
handle->setStatus(CalloutHandle::NEXT_STEP_SKIP);
handle->setArgument("query6", query);
HooksManager::callCallouts(testHooks.hook_index_buffer6_receive_,
*handle);
......
......@@ -28,7 +28,12 @@ namespace hooks {
// Constructor
HooksManager::HooksManager() : test_mode_(false) {
init();
// Nothing present, so create the collection with any empty set of
// libraries, and get the CalloutManager.
HookLibsCollection libraries;
lm_collection_.reset(new LibraryManagerCollection(libraries));
lm_collection_->loadLibraries();
callout_manager_ = lm_collection_->getCalloutManager();
}
// Return reference to singleton hooks manager.
......@@ -118,7 +123,7 @@ HooksManager::loadLibrariesInternal(const HookLibsCollection& libraries) {
} else {
// Unable to load libraries, reset to state before this function was
// called.
init();
static_cast<void>(unloadLibrariesInternal());
}
return (status);
......@@ -166,7 +171,8 @@ HooksManager::unloadLibrariesInternal() {
return (true);
}
bool HooksManager::unloadLibraries() {
bool
HooksManager::unloadLibraries() {
return (getHooksManager().unloadLibrariesInternal());
}
......@@ -179,7 +185,8 @@ HooksManager::prepareUnloadLibrariesInternal() {
static_cast<void>(lm_collection_->prepareUnloadLibraries());
}
void HooksManager::prepareUnloadLibraries() {
void
HooksManager::prepareUnloadLibraries() {
getHooksManager().prepareUnloadLibrariesInternal();
}
......@@ -217,18 +224,6 @@ HooksManager::getLibraryInfo() {
return (getHooksManager().getLibraryInfoInternal());
}
// Perform initialization
void
HooksManager::init() {
// Nothing present, so create the collection with any empty set of
// libraries, and get the CalloutManager.
HookLibsCollection libraries;
lm_collection_.reset(new LibraryManagerCollection(libraries));
lm_collection_->loadLibraries();
callout_manager_ = lm_collection_->getCalloutManager();
}
// Shell around ServerHooks::registerHook()
int
......
......@@ -474,23 +474,16 @@ private:
//@}
/// @brief Initialization to No Libraries
///
/// Initializes the hooks manager with an empty set of libraries.
void init();
// Members
/// Set of library managers.
///
/// @node: This should always be initialized using @ref init or
/// @ref loadLibraries.
/// @node: This should never be null.
boost::shared_ptr<LibraryManagerCollection> lm_collection_;
/// Callout manager for the set of library managers.
///
/// @node: This should always be initialized using @ref init or
/// @ref loadLibraries.
/// @node: This should never be null.
boost::shared_ptr<CalloutManager> callout_manager_;
/// Test flag to keep @ref callout_manager_ when calling @ref loadLibraries
......
// File created from ../../../src/lib/hooks/hooks_messages.mes on Wed Jun 24 2020 22:17
// File created from ../../../src/lib/hooks/hooks_messages.mes on Tue Jun 30 2020 14:43
#include <cstddef>
#include <log/message_types.h>
......@@ -26,7 +26,6 @@ extern const isc::log::MessageID HOOKS_LIBRARY_MULTI_THREADING_COMPATIBLE = "HOO
extern const isc::log::MessageID HOOKS_LIBRARY_MULTI_THREADING_NOT_COMPATIBLE = "HOOKS_LIBRARY_MULTI_THREADING_NOT_COMPATIBLE";
extern const isc::log::MessageID HOOKS_LIBRARY_UNLOADED = "HOOKS_LIBRARY_UNLOADED";
extern const isc::log::MessageID HOOKS_LIBRARY_UNLOADING = "HOOKS_LIBRARY_UNLOADING";
extern const isc::log::MessageID HOOKS_LIBRARY_UNLOAD_ALREADY_CALLED = "HOOKS_LIBRARY_UNLOAD_ALREADY_CALLED";
extern const isc::log::MessageID HOOKS_LIBRARY_VERSION = "HOOKS_LIBRARY_VERSION";
extern const isc::log::MessageID HOOKS_LOAD_ERROR = "HOOKS_LOAD_ERROR";
extern const isc::log::MessageID HOOKS_LOAD_EXCEPTION = "HOOKS_LOAD_EXCEPTION";
......@@ -69,7 +68,6 @@ const char* values[] = {
"HOOKS_LIBRARY_MULTI_THREADING_NOT_COMPATIBLE", "hooks library %1 is not compatible with multi-threading",
"HOOKS_LIBRARY_UNLOADED", "hooks library %1 successfully unloaded",
"HOOKS_LIBRARY_UNLOADING", "unloading library %1",
"HOOKS_LIBRARY_UNLOAD_ALREADY_CALLED", "hooks library %1 unload() was already called",
"HOOKS_LIBRARY_VERSION", "hooks library %1 reports its version as %2",
"HOOKS_LOAD_ERROR", "'load' function in hook library %1 returned error %2",
"HOOKS_LOAD_EXCEPTION", "'load' function in hook library %1 threw an exception",
......
// File created from ../../../src/lib/hooks/hooks_messages.mes on Wed Jun 24 2020 22:17
// File created from ../../../src/lib/hooks/hooks_messages.mes on Tue Jun 30 2020 14:43
#ifndef HOOKS_MESSAGES_H
#define HOOKS_MESSAGES_H
......@@ -27,7 +27,6 @@ extern const isc::log::MessageID HOOKS_LIBRARY_MULTI_THREADING_COMPATIBLE;
extern const isc::log::MessageID HOOKS_LIBRARY_MULTI_THREADING_NOT_COMPATIBLE;
extern const isc::log::MessageID HOOKS_LIBRARY_UNLOADED;
extern const isc::log::MessageID HOOKS_LIBRARY_UNLOADING;
extern const isc::log::MessageID HOOKS_LIBRARY_UNLOAD_ALREADY_CALLED;
extern const isc::log::MessageID HOOKS_LIBRARY_VERSION;
extern const isc::log::MessageID HOOKS_LOAD_ERROR;
extern const isc::log::MessageID HOOKS_LOAD_EXCEPTION;
......
......@@ -107,10 +107,6 @@ from the configuration or the multi-threading disabled.
This information message is issued when a user-supplied hooks library
has been successfully unloaded.
% HOOKS_LIBRARY_UNLOAD_ALREADY_CALLED hooks library %1 unload() was already called
This warning message is issued when the unload() function of a
user-supplied hooks library was already called.
% HOOKS_LIBRARY_UNLOADING unloading library %1
This is a debug message called when the specified library is
being unloaded. If all is successful, it will be followed by the
......
......@@ -253,9 +253,7 @@ LibraryManager::prepareUnloadLibrary() {
// Call once.
if (index_ < 0) {
LOG_WARN(hooks_logger, HOOKS_LIBRARY_UNLOAD_ALREADY_CALLED)
.arg(library_name_);
return (false);
return (true);
}
// Get the pointer to the "load" function.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment