From: JINMEI Tatuya Date: Fri, 16 Mar 2012 21:00:11 +0000 (-0700) Subject: [1784] introduced a base interface class for DNSService for subsequent tests. X-Git-Tag: trac2351_base~226^2~116^2~100^2~5^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ce65bd4fa0bc59f262277d7bedb2a649becd1fb8;p=thirdparty%2Fkea.git [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. --- diff --git a/src/bin/auth/auth_srv.h b/src/bin/auth/auth_srv.h index 02a578dc40..382bda75b6 100644 --- a/src/bin/auth/auth_srv.h +++ b/src/bin/auth/auth_srv.h @@ -28,6 +28,7 @@ #include #include +#include #include #include #include diff --git a/src/lib/asiodns/dns_service.h b/src/lib/asiodns/dns_service.h index 9c987b8ff4..702f724408 100644 --- a/src/lib/asiodns/dns_service.h +++ b/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(); diff --git a/src/lib/server_common/portconfig.cc b/src/lib/server_common/portconfig.cc index d1e97f3604..2797bd3d4e 100644 --- a/src/lib/server_common/portconfig.cc +++ b/src/lib/server_common/portconfig.cc @@ -84,7 +84,7 @@ namespace { vector 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); diff --git a/src/lib/server_common/portconfig.h b/src/lib/server_common/portconfig.h index 0c0fa6a2de..bc36fbe1b9 100644 --- a/src/lib/server_common/portconfig.h +++ b/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: