Browse Source

[1784] introduced a base interface class for DNSService for subsequent tests.

Only some part of portconfig need to be adjusted; others will still use
the derived class directly.
JINMEI Tatuya 13 years ago
parent
commit
ce65bd4fa0

+ 1 - 0
src/bin/auth/auth_srv.h

@@ -28,6 +28,7 @@
 #include <util/buffer.h>
 
 #include <asiodns/dns_server.h>
+#include <asiodns/dns_service.h>
 #include <asiodns/dns_lookup.h>
 #include <asiodns/dns_answer.h>
 #include <asiolink/io_message.h>

+ 46 - 11
src/lib/asiodns/dns_service.h

@@ -27,14 +27,25 @@ class DNSLookup;
 class DNSAnswer;
 class DNSServiceImpl;
 
-/// \brief Handle DNS Queries
+/// \brief A base class for common \c DNSService interfaces.
 ///
-/// DNSService is the service that handles DNS queries and answers with
-/// a given IOService. This class is mainly intended to hold all the
-/// logic that is shared between the authoritative and the recursive
-/// server implementations. As such, it handles asio, including config
-/// updates (through the 'Checkinprovider'), and listening sockets.
-class DNSService {
+/// This class is defined mainly for test code so it can use a faked/mock
+/// version of a derived class and test scenarios that would involve
+/// \c DNSService without actually instantiating the real service class.
+///
+/// It doesn't intend to be a customization for other purposes - we generally
+/// expect non test code only use \c DNSService directly.
+/// For this reason most of the detailed description are given in the
+/// \c DNSService class.  See that for further details of specific methods
+/// and class behaviors.
+class DNSServiceBase {
+protected:
+    /// \brief Default constructor.
+    ///
+    /// This is protected so this class couldn't be accidentally instantiated
+    /// directly, even if there were no pure virtual functions.
+    DNSServiceBase() {}
+
 public:
     /// \brief Flags for optional server properties.
     ///
@@ -43,6 +54,10 @@ public:
     /// variants.  As we see need for more such properties, a compound
     /// form of flags (i.e., a single value generated by bitwise OR'ed
     /// multiple flag values) will be allowed.
+    ///
+    /// Note: the description is given here because it's used in the method
+    /// signature.  It essentially belongs to the derived \c DNSService
+    /// class.
     enum ServerFlag {
         SERVER_DEFAULT = 0, ///< The default flag (no particular property)
         SERVER_SYNC_OK = 1 ///< The server can act in the "synchronous" mode.
@@ -60,6 +75,26 @@ public:
                            ///< information given by the client.
     };
 
+    /// \brief The destructor.
+    virtual ~DNSServiceBase() {}
+
+    virtual void addServerTCPFromFD(int fd, int af) = 0;
+    virtual void addServerUDPFromFD(int fd, int af,
+                                    ServerFlag options = SERVER_DEFAULT) = 0;
+    virtual void clearServers() = 0;
+};
+
+/// \brief Handle DNS Queries
+///
+/// DNSService is the service that handles DNS queries and answers with
+/// a given IOService. This class is mainly intended to hold all the
+/// logic that is shared between the authoritative and the recursive
+/// server implementations. As such, it handles asio, including config
+/// updates (through the 'Checkinprovider'), and listening sockets.
+class DNSService : public DNSServiceBase {
+public:
+    using DNSServiceBase::ServerFlag;
+
     ///
     /// \name Constructors and Destructor
     ///
@@ -110,7 +145,7 @@ public:
                DNSLookup* lookup, DNSAnswer* answer);
 
     /// \brief The destructor.
-    ~DNSService();
+    virtual ~DNSService();
     //@}
 
     /// \brief Add another server to the service
@@ -137,7 +172,7 @@ public:
     /// \throw isc::InvalidParameter if af is neither AF_INET nor AF_INET6.
     /// \throw isc::asiolink::IOError when a low-level error happens, like the
     ///     fd is not a valid descriptor or it can't be listened on.
-    void addServerTCPFromFD(int fd, int af);
+    virtual void addServerTCPFromFD(int fd, int af);
 
     /// \brief Add another UDP server to the service from already opened
     ///    file descriptor
@@ -156,8 +191,8 @@ public:
     /// \throw isc::InvalidParameter if af is neither AF_INET nor AF_INET6.
     /// \throw isc::asiolink::IOError when a low-level error happens, like the
     ///     fd is not a valid descriptor or it can't be listened on.
-    void addServerUDPFromFD(int fd, int af,
-                            ServerFlag options = SERVER_DEFAULT);
+    virtual void addServerUDPFromFD(int fd, int af,
+                                    ServerFlag options = SERVER_DEFAULT);
 
     /// \brief Remove all servers from the service
     void clearServers();

+ 2 - 2
src/lib/server_common/portconfig.cc

@@ -84,7 +84,7 @@ namespace {
 vector<string> current_sockets;
 
 void
-setAddresses(DNSService& service, const AddressList& addresses) {
+setAddresses(DNSServiceBase& service, const AddressList& addresses) {
     service.clearServers();
     BOOST_FOREACH(const string& token, current_sockets) {
         socketRequestor().releaseSocket(token);
@@ -118,7 +118,7 @@ setAddresses(DNSService& service, const AddressList& addresses) {
 void
 installListenAddresses(const AddressList& newAddresses,
                        AddressList& addressStore,
-                       isc::asiodns::DNSService& service)
+                       isc::asiodns::DNSServiceBase& service)
 {
     try {
         LOG_DEBUG(logger, DBG_TRACE_BASIC, SRVCOMM_SET_LISTEN);

+ 6 - 2
src/lib/server_common/portconfig.h

@@ -27,7 +27,7 @@
  */
 namespace isc {
 namespace asiodns {
-class DNSService;
+class DNSServiceBase;
 }
 }
 
@@ -120,10 +120,14 @@ parseAddresses(isc::data::ConstElementPtr addresses,
 void
 installListenAddresses(const AddressList& newAddresses,
                        AddressList& addressStore,
-                       asiodns::DNSService& dnsService);
+                       asiodns::DNSServiceBase& dnsService);
 
 }
 }
 }
 
 #endif
+
+// Local Variables:
+// mode: c++
+// End: