From: Francis Dupont Date: Fri, 22 May 2015 06:29:03 +0000 (+0200) Subject: [3859] redeclare and redefine the getVersion() X-Git-Tag: trac3882_base X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6cb3d5c748d684bb060ef899ae91f360de1bb30f;p=thirdparty%2Fkea.git [3859] redeclare and redefine the getVersion() --- diff --git a/src/bin/d2/d_controller.cc b/src/bin/d2/d_controller.cc index 7711c8dea1..2295e09063 100644 --- a/src/bin/d2/d_controller.cc +++ b/src/bin/d2/d_controller.cc @@ -447,19 +447,15 @@ DControllerBase::~DControllerBase() { // Refer to config_report so it will be embedded in the binary const char* const* d2_config_report = isc::detail::config_report; -}; // namespace isc::d2 - -}; // namespace isc - std::string -isc::dhcp::Daemon::getVersion(bool extended) { +DControllerBase::getVersion(bool extended) { std::stringstream tmp; tmp << VERSION; if (extended) { tmp << std::endl << EXTENDED_VERSION << std::endl; - tmp << "linked with " << isc::log::Logger::getVersion() << std::endl; - tmp << "and " << isc::cryptolink::CryptoLink::getVersion() + tmp << "linked with " << log::Logger::getVersion() << std::endl; + tmp << "and " << cryptolink::CryptoLink::getVersion() << std::endl; #ifdef HAVE_MYSQL tmp << "database: MySQL"; @@ -475,3 +471,7 @@ isc::dhcp::Daemon::getVersion(bool extended) { return (tmp.str()); } + +}; // namespace isc::d2 + +}; // namespace isc diff --git a/src/bin/d2/d_controller.h b/src/bin/d2/d_controller.h index 6d1c4fc187..7f730480db 100644 --- a/src/bin/d2/d_controller.h +++ b/src/bin/d2/d_controller.h @@ -113,6 +113,10 @@ public: /// @brief Destructor virtual ~DControllerBase(); + /// @brief returns Kea version on stdout and exit. + /// redeclaration/redefinition. @ref Daemon::getVersion()) + static std::string getVersion(bool extended); + /// @brief Acts as the primary entry point into the controller execution /// and provides the outermost application control logic: /// diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc index 8190388d39..c39e1cd5a7 100644 --- a/src/bin/dhcp4/dhcp4_srv.cc +++ b/src/bin/dhcp4/dhcp4_srv.cc @@ -2215,7 +2215,7 @@ Dhcpv4Srv::d2ClientErrorHandler(const const char* const* dhcp4_config_report = isc::detail::config_report; std::string -Daemon::getVersion(bool extended) { +Dhcpv4Srv::getVersion(bool extended) { std::stringstream tmp; tmp << VERSION; diff --git a/src/bin/dhcp4/dhcp4_srv.h b/src/bin/dhcp4/dhcp4_srv.h index 6a05a245a7..6b70c1c29f 100644 --- a/src/bin/dhcp4/dhcp4_srv.h +++ b/src/bin/dhcp4/dhcp4_srv.h @@ -186,6 +186,10 @@ public: /// @brief Destructor. Used during DHCPv4 service shutdown. virtual ~Dhcpv4Srv(); + /// @brief returns Kea version on stdout and exit. + /// redeclaration/redefinition. @ref Daemon::getVersion()) + static std::string getVersion(bool extended); + /// @brief Main server processing loop. /// /// Main server processing loop. Receives incoming packets, verifies diff --git a/src/bin/dhcp4/main.cc b/src/bin/dhcp4/main.cc index bf6ce7b890..efaa4de26b 100644 --- a/src/bin/dhcp4/main.cc +++ b/src/bin/dhcp4/main.cc @@ -76,11 +76,11 @@ main(int argc, char* argv[]) { break; case 'v': - cout << Daemon::getVersion(false) << endl; + cout << Dhcpv4Srv::getVersion(false) << endl; return (EXIT_SUCCESS); case 'V': - cout << Daemon::getVersion(true) << endl; + cout << Dhcpv4Srv::getVersion(true) << endl; return (EXIT_SUCCESS); case 'p': diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc index ad47fb2e56..43ea0014fe 100644 --- a/src/bin/dhcp6/dhcp6_srv.cc +++ b/src/bin/dhcp6/dhcp6_srv.cc @@ -2762,7 +2762,7 @@ Dhcpv6Srv::d2ClientErrorHandler(const const char* const* dhcp6_config_report = isc::detail::config_report; std::string -Daemon::getVersion(bool extended) { +Dhcpv6Srv::getVersion(bool extended) { std::stringstream tmp; tmp << VERSION; diff --git a/src/bin/dhcp6/dhcp6_srv.h b/src/bin/dhcp6/dhcp6_srv.h index 0099b7ea86..384d1a92e7 100644 --- a/src/bin/dhcp6/dhcp6_srv.h +++ b/src/bin/dhcp6/dhcp6_srv.h @@ -77,6 +77,10 @@ public: /// @brief Destructor. Used during DHCPv6 service shutdown. virtual ~Dhcpv6Srv(); + /// @brief returns Kea version on stdout and exit. + /// redeclaration/redefinition. @ref Daemon::getVersion()) + static std::string getVersion(bool extended); + /// @brief Returns server-indentifier option. /// /// @return server-id option diff --git a/src/bin/dhcp6/main.cc b/src/bin/dhcp6/main.cc index 9c74921f9a..902c3a65d3 100644 --- a/src/bin/dhcp6/main.cc +++ b/src/bin/dhcp6/main.cc @@ -78,11 +78,11 @@ main(int argc, char* argv[]) { break; case 'v': - cout << Daemon::getVersion(false) << endl; + cout << Dhcpv6Srv::getVersion(false) << endl; return (EXIT_SUCCESS); case 'V': - cout << Daemon::getVersion(true) << endl; + cout << Dhcpv6Srv::getVersion(true) << endl; return (EXIT_SUCCESS); case 'p': // port number diff --git a/src/lib/dhcpsrv/daemon.cc b/src/lib/dhcpsrv/daemon.cc index b6ab33b51f..2733b926cd 100644 --- a/src/lib/dhcpsrv/daemon.cc +++ b/src/lib/dhcpsrv/daemon.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2014, 2015 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 @@ -92,5 +92,9 @@ void Daemon::loggerInit(const char* name, bool verbose) { isc::log::setDefaultLoggingOutput(verbose); } +std::string Daemon::getVersion(bool /*extended*/) { + isc_throw(isc::NotImplemented, "Daemon::getVersion() called"); +} + }; }; diff --git a/src/lib/dhcpsrv/daemon.h b/src/lib/dhcpsrv/daemon.h index 8009a796af..7766472053 100644 --- a/src/lib/dhcpsrv/daemon.h +++ b/src/lib/dhcpsrv/daemon.h @@ -153,6 +153,10 @@ public: /// also additional information about sources. It is expected to /// return extra information about dependencies and used DB backends. /// + /// As there is no static virtual methods in C++ this class method + /// has to be redefined in derived classes and called with the + /// derived class name or a child name. + /// /// @param extended print additional information? /// @return text string static std::string getVersion(bool extended); diff --git a/src/lib/dhcpsrv/tests/daemon_unittest.cc b/src/lib/dhcpsrv/tests/daemon_unittest.cc index 059f7940a0..f9e6ccba32 100644 --- a/src/lib/dhcpsrv/tests/daemon_unittest.cc +++ b/src/lib/dhcpsrv/tests/daemon_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2014, 2015 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 @@ -27,7 +27,16 @@ using namespace isc; using namespace isc::dhcp; using namespace isc::data; -std::string isc::dhcp::Daemon::getVersion(bool extended) { +namespace isc { +namespace dhcp { + +// @brief Derived Daemon class +class DaemonImpl : public Daemon { +public: + static std::string getVersion(bool extended); +}; + +std::string DaemonImpl::getVersion(bool extended) { if (extended) { return (std::string("EXTENDED")); } else { @@ -35,6 +44,9 @@ std::string isc::dhcp::Daemon::getVersion(bool extended) { } } +}; +}; + namespace { /// @brief Daemon Test test fixture class @@ -105,6 +117,15 @@ TEST_F(DaemonTest, parsingConsoleOutput) { EXPECT_EQ("stdout" , storage->getLoggingInfo()[0].destinations_[0].output_); } +// Test the getVersion() redefinition +TEST_F(DaemonTest, getVersion) { + EXPECT_THROW(Daemon::getVersion(false), NotImplemented); + + ASSERT_NO_THROW(DaemonImpl::getVersion(false)); + + EXPECT_EQ(DaemonImpl::getVersion(true), "EXTENDED"); +} + // More tests will appear here as we develop Daemon class.