Browse Source

[master] Merged trac3859 (getVersion() defined outside its module)

Francis Dupont 10 years ago
parent
commit
384e6c6225

+ 1 - 0
ChangeLog

@@ -6,6 +6,7 @@
 	"-W" provides the configure report from the configuration step
 	during the build of Kea.
 	(Trac #3513, git 584cf666e101c6cb5c9af76175ddd867ece85764)
+	(Trac #3859, git xxx)
 
 953.	[bug]		fdupont
 	Corrected the setting of string characters to values above 127

+ 11 - 11
src/bin/d2/d_controller.cc

@@ -454,12 +454,8 @@ 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;
@@ -468,17 +464,21 @@ isc::dhcp::Daemon::getVersion(bool extended) {
         tmp << "linked with:" << std::endl;
         tmp << isc::log::Logger::getVersion() << std::endl;
         tmp << isc::cryptolink::CryptoLink::getVersion() << std::endl;
+        tmp << "database:" << std::endl; 
 #ifdef HAVE_MYSQL
-        tmp << "database: MySQL";
-#else
-#ifdef HAVE_PGSQL
-        tmp << "database: PostgreSQL";
-#else
-        tmp << "no database";
+        tmp << "MySQL backend" << std::endl;
 #endif
+#ifdef HAVE_PGSQL
+        tmp << "PostgreSQL backend" << std::endl;
 #endif
+        tmp << "Memfile backend";
+
         // @todo: more details about database runtime
     }
 
     return (tmp.str());
 }
+
+}; // namespace isc::d2
+
+}; // namespace isc

+ 4 - 0
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:
     ///

+ 1 - 1
src/bin/dhcp4/dhcp4_srv.cc

@@ -2255,7 +2255,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;

+ 4 - 0
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

+ 2 - 2
src/bin/dhcp4/main.cc

@@ -78,11 +78,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 'W':

+ 1 - 1
src/bin/dhcp6/dhcp6_srv.cc

@@ -2837,7 +2837,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;

+ 5 - 1
src/bin/dhcp6/dhcp6_srv.h

@@ -77,7 +77,11 @@ public:
     /// @brief Destructor. Used during DHCPv6 service shutdown.
     virtual ~Dhcpv6Srv();
 
-    /// @brief Returns server-identifier option.
+    /// @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
     OptionPtr getServerID() { return serverid_; }

+ 2 - 2
src/bin/dhcp6/main.cc

@@ -80,11 +80,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 'W':

+ 5 - 1
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");
+}
+
 };
 };

+ 4 - 0
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);

+ 27 - 2
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,19 @@ 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(false), "BASIC");
+
+    ASSERT_NO_THROW(DaemonImpl::getVersion(true));
+
+    EXPECT_EQ(DaemonImpl::getVersion(true), "EXTENDED");
+}
+
 
 // More tests will appear here as we develop Daemon class.