Commit 8b7ae5fa authored by Stephen Morris's avatar Stephen Morris
Browse files

[2980] Added the LibraryManagerCollection object

This manages LibraryManagers created for the libraries loaded.
parent 7c20771f
......@@ -1402,6 +1402,7 @@ AC_OUTPUT([doc/version.ent
src/lib/cc/session_config.h.pre
src/lib/cc/tests/session_unittests_config.h
src/lib/datasrc/datasrc_config.h.pre
src/lib/hooks/tests/library_manager_collection_unittest.cc
src/lib/hooks/tests/library_manager_unittest.cc
src/lib/hooks/tests/marker_file.h
src/lib/log/tests/console_test.sh
......
......@@ -33,6 +33,7 @@ libb10_hooks_la_SOURCES += hooks.h
libb10_hooks_la_SOURCES += hooks_log.cc hooks_log.h
libb10_hooks_la_SOURCES += library_handle.cc library_handle.h
libb10_hooks_la_SOURCES += library_manager.cc library_manager.h
libb10_hooks_la_SOURCES += library_manager_collection.cc library_manager_collection.h
libb10_hooks_la_SOURCES += server_hooks.cc server_hooks.h
nodist_libb10_hooks_la_SOURCES = hooks_messages.cc hooks_messages.h
......
......@@ -353,6 +353,9 @@ private:
bool skip_;
};
/// A shared pointer to a CalloutHandle object.
typedef boost::shared_ptr<CalloutHandle> CalloutHandlePtr;
} // namespace util
} // namespace isc
......
......@@ -27,6 +27,18 @@ using namespace std;
namespace isc {
namespace hooks {
// Set the number of libraries handles by the CalloutManager.
void
CalloutManager::setNumLibraries(int num_libraries) {
if (num_libraries < 0) {
isc_throw(isc::BadValue, "number of libraries passed to the "
"CalloutManager must be >= 0");
}
num_libraries_ = num_libraries;
}
// Register a callout for the current library.
void
......
......@@ -96,17 +96,15 @@ public:
///
/// @throw isc::BadValue if the number of libraries is less than or equal
/// to 0, or if the pointer to the server hooks object is empty.
CalloutManager(int num_libraries)
: current_hook_(-1), current_library_(-1), hook_vector_(),
CalloutManager(int num_libraries = 0)
: current_hook_(-1), current_library_(-1),
hook_vector_(ServerHooks::getServerHooks().getCount()),
library_handle_(this), num_libraries_(num_libraries)
{
if (num_libraries <= 0) {
isc_throw(isc::BadValue, "number of libraries passed to the "
"CalloutManager must be >= 0");
}
// Parameters OK, do operations that depend on them.
hook_vector_.resize(ServerHooks::getServerHooks().getCount());
// Check that the number of libraries is OK. (This does a redundant
// set of the number of libraries, but it's only a single assignment
// and avoids the need for a separate "check" method.
setNumLibraries(num_libraries);
}
/// @brief Register a callout on a hook for the current library
......@@ -187,12 +185,23 @@ public:
return (current_hook_);
}
/// @brief Set number of libraries
///
/// Sets the number of libraries. Although the value is passed to the
/// constructor, in some cases that is only an estimate and the number
/// can only be determined after the CalloutManager is created.
///
/// @param num_libraries Number of libraries served by this CalloutManager.
///
/// @throw BadValue Number of libraries must be >= 0.
void setNumLibraries(int num_libraries);
/// @brief Get number of libraries
///
/// Returns the number of libraries that this CalloutManager is expected
/// to serve. This is the number passed to its constructor.
///
/// @return Number of libraries server by this CalloutManager.
/// @return Number of libraries served by this CalloutManager.
int getNumLibraries() const {
return (num_libraries_);
}
......
......@@ -23,6 +23,7 @@ namespace isc {
namespace hooks {
class CalloutManager;
class LibraryHandle;
class LibraryManager;
/// @brief Library manager
......
......@@ -72,6 +72,7 @@ run_unittests_SOURCES = run_unittests.cc
run_unittests_SOURCES += callout_handle_unittest.cc
run_unittests_SOURCES += callout_manager_unittest.cc
run_unittests_SOURCES += handles_unittest.cc
run_unittests_SOURCES += library_manager_collection_unittest.cc
run_unittests_SOURCES += library_manager_unittest.cc
run_unittests_SOURCES += server_hooks_unittest.cc
......
......@@ -177,22 +177,31 @@ TEST_F(CalloutManagerTest, BadConstructorParameters) {
boost::scoped_ptr<CalloutManager> cm;
// Invalid number of libraries
EXPECT_THROW(cm.reset(new CalloutManager(0)), BadValue);
EXPECT_THROW(cm.reset(new CalloutManager(-1)), BadValue);
}
// Check the number of libraries is reported successfully.
TEST_F(CalloutManagerTest, GetNumLibraries) {
TEST_F(CalloutManagerTest, NumberOfLibraries) {
boost::scoped_ptr<CalloutManager> cm;
// Check two valid values of number of libraries to ensure that the
// GetNumLibraries() returns the value set.
EXPECT_NO_THROW(cm.reset(new CalloutManager()));
EXPECT_EQ(0, cm->getNumLibraries());
EXPECT_NO_THROW(cm.reset(new CalloutManager(0)));
EXPECT_EQ(0, cm->getNumLibraries());
EXPECT_NO_THROW(cm.reset(new CalloutManager(4)));
EXPECT_EQ(4, cm->getNumLibraries());
EXPECT_NO_THROW(cm.reset(new CalloutManager(42)));
EXPECT_EQ(42, cm->getNumLibraries());
// Check that setting the number of libraries alterns the number reported.
EXPECT_NO_THROW(cm->setNumLibraries(27));
EXPECT_EQ(27, cm->getNumLibraries());
}
// Check that we can only set the current library index to the correct values.
......
......@@ -33,6 +33,20 @@ using namespace std;
namespace {
// Names of the libraries used in these tests. These libraries are built using
// libtool, so we need to look in the hidden ".libs" directory to locate the
// .so file. Note that we access the .so file - libtool creates this as a
// like to the real shared library.
static const char* BASIC_CALLOUT_LIBRARY = "@abs_builddir@/.libs/libbcl.so";
static const char* FULL_CALLOUT_LIBRARY = "@abs_builddir@/.libs/libfcl.so";
static const char* INCORRECT_VERSION_LIBRARY = "@abs_builddir@/.libs/libivl.so";
static const char* LOAD_CALLOUT_LIBRARY = "@abs_builddir@/.libs/liblcl.so";
static const char* LOAD_ERROR_CALLOUT_LIBRARY =
"@abs_builddir@/.libs/liblecl.so";
static const char* NOT_PRESENT_LIBRARY = "@abs_builddir@/.libs/libnothere.so";
static const char* NO_VERSION_LIBRARY = "@abs_builddir@/.libs/libnvl.so";
static const char* UNLOAD_CALLOUT_LIBRARY = "@abs_builddir@/.libs/libucl.so";
/// @brief Library manager test class
class LibraryManagerTest : public ::testing::Test {
......@@ -143,7 +157,6 @@ public:
boost::shared_ptr<CalloutManager> callout_manager_;
};
/// @brief Library manager class
///
/// This is an instance of the LibraryManager class but with the protected
......@@ -174,20 +187,6 @@ public:
using LibraryManager::runUnload;
};
// Names of the libraries used in these tests. These libraries are built using
// libtool, so we need to look in the hidden ".libs" directory to locate the
// .so file. Note that we access the .so file - libtool creates this as a
// like to the real shared library.
static const char* BASIC_CALLOUT_LIBRARY = "@abs_builddir@/.libs/libbcl.so";
static const char* FULL_CALLOUT_LIBRARY = "@abs_builddir@/.libs/libfcl.so";
static const char* INCORRECT_VERSION_LIBRARY = "@abs_builddir@/.libs/libivl.so";
static const char* LOAD_CALLOUT_LIBRARY = "@abs_builddir@/.libs/liblcl.so";
static const char* LOAD_ERROR_CALLOUT_LIBRARY =
"@abs_builddir@/.libs/liblecl.so";
static const char* NOT_PRESENT_LIBRARY = "@abs_builddir@/.libs/libnothere.so";
static const char* NO_VERSION_LIBRARY = "@abs_builddir@/.libs/libnvl.so";
static const char* UNLOAD_CALLOUT_LIBRARY = "@abs_builddir@/.libs/libucl.so";
// Check that openLibrary() reports an error when it can't find the specified
// library.
......
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