BIND 10 trac2376-callbacks, updated. d95162bee2f3bc75810dfdf2e2f1938690c5ceb7 [2376] Some forward declarations

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Nov 21 12:52:45 UTC 2012


The branch, trac2376-callbacks has been updated
       via  d95162bee2f3bc75810dfdf2e2f1938690c5ceb7 (commit)
       via  1b8d478d7b5ed39f1c64d6c4973addc976aa01d3 (commit)
      from  86c78e9e9cf17caacb76918795849b4ea9941d41 (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 d95162bee2f3bc75810dfdf2e2f1938690c5ceb7
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Wed Nov 21 13:52:27 2012 +0100

    [2376] Some forward declarations
    
    So we can include less

commit 1b8d478d7b5ed39f1c64d6c4973addc976aa01d3
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Wed Nov 21 13:48:02 2012 +0100

    [2376] Split off the add callback
    
    So the issue callbacks don't depend on other things.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/datasrc/master_loader_callbacks.cc         |   23 +++++-----
 src/lib/datasrc/master_loader_callbacks.h          |   37 ++++++++++-----
 .../datasrc/tests/master_loader_callbacks_test.cc  |   22 +++------
 src/lib/dns/master_loader_callbacks.h              |   47 ++++++++------------
 src/lib/dns/tests/master_loader_callbacks_test.cc  |   28 +++---------
 5 files changed, 67 insertions(+), 90 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/master_loader_callbacks.cc b/src/lib/datasrc/master_loader_callbacks.cc
index c6bb6f1..54e4d0e 100644
--- a/src/lib/datasrc/master_loader_callbacks.cc
+++ b/src/lib/datasrc/master_loader_callbacks.cc
@@ -51,25 +51,22 @@ logWarning(const isc::dns::Name& name, const isc::dns::RRClass& rrclass,
 }
 
 isc::dns::MasterLoaderCallbacks
-createMasterLoaderCallbacks(ZoneUpdater& updater, const isc::dns::Name& name,
+createMasterLoaderCallbacks(const isc::dns::Name& name,
                             const isc::dns::RRClass& rrclass, bool* ok)
 {
     return (isc::dns::MasterLoaderCallbacks(boost::bind(&logError, name,
                                                         rrclass, ok, _1, _2,
                                                         _3),
                                             boost::bind(&logWarning, name,
-                                                        rrclass, _1, _2, _3),
-                                            boost::bind(&ZoneUpdater::addRRset,
-                                                        &updater,
-                                                        // The callback provides
-                                                        // a shared pointer, we
-                                                        // need the object. This
-                                                        // bind unpacks the
-                                                        // object.
-                                                        boost::bind(&isc::dns::
-                                                                    RRsetPtr::
-                                                                    operator*,
-                                                                    _1))));
+                                                        rrclass, _1, _2, _3)));
+}
+
+isc::dns::AddRRsetCallback
+createMasterLoaderAddCallback(ZoneUpdater& updater) {
+    return (boost::bind(&ZoneUpdater::addRRset, &updater,
+                        // The callback provides a shared pointer, we
+                        // need the object. This bind unpacks the object.
+                        boost::bind(&isc::dns::RRsetPtr::operator*, _1)));
 }
 
 }
