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
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
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).
// 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>
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
///
/// @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
} // namespace util
} // namespace isc
-#endif // LIBRARY_HANDLE_H
+#endif // CALLOUT_MANAGER_H
--- /dev/null
+// 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
--- /dev/null
+// 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
#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>