BIND 10 trac2974, updated. 9deba8e6b563fbeeb98af85b89aee5c9f4878a03 [2974] Extended context methods on both CalloutHandle and LibraryHandle
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon May 27 19:38:25 UTC 2013
The branch, trac2974 has been updated
via 9deba8e6b563fbeeb98af85b89aee5c9f4878a03 (commit)
from 26f53e4d06284cf0854ec06d14b5071b26996347 (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 9deba8e6b563fbeeb98af85b89aee5c9f4878a03
Author: Stephen Morris <stephen at isc.org>
Date: Mon May 27 20:38:04 2013 +0100
[2974] Extended context methods on both CalloutHandle and LibraryHandle
-----------------------------------------------------------------------
Summary of changes:
src/lib/util/Makefile.am | 2 +-
.../hooks/callout_handle.cc} | 38 ++++++-----
src/lib/util/hooks/callout_handle.h | 8 +--
src/lib/util/hooks/library_handle.cc | 19 +++++-
src/lib/util/hooks/library_handle.h | 30 +++++++++
src/lib/util/hooks/server_hooks.cc | 4 +-
src/lib/util/tests/callout_handle_unittest.cc | 24 +++++++
src/lib/util/tests/library_handle_unittest.cc | 67 ++++++++++++++++++++
8 files changed, 167 insertions(+), 25 deletions(-)
copy src/lib/{dns/python/zone_checker_python.h => util/hooks/callout_handle.cc} (62%)
-----------------------------------------------------------------------
diff --git a/src/lib/util/Makefile.am b/src/lib/util/Makefile.am
index 8e42eff..bae2a80 100644
--- a/src/lib/util/Makefile.am
+++ b/src/lib/util/Makefile.am
@@ -37,7 +37,7 @@ libb10_util_la_SOURCES += encode/base32hex_from_binary.h
libb10_util_la_SOURCES += encode/base_n.cc encode/hex.h
libb10_util_la_SOURCES += encode/binary_from_base32hex.h
libb10_util_la_SOURCES += encode/binary_from_base16.h
-libb10_util_la_SOURCES += hooks/callout_handle.h
+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
diff --git a/src/lib/util/hooks/callout_handle.cc b/src/lib/util/hooks/callout_handle.cc
new file mode 100644
index 0000000..57d1b6a
--- /dev/null
+++ b/src/lib/util/hooks/callout_handle.cc
@@ -0,0 +1,43 @@
+// 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_handle.h>
+
+#include <algorithm>
+#include <functional>
+#include <string>
+#include <vector>
+
+using namespace std;
+using namespace isc::util;
+
+namespace isc {
+namespace util {
+
+// return the name of all context items.
+
+vector<string>
+CalloutHandle::getArgumentNames() const {
+
+ vector<string> names;
+ ArgumentCollection::const_iterator i;
+ for (i = arguments_.begin(); i != arguments_.end(); ++i) {
+ names.push_back(i->first);
+ }
+
+ return (names);
+}
+
+} // namespace util
+} // namespace isc
diff --git a/src/lib/util/hooks/callout_handle.h b/src/lib/util/hooks/callout_handle.h
index 7426957..24fc7c9 100644
--- a/src/lib/util/hooks/callout_handle.h
+++ b/src/lib/util/hooks/callout_handle.h
@@ -101,16 +101,16 @@ public:
/// vector.
///
/// @return Vector of strings reflecting argument names
- std::vector<std::string> getArgumentNames() const {
- std::vector<std::string> a;
- return (a);
- }
+ std::vector<std::string> getArgumentNames() const;
/// @brief Delete argument
///
/// Deletes an argument of the given name. If an argument of that name
/// does not exist, the method is a no-op.
///
+ /// N.B. If the element is a raw pointer, the pointed-to data is
+ /// NOT deleted by this.
+ ///
/// @param name Name of the element in the argument list to set.
void deleteArgument(const std::string& name) {
static_cast<void>(arguments_.erase(name));
diff --git a/src/lib/util/hooks/library_handle.cc b/src/lib/util/hooks/library_handle.cc
index bf05037..882f03d 100644
--- a/src/lib/util/hooks/library_handle.cc
+++ b/src/lib/util/hooks/library_handle.cc
@@ -28,9 +28,8 @@ namespace util {
void
LibraryHandle::checkHookIndex(int index) const {
if ((index < 0) || (index >= hook_vector_.size())) {
- isc_throw(NoSuchHook, "unable to call callout for hook index " <<
- index << ": index is invalid for the size of the hook "
- "vector (" << hook_vector_.size() << ")");
+ isc_throw(NoSuchHook, "hook index " << index << " is invalid for the "
+ " size of the hook vector (" << hook_vector_.size() << ")");
}
}
@@ -137,5 +136,19 @@ LibraryHandle::deregisterAll(const std::string& name) {
hook_vector_[index].clear();
}
+// return the name of all context items.
+
+vector<string>
+LibraryHandle::getContextNames() const {
+
+ vector<string> names;
+ ContextCollection::const_iterator i;
+ for (i = context_.begin(); i != context_.end(); ++i) {
+ names.push_back(i->first);
+ }
+
+ return (names);
+}
+
} // namespace util
} // namespace isc
diff --git a/src/lib/util/hooks/library_handle.h b/src/lib/util/hooks/library_handle.h
index f5fa81a..f9de92f 100644
--- a/src/lib/util/hooks/library_handle.h
+++ b/src/lib/util/hooks/library_handle.h
@@ -121,6 +121,36 @@ public:
value = boost::any_cast<T>(element_ptr->second);
}
+
+ /// @brief Get context names
+ ///
+ /// Returns a vector holding the names of context items.
+ ///
+ /// @return Vector of strings reflecting argument names
+ std::vector<std::string> getContextNames() const;
+
+ /// @brief Delete context element
+ ///
+ /// Deletes context item of the given name. If an item of that name
+ /// does not exist, the method is a no-op.
+ ///
+ /// N.B. If the element is a raw pointer, the pointed-to data is
+ /// NOT deleted by this.
+ ///
+ /// @param name Name of the element in the argument list to set.
+ void deleteContext(const std::string& name) {
+ static_cast<void>(context_.erase(name));
+ }
+
+ /// @brief Delete all arguments
+ ///
+ /// Deletes all arguments associated with this context.
+ ///
+ /// N.B. If any elements are raw pointers, the pointed-to data is
+ /// NOT deleted by this.
+ void deleteAllContext() {
+ context_.clear();
+ }
/// @brief Register a callout
///
diff --git a/src/lib/util/hooks/server_hooks.cc b/src/lib/util/hooks/server_hooks.cc
index 6d5a911..81ef571 100644
--- a/src/lib/util/hooks/server_hooks.cc
+++ b/src/lib/util/hooks/server_hooks.cc
@@ -77,10 +77,10 @@ ServerHooks::getIndex(const string& name) const {
// Return list of hooks
-std::vector<std::string>
+vector<string>
ServerHooks::getHookNames() const {
- std::vector<std::string> names;
+ vector<string> names;
HookCollection::const_iterator i;
for (i = hooks_.begin(); i != hooks_.end(); ++i) {
names.push_back(i->first);
diff --git a/src/lib/util/tests/callout_handle_unittest.cc b/src/lib/util/tests/callout_handle_unittest.cc
index 79e536d..ed4416e 100644
--- a/src/lib/util/tests/callout_handle_unittest.cc
+++ b/src/lib/util/tests/callout_handle_unittest.cc
@@ -218,6 +218,30 @@ TEST_F(CalloutHandleTest, PointerTypes) {
boost::bad_any_cast);
}
+// Check that we can get the names of the arguments.
+
+TEST_F(CalloutHandleTest, ContextItemNames) {
+ CalloutHandle handle(getHookManager());
+
+ vector<string> expected_names;
+ int value = 42;
+
+ expected_names.push_back("faith");
+ handle.setArgument("faith", value++);
+ expected_names.push_back("hope");
+ handle.setArgument("hope", value++);
+ expected_names.push_back("charity");
+ handle.setArgument("charity", value++);
+
+ // Get the names and check against the expected names. We'll sort
+ // both arrays to simplify the checking.
+ vector<string> actual_names = handle.getArgumentNames();
+
+ sort(actual_names.begin(), actual_names.end());
+ sort(expected_names.begin(), expected_names.end());
+ EXPECT_TRUE(expected_names == actual_names);
+}
+
// Test that we can delete and argument.
TEST_F(CalloutHandleTest, DeleteArgument) {
diff --git a/src/lib/util/tests/library_handle_unittest.cc b/src/lib/util/tests/library_handle_unittest.cc
index 1f47d1b..5a9de2b 100644
--- a/src/lib/util/tests/library_handle_unittest.cc
+++ b/src/lib/util/tests/library_handle_unittest.cc
@@ -18,6 +18,10 @@
#include <gtest/gtest.h>
+#include <algorithm>
+#include <string>
+#include <vector>
+
using namespace isc::util;
using namespace std;
@@ -237,6 +241,69 @@ TEST_F(LibraryHandleTest, PointerTypes) {
boost::bad_any_cast);
}
+// Check that we can get the names of the context items.
+
+TEST_F(LibraryHandleTest, ContextItemNames) {
+ LibraryHandle handle(getServerHooks(), 1);
+
+ vector<string> expected_names;
+ int value = 42;
+
+ expected_names.push_back("faith");
+ handle.setContext("faith", value++);
+ expected_names.push_back("hope");
+ handle.setContext("hope", value++);
+ expected_names.push_back("charity");
+ handle.setContext("charity", value++);
+
+ // Get the names and check against the expected names. We'll sort
+ // both arrays to simplify the checking.
+ vector<string> actual_names = handle.getContextNames();
+
+ sort(actual_names.begin(), actual_names.end());
+ sort(expected_names.begin(), expected_names.end());
+ EXPECT_TRUE(expected_names == actual_names);
+}
+
+// Check that we can delete one item of context.
+
+TEST_F(LibraryHandleTest, DeleteContext) {
+ LibraryHandle handle(getServerHooks(), 1);
+
+ int value = 42;
+ handle.setContext("faith", value++);
+ handle.setContext("hope", value++);
+ value = 0;
+
+ // Delete "faith" and verify that getting it throws an exception
+ handle.deleteContext("faith");
+ EXPECT_THROW(handle.getContext("faith", value), NoSuchContext);
+
+ // Check that the other item is untouched.
+ EXPECT_NO_THROW(handle.getContext("hope", value));
+ EXPECT_EQ(43, value);
+}
+
+// Delete all all items of context.
+
+TEST_F(LibraryHandleTest, DeleteAllContext) {
+ LibraryHandle handle(getServerHooks(), 1);
+
+ int value = 42;
+ handle.setContext("faith", value++);
+ handle.setContext("hope", value++);
+ handle.setContext("charity", value++);
+ value = 0;
+
+ // Delete all items of context and verify that they are gone.
+ handle.deleteAllContext();
+ EXPECT_THROW(handle.getContext("faith", value), NoSuchContext);
+ EXPECT_THROW(handle.getContext("hope", value), NoSuchContext);
+ EXPECT_THROW(handle.getContext("charity", value), NoSuchContext);
+}
+
+
+
// *** Callout Tests ***
//
// The next set of tests check that callouts can be registered.
More information about the bind10-changes
mailing list