Move timeMode property to manager

The current logic is to maintain the same attribute in manager and
epoch_base, the purpose of this commit is to merge this attribute
into manager for maintenance.

Also, Update the test/TestBmcEpoch.cpp file.

Tested: Built phosphor-time-manager successfully and UT passed.

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I05fea271d672bf12ecb722005023dfa6a2a980d1
diff --git a/bmc_epoch.cpp b/bmc_epoch.cpp
index 7135768..9fc3097 100644
--- a/bmc_epoch.cpp
+++ b/bmc_epoch.cpp
@@ -26,8 +26,9 @@
 namespace server = sdbusplus::xyz::openbmc_project::Time::server;
 using namespace phosphor::logging;
 
-BmcEpoch::BmcEpoch(sdbusplus::bus_t& bus, const char* objPath) :
-    EpochBase(bus, objPath)
+BmcEpoch::BmcEpoch(sdbusplus::bus_t& bus, const char* objPath,
+                   Manager& manager) :
+    EpochBase(bus, objPath, manager)
 {
     initialize();
 }
diff --git a/bmc_epoch.hpp b/bmc_epoch.hpp
index d8abe2f..10dbf7b 100644
--- a/bmc_epoch.hpp
+++ b/bmc_epoch.hpp
@@ -19,8 +19,7 @@
 class BmcEpoch : public EpochBase
 {
   public:
-    friend class TestBmcEpoch;
-    BmcEpoch(sdbusplus::bus_t& bus, const char* objPath);
+    BmcEpoch(sdbusplus::bus_t& bus, const char* objPath, Manager& manager);
     ~BmcEpoch();
 
     /**
diff --git a/epoch_base.cpp b/epoch_base.cpp
index 17be2c6..1761bea 100644
--- a/epoch_base.cpp
+++ b/epoch_base.cpp
@@ -24,13 +24,15 @@
 using namespace phosphor::logging;
 using FailedError = sdbusplus::xyz::openbmc_project::Time::Error::Failed;
 
-EpochBase::EpochBase(sdbusplus::bus_t& bus, const char* objPath) :
-    sdbusplus::server::object_t<EpochTime>(bus, objPath), bus(bus)
+EpochBase::EpochBase(sdbusplus::bus_t& bus, const char* objPath,
+                     Manager& manager) :
+    sdbusplus::server::object_t<EpochTime>(bus, objPath),
+    bus(bus), manager(manager)
 {}
 
 void EpochBase::onModeChanged(Mode mode)
 {
-    timeMode = mode;
+    manager.setTimeMode(mode);
 }
 
 using namespace std::chrono;
diff --git a/epoch_base.hpp b/epoch_base.hpp
index e80aa09..9c2a9e0 100644
--- a/epoch_base.hpp
+++ b/epoch_base.hpp
@@ -2,6 +2,7 @@
 
 #include "config.h"
 
+#include "manager.hpp"
 #include "property_change_listener.hpp"
 
 #include <sdbusplus/bus.hpp>
@@ -25,7 +26,7 @@
     public PropertyChangeListner
 {
   public:
-    EpochBase(sdbusplus::bus_t& bus, const char* objPath);
+    EpochBase(sdbusplus::bus_t& bus, const char* objPath, Manager& manager);
 
     /** @brief Notified on time mode changed */
     void onModeChanged(Mode mode) override;
@@ -34,8 +35,8 @@
     /** @brief Persistent sdbusplus DBus connection */
     sdbusplus::bus_t& bus;
 
-    /** @brief The current time mode */
-    Mode timeMode = DEFAULT_TIME_MODE;
+    /** @brief The manager to handle OpenBMC time */
+    Manager& manager;
 
     /** @brief Set current time to system
      *
diff --git a/main.cpp b/main.cpp
index b2d1d8a..82111b6 100644
--- a/main.cpp
+++ b/main.cpp
@@ -24,8 +24,8 @@
     // Add sdbusplus ObjectManager
     sdbusplus::server::manager_t bmcEpochObjManager(bus, OBJPATH_BMC);
 
-    phosphor::time::BmcEpoch bmc(bus, OBJPATH_BMC);
     phosphor::time::Manager manager(bus);
+    phosphor::time::BmcEpoch bmc(bus, OBJPATH_BMC, manager);
 
     bus.request_name(BUSNAME);
 
diff --git a/manager.hpp b/manager.hpp
index 03229fb..02dd253 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -34,6 +34,16 @@
     Manager& operator=(Manager&&) = delete;
     ~Manager() = default;
 
+    void setTimeMode(Mode mode)
+    {
+        this->timeMode = mode;
+    }
+
+    Mode getTimeMode()
+    {
+        return this->timeMode;
+    }
+
   private:
     /** @brief Persistent sdbusplus DBus connection */
     sdbusplus::bus_t& bus;
diff --git a/test/TestBmcEpoch.cpp b/test/TestBmcEpoch.cpp
index 0f4dbea..aee19f9 100644
--- a/test/TestBmcEpoch.cpp
+++ b/test/TestBmcEpoch.cpp
@@ -1,6 +1,7 @@
 #include "config.h"
 
 #include "bmc_epoch.hpp"
+#include "manager.hpp"
 #include "types.hpp"
 
 #include <sdbusplus/bus.hpp>
@@ -16,15 +17,16 @@
 {
   public:
     sdbusplus::bus_t bus;
+    Manager manager;
     sd_event* event;
     std::unique_ptr<BmcEpoch> bmcEpoch;
 
-    TestBmcEpoch() : bus(sdbusplus::bus::new_default())
+    TestBmcEpoch() : bus(sdbusplus::bus::new_default()), manager(bus)
     {
         // BmcEpoch requires sd_event to init
         sd_event_default(&event);
         bus.attach_event(event, SD_EVENT_PRIORITY_NORMAL);
-        bmcEpoch = std::make_unique<BmcEpoch>(bus, OBJPATH_BMC);
+        bmcEpoch = std::make_unique<BmcEpoch>(bus, OBJPATH_BMC, manager);
     }
 
     ~TestBmcEpoch()
@@ -32,31 +34,21 @@
         bus.detach_event();
         sd_event_unref(event);
     }
-
-    // Proxies for BmcEpoch's private members and functions
-    Mode getTimeMode()
-    {
-        return bmcEpoch->timeMode;
-    }
-    void setTimeMode(Mode mode)
-    {
-        bmcEpoch->timeMode = mode;
-    }
 };
 
 TEST_F(TestBmcEpoch, onModeChange)
 {
     bmcEpoch->onModeChanged(Mode::NTP);
-    EXPECT_EQ(Mode::NTP, getTimeMode());
+    EXPECT_EQ(Mode::NTP, manager.getTimeMode());
 
     bmcEpoch->onModeChanged(Mode::Manual);
-    EXPECT_EQ(Mode::Manual, getTimeMode());
+    EXPECT_EQ(Mode::Manual, manager.getTimeMode());
 }
 
 TEST_F(TestBmcEpoch, empty)
 {
     // Default mode is MANUAL
-    EXPECT_EQ(Mode::Manual, getTimeMode());
+    EXPECT_EQ(Mode::Manual, manager.getTimeMode());
 }
 
 TEST_F(TestBmcEpoch, getElapsed)