diff --git a/src/lib/datasrc/master_loader_callbacks.h b/src/lib/datasrc/master_loader_callbacks.h
index a592319..c258303 100644
--- a/src/lib/datasrc/master_loader_callbacks.h
+++ b/src/lib/datasrc/master_loader_callbacks.h
@@ -18,22 +18,19 @@
 #include <dns/master_loader_callbacks.h>
 
 namespace isc {
+namespace dns {
+class Name;
+class RRClass;
+}
 namespace datasrc {
 
 class ZoneUpdater;
 
-/// \brief Create callbacks to fill loaded zone into updater.
+/// \brief Create issue callbacks for MasterLoader
 ///
 /// This will create set of callbacks for the MasterLoader that
-/// will fill the loaded rrsets into a zone updater. If any issues
-/// are found, it logs them. If any of the issues are errors and
-/// the ok parameter is non-NULL, it is set to false.
+/// will be used to report any issues found in the zone data.
 ///
-/// \param updater The zone updater used as the destination for the
-///     RRsets. It should be opened in the replace mode and should
-///     be clean (no changes done to it). It is not commited
-///     automatically and it is up to the caller to commit (or not)
-///     when the loading is done.
 /// \param name Name of the zone. Used in logging.
 /// \param rrclass The class of the zone. Used in logging.
 /// \param ok If this is non-NULL and there are any errors during
@@ -41,9 +38,29 @@ class ZoneUpdater;
 /// \return Set of callbacks to be passed to the master loader.
 /// \throw std::bad_alloc when allocation fails.
 isc::dns::MasterLoaderCallbacks
-createMasterLoaderCallbacks(ZoneUpdater& updater, const isc::dns::Name& name,
+createMasterLoaderCallbacks(const isc::dns::Name& name,
                             const isc::dns::RRClass& rrclass, bool* ok);
 
+/// \brief Create a callback for MasterLoader to add RRsets.
+///
+/// This creates a callback that can be used by the MasterLoader to add
+/// loaded RRsets into a zone updater.
+///
+/// The zone updater should be opened in the replace mode no changes should
+/// have been done to it yet (but it is not checked). It is not commited
+/// automatically and it is up to the caller to commit the changes (or not).
+/// It must not be destroyed for the whole time of loading.
+///
+/// The function is mostly straightforward packing of the updater.addRRset
+/// into a boost::function, it is defined explicitly due to small technical
+/// annoyences around boost::bind application, so it can be reused.
+///
+/// \param updater The zone updater to use.
+/// \return The callback to be passed to MasterLoader.
+/// \throw std::bad_alloc when allocation fails.
+isc::dns::AddRRsetCallback
+createMasterLoaderAddCallback(ZoneUpdater& updater);
+
 }
 }
 
diff --git a/src/lib/datasrc/tests/master_loader_callbacks_test.cc b/src/lib/datasrc/tests/master_loader_callbacks_test.cc
index 6f62543..f814288 100644
--- a/src/lib/datasrc/tests/master_loader_callbacks_test.cc
+++ b/src/lib/datasrc/tests/master_loader_callbacks_test.cc
@@ -63,8 +63,7 @@ class MasterLoaderCallbackTest : public ::testing::Test {
 protected:
     MasterLoaderCallbackTest() :
         ok_(true),
-        callbacks_(createMasterLoaderCallbacks(updater_,
-                                               isc::dns::Name("example.org"),
+        callbacks_(createMasterLoaderCallbacks(isc::dns::Name("example.org"),
                                                isc::dns::RRClass::IN(), &ok_))
     {}
     // Generate a new RRset, put it to the updater and return it.
@@ -87,7 +86,7 @@ protected:
 
 // Check it doesn't crash if we don't provide the OK
 TEST_F(MasterLoaderCallbackTest, noOkProvided) {
-    createMasterLoaderCallbacks(updater_, isc::dns::Name("example.org"),
+    createMasterLoaderCallbacks(isc::dns::Name("example.org"),
                                 isc::dns::RRClass::IN(), NULL).
         error("No source", 1, "No reason");
 }
@@ -113,22 +112,13 @@ TEST_F(MasterLoaderCallbackTest, callbacks) {
 
 // Try adding some RRsets.
 TEST_F(MasterLoaderCallbackTest, addRRset) {
+    isc::dns::AddRRsetCallback
+        callback(createMasterLoaderAddCallback(updater_));
     // Put some of them in.
-    EXPECT_NO_THROW(callbacks_.addRRset(generateRRset()));
-    EXPECT_NO_THROW(callbacks_.addRRset(generateRRset()));
+    EXPECT_NO_THROW(callback(generateRRset()));
+    EXPECT_NO_THROW(callback(generateRRset()));
     // They all get pushed there right away, so there are none in the queue
     EXPECT_TRUE(updater_.expected_rrsets_.empty());
-
-    // Making the status not OK by an error does not stop the RRsets to get
-    // through.
-    callbacks_.error("No source", 1, "Just an error");
-    EXPECT_FALSE(ok_);
-
-    EXPECT_NO_THROW(callbacks_.addRRset(generateRRset()));
-    EXPECT_NO_THROW(callbacks_.addRRset(generateRRset()));
-    // They got through and the OK status didn't get reset
-    EXPECT_TRUE(updater_.expected_rrsets_.empty());
-    EXPECT_FALSE(ok_);
 }
 
 }
diff --git a/src/lib/dns/master_loader_callbacks.h b/src/lib/dns/master_loader_callbacks.h
index 4af8f54..00d831c 100644
--- a/src/lib/dns/master_loader_callbacks.h
+++ b/src/lib/dns/master_loader_callbacks.h
@@ -15,17 +15,30 @@
 #ifndef MASTER_LOADER_CALLBACKS_H
 #define MASTER_LOADER_CALLBACKS_H
 
-#include <dns/rrset.h>
-
 #include <exceptions/exceptions.h>
 
 #include <string>
 #include <boost/function.hpp>
+#include <boost/shared_ptr.hpp>
 
 namespace isc {
 namespace dns {
 
-/// \brief Set of callbacks for a loader.
+class AbstractRRset;
+typedef boost::shared_ptr<AbstractRRset> RRsetPtr;
+
+/// \brief Type of callback to add a RRset.
+///
+/// This type of callback is used by the loader to report another loaded
+/// RRset. The RRset is no longer preserved by the loader and is fully
+/// owned by the callback.
+///
+/// \param RRset The rrset to add. It does not contain the accompanying
+///     RRSIG (if the zone is signed), they are reported with separate
+///     calls to the callback.
+typedef boost::function<void(const RRsetPtr& rrset)> AddRRsetCallback;
+
+/// \brief Set of issue callbacks for a loader.
 ///
 /// This holds a set of callbacks by which a loader (such as MasterLoader)
 /// can report loaded RRsets, errors and other unusual conditions.
@@ -47,33 +60,19 @@ public:
                                  size_t source_line,
                                  const std::string& reason)> IssueCallback;
 
-    /// \brief Type of callback to add a RRset.
-    ///
-    /// This type of callback is used by the loader to report another loaded
-    /// RRset. The RRset is no longer preserved by the loader and is fully
-    /// owned by the callback.
-    ///
-    /// \param RRset The rrset to add. It does not contain the accompanying
-    ///     RRSIG (if the zone is signed), they are reported with separate
-    ///     calls to the callback.
-    typedef boost::function<void(const RRsetPtr& rrset)> AddCallback;
-
     /// \brief Constructor
     ///
     /// Initializes the callbacks.
     ///
     /// \param error The error callback to use.
     /// \param warning The warning callback to use.
-    /// \param add The add callback to use.
     /// \throw isc::InvalidParameter if any of the callbacks is empty.
     MasterLoaderCallbacks(const IssueCallback& error,
-                          const IssueCallback& warning,
-                          const AddCallback& add) :
+                          const IssueCallback& warning) :
         error_(error),
-        warning_(warning),
-        add_(add)
+        warning_(warning)
     {
-        if (error_.empty() || warning_.empty() || add_.empty()) {
+        if (error_.empty() || warning_.empty()) {
             isc_throw(isc::InvalidParameter,
                       "Empty function passed as callback");
         }
@@ -113,16 +112,8 @@ public:
         warning_(source_name, source_line, reason);
     }
 
-    /// \brief Call the add callback.
-    ///
-    /// This is called for each loaded RRset.
-    void addRRset(const RRsetPtr& rrset) {
-        add_(rrset);
-    }
-
 private:
     IssueCallback error_, warning_;
-    AddCallback add_;
 };
 
 }
diff --git a/src/lib/dns/tests/master_loader_callbacks_test.cc b/src/lib/dns/tests/master_loader_callbacks_test.cc
index b93c87e..e9f7ae2 100644
--- a/src/lib/dns/tests/master_loader_callbacks_test.cc
+++ b/src/lib/dns/tests/master_loader_callbacks_test.cc
@@ -31,15 +31,13 @@ class MasterLoaderCallbacksTest : public ::testing::Test {
 protected:
     MasterLoaderCallbacksTest() :
         issue_called_(false),
-        add_called_(false),
         rrset_(new RRset(Name("example.org"), RRClass::IN(), RRType::A(),
                          RRTTL(3600))),
         error_(boost::bind(&MasterLoaderCallbacksTest::checkCallback, this,
                            true, _1, _2, _3)),
         warning_(boost::bind(&MasterLoaderCallbacksTest::checkCallback, this,
                              false, _1, _2, _3)),
-        add_(boost::bind(&MasterLoaderCallbacksTest::checkAdd, this, _1)),
-        callbacks_(error_, warning_, add_)
+        callbacks_(error_, warning_)
     {}
 
     void checkCallback(bool error, const string& source, size_t line,
@@ -51,29 +49,21 @@ protected:
         EXPECT_EQ(1, line);
         EXPECT_EQ("reason", reason);
     }
-    void checkAdd(const RRsetPtr& rrset) {
-        add_called_ = true;
-        EXPECT_EQ(rrset_, rrset);
-    }
     bool last_was_error_;
-    bool issue_called_, add_called_;
+    bool issue_called_;
     const RRsetPtr rrset_;
     const MasterLoaderCallbacks::IssueCallback error_, warning_;
-    const MasterLoaderCallbacks::AddCallback add_;
     MasterLoaderCallbacks callbacks_;
 };
 
 // Check the constructor rejects empty callbacks, but accepts non-empty ones
 TEST_F(MasterLoaderCallbacksTest, constructor) {
     EXPECT_THROW(MasterLoaderCallbacks(MasterLoaderCallbacks::IssueCallback(),
-                                       warning_, add_), isc::InvalidParameter);
+                                       warning_), isc::InvalidParameter);
     EXPECT_THROW(MasterLoaderCallbacks(error_,
-                                       MasterLoaderCallbacks::IssueCallback(),
-                                       add_), isc::InvalidParameter);
-    EXPECT_THROW(MasterLoaderCallbacks(error_, warning_,
-                                       MasterLoaderCallbacks::AddCallback()),
+                                       MasterLoaderCallbacks::IssueCallback()),
                  isc::InvalidParameter);
-    EXPECT_NO_THROW(MasterLoaderCallbacks(error_, warning_, add_));
+    EXPECT_NO_THROW(MasterLoaderCallbacks(error_, warning_));
 }
 
 // Call the issue callbacks
@@ -89,12 +79,4 @@ TEST_F(MasterLoaderCallbacksTest, issueCall) {
     EXPECT_TRUE(issue_called_);
 }
 
-// Call the add callback
-TEST_F(MasterLoaderCallbacksTest, addCall) {
-    EXPECT_FALSE(issue_called_);
-    callbacks_.addRRset(rrset_);
-    EXPECT_TRUE(add_called_);
-}
-
-
 }



More information about the bind10-changes mailing list