BIND 10 trac2974, updated. ab1890f4594c873aca0b7f483234de5cd3e5e01c [2974] Split out CalloutManager and LibraryHandle into separate files
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Jun 7 16:35:07 UTC 2013
The branch, trac2974 has been updated
via ab1890f4594c873aca0b7f483234de5cd3e5e01c (commit)
from 71376fdfd9be70f5dc7f28fcec5bb75fbeb27ccd (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit ab1890f4594c873aca0b7f483234de5cd3e5e01c
Author: Stephen Morris <stephen at isc.org>
Date: Fri Jun 7 17:34:06 2013 +0100
[2974] Split out CalloutManager and LibraryHandle into separate files
-----------------------------------------------------------------------
Summary of changes:
src/lib/util/Makefile.am | 1 +
src/lib/util/hooks/callout_manager.cc | 19 +--
src/lib/util/hooks/callout_manager.h | 131 +-------------------
.../library_handle.cc} | 41 +++---
src/lib/util/hooks/library_handle.h | 122 ++++++++++++++++++
src/lib/util/tests/callout_manager_unittest.cc | 1 +
6 files changed, 147 insertions(+), 168 deletions(-)
copy src/lib/util/{unittests/interprocess_util.cc => hooks/library_handle.cc} (56%)
create mode 100644 src/lib/util/hooks/library_handle.h
-----------------------------------------------------------------------
diff --git a/src/lib/util/Makefile.am b/src/lib/util/Makefile.am
index 0f22a74..9c66fd5 100644
--- a/src/lib/util/Makefile.am
+++ b/src/lib/util/Makefile.am
@@ -39,6 +39,7 @@ libb10_util_la_SOURCES += encode/binary_from_base32hex.h
libb10_util_la_SOURCES += encode/binary_from_base16.h
libb10_util_la_SOURCES += hooks/callout_manager.h hooks/callout_manager.cc
# libb10_util_la_SOURCES += hooks/callout_handle.h hooks/callout_handle.cc
+libb10_util_la_SOURCES += hooks/library_handle.h hooks/library_handle.cc
libb10_util_la_SOURCES += hooks/server_hooks.h hooks/server_hooks.cc
libb10_util_la_SOURCES += random/qid_gen.h random/qid_gen.cc
libb10_util_la_SOURCES += random/random_number_generator.h
diff --git a/src/lib/util/hooks/callout_manager.cc b/src/lib/util/hooks/callout_manager.cc
index 1cae83f..4006103 100644
--- a/src/lib/util/hooks/callout_manager.cc
+++ b/src/lib/util/hooks/callout_manager.cc
@@ -25,23 +25,6 @@ using namespace isc::util;
namespace isc {
namespace util {
-// Callout manipulation - all deferred to the CalloutManager.
-
-void
-LibraryHandle::registerCallout(const std::string& name, CalloutPtr callout) {
- callout_manager_->registerCallout(library_index_, name, callout);
-}
-
-bool
-LibraryHandle::deregisterCallout(const std::string& name, CalloutPtr callout) {
- return (callout_manager_->deregisterCallout(library_index_, name, callout));
-}
-
-bool
-LibraryHandle::deregisterAllCallouts(const std::string& name) {
- return (callout_manager_->deregisterAllCallouts(library_index_, name));
-}
-
// Register a callout for a particular library.
void
@@ -147,7 +130,7 @@ CalloutManager::deregisterCallout(int library_index, const std::string& name,
bool
CalloutManager::deregisterAllCallouts(int library_index,
- const std::string& name) {
+ const std::string& name) {
// Get the index associated with this hook (validating the name in the
// process).
diff --git a/src/lib/util/hooks/callout_manager.h b/src/lib/util/hooks/callout_manager.h
index f1b8d8c..bfe88c9 100644
--- a/src/lib/util/hooks/callout_manager.h
+++ b/src/lib/util/hooks/callout_manager.h
@@ -12,10 +12,11 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
-#ifndef LIBRARY_HANDLE_H
-#define LIBRARY_HANDLE_H
+#ifndef CALLOUT_MANAGER_H
+#define CALLOUT_MANAGER_H
#include <exceptions/exceptions.h>
+#include <util/hooks/library_handle.h>
#include <util/hooks/server_hooks.h>
#include <boost/shared_ptr.hpp>
@@ -26,127 +27,6 @@
namespace isc {
namespace util {
-/// @brief No Such Context
-///
-/// Thrown if an attempt is made to obtain context that has not been previously
-/// set.
-
-class NoSuchLibraryContext : public Exception {
-public:
- NoSuchLibraryContext(const char* file, size_t line, const char* what) :
- isc::Exception(file, line, what) {}
-};
-
-/// @brief Invalid index
-///
-/// Thrown if an attempt is made to obtain a library handle but the current
-/// library handle index is invalid. This will occur if the method
-/// CalloutManager::getHandleVector() is called outside of a callout.
-
-class InvalidIndex : public Exception {
-public:
- InvalidIndex(const char* file, size_t line, const char* what) :
- isc::Exception(file, line, what) {}
-};
-
-// Forward declarations
-class CalloutHandle;
-class CalloutManager;
-
-/// Typedef for a callout pointer. (Callouts must have "C" linkage.)
-extern "C" {
- typedef int (*CalloutPtr)(CalloutHandle&);
-};
-
-
-
-
-/// @brief Library handle
-///
-/// This class is used to manage a loaded library. It is used by the user
-/// library to register callouts.
-///
-/// The main processing is done by the CalloutManager class. By
-/// presenting this object to the user-library callouts, they can manage the
-/// callout list for their own library, but cannot affect the callouts registered
-/// by other libraries.
-
-class LibraryHandle {
-public:
-
- /// @brief Constructor
- ///
- /// @param hooks Library index. A number (starting at 0) that represents
- /// the index of the library in the list of libraries loaded by the
- /// server.
- /// @param collection Back pointer to the containing CalloutManager.
- /// This pointer is used to access appropriate methods in the collection
- /// object.
- LibraryHandle(int library_index, CalloutManager* collection)
- : library_index_(library_index), callout_manager_(collection)
- {}
-
- /// @brief Register a callout on a hook
- ///
- /// Registers a callout function with a given hook. The callout is added
- /// to the end of the callouts for this library that are associated with
- /// that hook.
- ///
- /// @param name Name of the hook to which the callout is added.
- /// @param callout Pointer to the callout function to be registered.
- ///
- /// @throw NoSuchHook The hook name is unrecognised.
- /// @throw Unexpected The hook name is valid but an internal data structure
- /// is of the wrong size.
- void registerCallout(const std::string& name, CalloutPtr callout);
-
- /// @brief De-Register a callout on a hook
- ///
- /// Searches through the functions registered by this library with the named
- /// hook and removes all entries matching the callout. It does not affect
- /// callouts registered by other libraries.
- ///
- /// @param name Name of the hook from which the callout is removed.
- /// @param callout Pointer to the callout function to be removed.
- ///
- /// @return true if a one or more callouts were deregistered.
- ///
- /// @throw NoSuchHook The hook name is unrecognised.
- /// @throw Unexpected The hook name is valid but an internal data structure
- /// is of the wrong size.
- bool deregisterCallout(const std::string& name, CalloutPtr callout);
-
- /// @brief Removes all callouts on a hook
- ///
- /// Removes all callouts associated with a given hook that were registered.
- /// by this library. It does not affect callouts that were registered by
- /// other libraries.
- ///
- /// @param name Name of the hook from which the callouts are removed.
- ///
- /// @return true if one or more callouts were deregistered.
- ///
- /// @throw NoSuchHook Thrown if the hook name is unrecognised.
- bool deregisterAllCallouts(const std::string& name);
-
- /// @brief Return handle index
- ///
- /// For test purposes only, this returns the index allocated to this
- /// LibraryHandle.
- ///
- /// @return Handle index
- int getIndex() const {
- return (library_index_);
- }
-
-private:
- /// Index of this handle in the library handle list
- int library_index_;
-
- /// Back pointer to the collection object for the library
- CalloutManager* callout_manager_;
-};
-
/// @brief Callout Manager
///
@@ -284,7 +164,8 @@ private:
/// @brief Compare two callout entries for library equality
///
- /// This is used in callout removal code.
+ /// This is used in callout removal code. It just checks whether two
+ /// entries have the same library element.
///
/// @param ent1 First callout entry to check
/// @param ent2 Second callout entry to check
@@ -312,4 +193,4 @@ private:
} // namespace util
} // namespace isc
-#endif // LIBRARY_HANDLE_H
+#endif // CALLOUT_MANAGER_H
diff --git a/src/lib/util/hooks/library_handle.cc b/src/lib/util/hooks/library_handle.cc
new file mode 100644
index 0000000..3ea2192
--- /dev/null
+++ b/src/lib/util/hooks/library_handle.cc
@@ -0,0 +1,39 @@
+// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <util/hooks/callout_manager.h>
+#include <util/hooks/library_handle.h>
+
+namespace isc {
+namespace util {
+
+// Callout manipulation - all deferred to the CalloutManager.
+
+void
+LibraryHandle::registerCallout(const std::string& name, CalloutPtr callout) {
+ callout_manager_->registerCallout(library_index_, name, callout);
+}
+
+bool
+LibraryHandle::deregisterCallout(const std::string& name, CalloutPtr callout) {
+ return (callout_manager_->deregisterCallout(library_index_, name, callout));
+}
+
+bool
+LibraryHandle::deregisterAllCallouts(const std::string& name) {
+ return (callout_manager_->deregisterAllCallouts(library_index_, name));
+}
+
+} // namespace util
+} // namespace isc
diff --git a/src/lib/util/hooks/library_handle.h b/src/lib/util/hooks/library_handle.h
new file mode 100644
index 0000000..9b90245
--- /dev/null
+++ b/src/lib/util/hooks/library_handle.h
@@ -0,0 +1,122 @@
+// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef LIBRARY_HANDLE_H
+#define LIBRARY_HANDLE_H
+
+#include <string>
+
+namespace isc {
+namespace util {
+
+// Forward declarations
+class CalloutHandle;
+class CalloutManager;
+
+/// Typedef for a callout pointer. (Callouts must have "C" linkage.)
+extern "C" {
+ typedef int (*CalloutPtr)(CalloutHandle&);
+};
+
+/// @brief Library handle
+///
+/// This class is accessed by the user library when registering callouts,
+/// either by the library's load() function, or by one of the callouts
+/// themselves.
+///
+/// It is really little more than a shell around the CalloutManager/ By
+/// presenting this object to the user-library callouts, callouts can manage the
+/// callout list for their own library, but cannot affect the callouts
+/// registered by other libraries.
+
+class LibraryHandle {
+public:
+
+ /// @brief Constructor
+ ///
+ /// @param hooks Library index. A number (starting at 0) that represents
+ /// the index of the library in the list of libraries loaded by the
+ /// server.
+ /// @param collection Back pointer to the containing CalloutManager.
+ /// This pointer is used to access appropriate methods in that
+ /// object.
+ LibraryHandle(int library_index, CalloutManager* collection)
+ : library_index_(library_index), callout_manager_(collection)
+ {}
+
+ /// @brief Register a callout on a hook
+ ///
+ /// Registers a callout function with a given hook. The callout is added
+ /// to the end of the callouts for this library that are associated with
+ /// that hook.
+ ///
+ /// @param name Name of the hook to which the callout is added.
+ /// @param callout Pointer to the callout function to be registered.
+ ///
+ /// @throw NoSuchHook The hook name is unrecognised.
+ /// @throw Unexpected The hook name is valid but an internal data structure
+ /// is of the wrong size.
+ void registerCallout(const std::string& name, CalloutPtr callout);
+
+ /// @brief De-Register a callout on a hook
+ ///
+ /// Searches through the functions registered by this library with the named
+ /// hook and removes all entries matching the callout. It does not affect
+ /// callouts registered by other libraries.
+ ///
+ /// @param name Name of the hook from which the callout is removed.
+ /// @param callout Pointer to the callout function to be removed.
+ ///
+ /// @return true if a one or more callouts were deregistered.
+ ///
+ /// @throw NoSuchHook The hook name is unrecognised.
+ /// @throw Unexpected The hook name is valid but an internal data structure
+ /// is of the wrong size.
+ bool deregisterCallout(const std::string& name, CalloutPtr callout);
+
+ /// @brief Removes all callouts on a hook
+ ///
+ /// Removes all callouts associated with a given hook that were registered.
+ /// by this library. It does not affect callouts that were registered by
+ /// other libraries.
+ ///
+ /// @param name Name of the hook from which the callouts are removed.
+ ///
+ /// @return true if one or more callouts were deregistered.
+ ///
+ /// @throw NoSuchHook Thrown if the hook name is unrecognised.
+ bool deregisterAllCallouts(const std::string& name);
+
+ /// @brief Return handle index
+ ///
+ /// For test purposes only, this returns the index allocated to this
+ /// LibraryHandle.
+ ///
+ /// @return Handle index
+ int getIndex() const {
+ return (library_index_);
+ }
+
+private:
+ /// Index of this handle in the library handle list
+ int library_index_;
+
+ /// Back pointer to the collection object for the library
+ CalloutManager* callout_manager_;
+};
+
+} // namespace util
+} // namespace isc
+
+#endif // LIBRARY_HANDLE_H
diff --git a/src/lib/util/tests/callout_manager_unittest.cc b/src/lib/util/tests/callout_manager_unittest.cc
index 214eec2..0294305 100644
--- a/src/lib/util/tests/callout_manager_unittest.cc
+++ b/src/lib/util/tests/callout_manager_unittest.cc
@@ -15,6 +15,7 @@
#include <exceptions/exceptions.h>
#include <util/hooks/callout_handle.h>
#include <util/hooks/callout_manager.h>
+#include <util/hooks/library_handle.h>
#include <util/hooks/server_hooks.h>
#include <gtest/gtest.h>
More information about the bind10-changes
mailing list