diff --git a/test/TestManager.cpp b/test/TestManager.cpp
index 2f5990c..f64b3a0 100644
--- a/test/TestManager.cpp
+++ b/test/TestManager.cpp
@@ -22,11 +22,6 @@
     TestManager() : bus(sdbusplus::bus::new_default()), manager(bus)
     {}
 
-    // Proxies for Manager's private members and functions
-    Mode getTimeMode()
-    {
-        return manager.timeMode;
-    }
     void notifyPropertyChanged(const std::string& key, const std::string& value)
     {
         manager.onPropertyChanged(key, value);
@@ -38,12 +33,12 @@
     notifyPropertyChanged(
         "TimeSyncMethod",
         "xyz.openbmc_project.Time.Synchronization.Method.Manual");
-    EXPECT_EQ(Mode::Manual, getTimeMode());
+    EXPECT_EQ(Mode::Manual, manager.getTimeMode());
 
     notifyPropertyChanged(
         "TimeSyncMethod",
         "xyz.openbmc_project.Time.Synchronization.Method.NTP");
-    EXPECT_EQ(Mode::NTP, getTimeMode());
+    EXPECT_EQ(Mode::NTP, manager.getTimeMode());
 
     ASSERT_DEATH(notifyPropertyChanged("invalid property", "whatever"), "");
 }