clang-format: Update to match docs repo
Update the .clang-format file and run clang-format-6.0.
This .clang-format matches the example one in
https://github.com/openbmc/docs/blob/master/cpp-style-and-conventions.md#clang-formatting
Change-Id: Ic2c462525eb27b8295c2b298871e04268d93faf2
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..8c5278e
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,98 @@
+---
+Language: Cpp
+# BasedOnStyle: LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: true
+ AfterEnum: true
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: true
+ AfterStruct: true
+ AfterUnion: true
+ BeforeCatch: true
+ BeforeElse: true
+ IndentBraces: false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: AfterColon
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IncludeBlocks: Regroup
+IncludeCategories:
+ - Regex: '^[<"](gtest|gmock)'
+ Priority: 5
+ - Regex: '^"config.h"'
+ Priority: -1
+ - Regex: '^".*\.hpp"'
+ Priority: 1
+ - Regex: '^<.*\.h>'
+ Priority: 2
+ - Regex: '^<.*'
+ Priority: 3
+ - Regex: '.*'
+ Priority: 4
+IndentCaseLabels: true
+IndentWidth: 4
+IndentWrappedFunctionNames: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerAlignment: Left
+ReflowComments: true
+SortIncludes: true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: Cpp11
+TabWidth: 4
+UseTab: Never
+...
diff --git a/bmc_epoch.cpp b/bmc_epoch.cpp
index 8c251ee..d000a71 100644
--- a/bmc_epoch.cpp
+++ b/bmc_epoch.cpp
@@ -1,15 +1,15 @@
#include "bmc_epoch.hpp"
-#include "utils.hpp"
-#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
-#include <xyz/openbmc_project/Common/error.hpp>
-#include <xyz/openbmc_project/Time/error.hpp>
+#include "utils.hpp"
#include <sys/timerfd.h>
#include <unistd.h>
+#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/log.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
+#include <xyz/openbmc_project/Time/error.hpp>
// Need to do this since its not exported outside of the kernel.
// Refer : https://gist.github.com/lethean/446cea944b7441228298
@@ -30,54 +30,47 @@
using NotAllowedError =
sdbusplus::xyz::openbmc_project::Time::Error::NotAllowed;
-BmcEpoch::BmcEpoch(sdbusplus::bus::bus& bus,
- const char* objPath)
- : EpochBase(bus, objPath),
- bus(bus)
+BmcEpoch::BmcEpoch(sdbusplus::bus::bus& bus, const char* objPath) :
+ EpochBase(bus, objPath), bus(bus)
{
initialize();
}
void BmcEpoch::initialize()
{
- using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
- Error::InternalFailure;
+ using InternalFailure =
+ sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
// Subscribe time change event
// Choose the MAX time that is possible to avoid mis fires.
constexpr itimerspec maxTime = {
- {0, 0}, // it_interval
- {TIME_T_MAX, 0}, //it_value
+ {0, 0}, // it_interval
+ {TIME_T_MAX, 0}, // it_value
};
timeFd = timerfd_create(CLOCK_REALTIME, 0);
if (timeFd == -1)
{
- log<level::ERR>("Failed to create timerfd",
- entry("ERRNO=%d", errno),
+ log<level::ERR>("Failed to create timerfd", entry("ERRNO=%d", errno),
entry("ERR=%s", strerror(errno)));
elog<InternalFailure>();
}
- auto r = timerfd_settime(timeFd,
- TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET,
- &maxTime,
- nullptr);
+ auto r = timerfd_settime(
+ timeFd, TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET, &maxTime, nullptr);
if (r != 0)
{
- log<level::ERR>("Failed to set timerfd",
- entry("ERRNO=%d", errno),
+ log<level::ERR>("Failed to set timerfd", entry("ERRNO=%d", errno),
entry("ERR=%s", strerror(errno)));
elog<InternalFailure>();
}
sd_event_source* es;
- r = sd_event_add_io(bus.get_event(), &es,
- timeFd, EPOLLIN, onTimeChange, this);
+ r = sd_event_add_io(bus.get_event(), &es, timeFd, EPOLLIN, onTimeChange,
+ this);
if (r < 0)
{
- log<level::ERR>("Failed to add event",
- entry("ERRNO=%d", -r),
+ log<level::ERR>("Failed to add event", entry("ERRNO=%d", -r),
entry("ERR=%s", strerror(-r)));
elog<InternalFailure>();
}
@@ -143,16 +136,17 @@
}
}
-int BmcEpoch::onTimeChange(sd_event_source* es, int fd,
- uint32_t /* revents */, void* userdata)
+int BmcEpoch::onTimeChange(sd_event_source* es, int fd, uint32_t /* revents */,
+ void* userdata)
{
auto bmcEpoch = static_cast<BmcEpoch*>(userdata);
- std::array<char, 64> time {};
+ std::array<char, 64> time{};
// We are not interested in the data here.
// So read until there is no new data here in the FD
- while (read(fd, time.data(), time.max_size()) > 0);
+ while (read(fd, time.data(), time.max_size()) > 0)
+ ;
log<level::INFO>("BMC system time is changed");
bmcEpoch->notifyBmcTimeChange(bmcEpoch->getTime());
@@ -162,4 +156,3 @@
} // namespace time
} // namespace phosphor
-
diff --git a/bmc_epoch.hpp b/bmc_epoch.hpp
index 228a39d..96c14b7 100644
--- a/bmc_epoch.hpp
+++ b/bmc_epoch.hpp
@@ -19,75 +19,74 @@
*/
class BmcEpoch : public EpochBase
{
- public:
- friend class TestBmcEpoch;
- BmcEpoch(sdbusplus::bus::bus& bus,
- const char* objPath);
- ~BmcEpoch();
+ public:
+ friend class TestBmcEpoch;
+ BmcEpoch(sdbusplus::bus::bus& bus, const char* objPath);
+ ~BmcEpoch();
- /**
- * @brief Get value of Elapsed property
- *
- * @return The elapsed microseconds since UTC
- **/
- uint64_t elapsed() const override;
+ /**
+ * @brief Get value of Elapsed property
+ *
+ * @return The elapsed microseconds since UTC
+ **/
+ uint64_t elapsed() const override;
- /**
- * @brief Set value of Elapsed property
- *
- * @param[in] value - The microseconds since UTC to set
- * @return The updated elapsed microseconds since UTC
- **/
- uint64_t elapsed(uint64_t value) override;
+ /**
+ * @brief Set value of Elapsed property
+ *
+ * @param[in] value - The microseconds since UTC to set
+ * @return The updated elapsed microseconds since UTC
+ **/
+ uint64_t elapsed(uint64_t value) override;
- /** @brief Set the listner for bmc time change
- *
- * @param[in] listener - The pointer to the listener
- */
- void setBmcTimeChangeListener(BmcTimeChangeListener* listener);
+ /** @brief Set the listner for bmc time change
+ *
+ * @param[in] listener - The pointer to the listener
+ */
+ void setBmcTimeChangeListener(BmcTimeChangeListener* listener);
- private:
- /** @brief The fd for time change event */
- int timeFd = -1;
+ private:
+ /** @brief The fd for time change event */
+ int timeFd = -1;
- /** @brief Initialize timerFd related resource */
- void initialize();
+ /** @brief Initialize timerFd related resource */
+ void initialize();
- /** @brief Notify the listeners that bmc time is changed
- *
- * @param[in] time - The epoch time in microseconds to notify
- */
- void notifyBmcTimeChange(const microseconds& time);
+ /** @brief Notify the listeners that bmc time is changed
+ *
+ * @param[in] time - The epoch time in microseconds to notify
+ */
+ void notifyBmcTimeChange(const microseconds& time);
- /** @brief The callback function on system time change
- *
- * @param[in] es - Source of the event
- * @param[in] fd - File descriptor of the timer
- * @param[in] revents - Not used
- * @param[in] userdata - User data pointer
- */
- static int onTimeChange(sd_event_source* es, int fd,
- uint32_t revents, void* userdata);
+ /** @brief The callback function on system time change
+ *
+ * @param[in] es - Source of the event
+ * @param[in] fd - File descriptor of the timer
+ * @param[in] revents - Not used
+ * @param[in] userdata - User data pointer
+ */
+ static int onTimeChange(sd_event_source* es, int fd, uint32_t revents,
+ void* userdata);
- /** @brief The reference of sdbusplus bus */
- sdbusplus::bus::bus& bus;
+ /** @brief The reference of sdbusplus bus */
+ sdbusplus::bus::bus& bus;
- /** @brief The deleter of sd_event_source */
- std::function<void(sd_event_source*)> sdEventSourceDeleter =
- [] (sd_event_source* p) {
- if (p)
- {
- sd_event_source_unref(p);
- }
- };
- using SdEventSource = std::unique_ptr<sd_event_source,
- decltype(sdEventSourceDeleter)>;
+ /** @brief The deleter of sd_event_source */
+ std::function<void(sd_event_source*)> sdEventSourceDeleter =
+ [](sd_event_source* p) {
+ if (p)
+ {
+ sd_event_source_unref(p);
+ }
+ };
+ using SdEventSource =
+ std::unique_ptr<sd_event_source, decltype(sdEventSourceDeleter)>;
- /** @brief The event source on system time change */
- SdEventSource timeChangeEventSource {nullptr, sdEventSourceDeleter};
+ /** @brief The event source on system time change */
+ SdEventSource timeChangeEventSource{nullptr, sdEventSourceDeleter};
- /** @brief The listener for bmc time change */
- BmcTimeChangeListener* timeChangeListener = nullptr;
+ /** @brief The listener for bmc time change */
+ BmcTimeChangeListener* timeChangeListener = nullptr;
};
} // namespace time
diff --git a/bmc_time_change_listener.hpp b/bmc_time_change_listener.hpp
index 44fc479..2c382f6 100644
--- a/bmc_time_change_listener.hpp
+++ b/bmc_time_change_listener.hpp
@@ -9,16 +9,15 @@
class BmcTimeChangeListener
{
- public:
- virtual ~BmcTimeChangeListener() = default;
+ public:
+ virtual ~BmcTimeChangeListener() = default;
- /** @brief Notified on bmc time is changed
- *
- * @param[in] bmcTime - The epoch time in microseconds
- */
- virtual void onBmcTimeChanged(
- const std::chrono::microseconds& bmcTime) = 0;
+ /** @brief Notified on bmc time is changed
+ *
+ * @param[in] bmcTime - The epoch time in microseconds
+ */
+ virtual void onBmcTimeChanged(const std::chrono::microseconds& bmcTime) = 0;
};
-}
-}
+} // namespace time
+} // namespace phosphor
diff --git a/epoch_base.cpp b/epoch_base.cpp
index 8aa41dd..9346391 100644
--- a/epoch_base.cpp
+++ b/epoch_base.cpp
@@ -1,12 +1,11 @@
#include "epoch_base.hpp"
-#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
-#include <xyz/openbmc_project/Time/error.hpp>
-
#include <iomanip>
+#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/log.hpp>
#include <sstream>
+#include <xyz/openbmc_project/Time/error.hpp>
namespace // anonymous
{
@@ -14,7 +13,7 @@
constexpr auto SYSTEMD_TIME_PATH = "/org/freedesktop/timedate1";
constexpr auto SYSTEMD_TIME_INTERFACE = "org.freedesktop.timedate1";
constexpr auto METHOD_SET_TIME = "SetTime";
-}
+} // namespace
namespace phosphor
{
@@ -22,13 +21,10 @@
{
using namespace phosphor::logging;
-using FailedError =
- sdbusplus::xyz::openbmc_project::Time::Error::Failed;
+using FailedError = sdbusplus::xyz::openbmc_project::Time::Error::Failed;
-EpochBase::EpochBase(sdbusplus::bus::bus& bus,
- const char* objPath)
- : sdbusplus::server::object::object<EpochTime>(bus, objPath),
- bus(bus)
+EpochBase::EpochBase(sdbusplus::bus::bus& bus, const char* objPath) :
+ sdbusplus::server::object::object<EpochTime>(bus, objPath), bus(bus)
{
}
@@ -45,12 +41,10 @@
using namespace std::chrono;
bool EpochBase::setTime(const microseconds& usec)
{
- auto method = bus.new_method_call(SYSTEMD_TIME_SERVICE,
- SYSTEMD_TIME_PATH,
- SYSTEMD_TIME_INTERFACE,
- METHOD_SET_TIME);
+ auto method = bus.new_method_call(SYSTEMD_TIME_SERVICE, SYSTEMD_TIME_PATH,
+ SYSTEMD_TIME_INTERFACE, METHOD_SET_TIME);
method.append(static_cast<int64_t>(usec.count()),
- false, // relative
+ false, // relative
false); // user_interaction
try
@@ -61,8 +55,7 @@
{
log<level::ERR>("Error in setting system time");
using namespace xyz::openbmc_project::Time;
- elog<FailedError>(
- Failed::REASON(ex.what()));
+ elog<FailedError>(Failed::REASON(ex.what()));
}
return true;
}
@@ -70,8 +63,7 @@
microseconds EpochBase::getTime() const
{
auto now = system_clock::now();
- return duration_cast<microseconds>
- (now.time_since_epoch());
+ return duration_cast<microseconds>(now.time_since_epoch());
}
} // namespace time
diff --git a/epoch_base.hpp b/epoch_base.hpp
index 79aca90..80fa3f4 100644
--- a/epoch_base.hpp
+++ b/epoch_base.hpp
@@ -1,13 +1,13 @@
#pragma once
#include "config.h"
+
#include "property_change_listener.hpp"
+#include <chrono>
#include <sdbusplus/bus.hpp>
#include <xyz/openbmc_project/Time/EpochTime/server.hpp>
-#include <chrono>
-
namespace phosphor
{
namespace time
@@ -18,48 +18,47 @@
* @details A base class that implements xyz.openbmc_project.Time.EpochTime
* DBus API for epoch time.
*/
-class EpochBase : public sdbusplus::server::object::object <
- sdbusplus::xyz::openbmc_project::Time::server::EpochTime >,
- public PropertyChangeListner
+class EpochBase : public sdbusplus::server::object::object<
+ sdbusplus::xyz::openbmc_project::Time::server::EpochTime>,
+ public PropertyChangeListner
{
- public:
- friend class TestEpochBase;
+ public:
+ friend class TestEpochBase;
- EpochBase(sdbusplus::bus::bus& bus,
- const char* objPath);
+ EpochBase(sdbusplus::bus::bus& bus, const char* objPath);
- /** @brief Notified on time mode changed */
- void onModeChanged(Mode mode) override;
+ /** @brief Notified on time mode changed */
+ void onModeChanged(Mode mode) override;
- /** @brief Notified on time owner changed */
- void onOwnerChanged(Owner owner) override;
+ /** @brief Notified on time owner changed */
+ void onOwnerChanged(Owner owner) override;
- protected:
- /** @brief Persistent sdbusplus DBus connection */
- sdbusplus::bus::bus& bus;
+ protected:
+ /** @brief Persistent sdbusplus DBus connection */
+ sdbusplus::bus::bus& bus;
- /** @brief The current time mode */
- Mode timeMode = DEFAULT_TIME_MODE;
+ /** @brief The current time mode */
+ Mode timeMode = DEFAULT_TIME_MODE;
- /** @brief The current time owner */
- Owner timeOwner = DEFAULT_TIME_OWNER;
+ /** @brief The current time owner */
+ Owner timeOwner = DEFAULT_TIME_OWNER;
- /** @brief Set current time to system
- *
- * This function set the time to system by invoking systemd
- * org.freedesktop.timedate1's SetTime method.
- *
- * @param[in] timeOfDayUsec - Microseconds since UTC
- *
- * @return true or false to indicate if it sets time successfully
- */
- bool setTime(const std::chrono::microseconds& timeOfDayUsec);
+ /** @brief Set current time to system
+ *
+ * This function set the time to system by invoking systemd
+ * org.freedesktop.timedate1's SetTime method.
+ *
+ * @param[in] timeOfDayUsec - Microseconds since UTC
+ *
+ * @return true or false to indicate if it sets time successfully
+ */
+ bool setTime(const std::chrono::microseconds& timeOfDayUsec);
- /** @brief Get current time
- *
- * @return Microseconds since UTC
- */
- std::chrono::microseconds getTime() const;
+ /** @brief Get current time
+ *
+ * @return Microseconds since UTC
+ */
+ std::chrono::microseconds getTime() const;
};
} // namespace time
diff --git a/host_epoch.cpp b/host_epoch.cpp
index c3e6400..96cbfa9 100644
--- a/host_epoch.cpp
+++ b/host_epoch.cpp
@@ -1,4 +1,5 @@
#include "host_epoch.hpp"
+
#include "utils.hpp"
#include <phosphor-logging/elog-errors.hpp>
@@ -16,14 +17,13 @@
using NotAllowedError =
sdbusplus::xyz::openbmc_project::Time::Error::NotAllowed;
-HostEpoch::HostEpoch(sdbusplus::bus::bus& bus,
- const char* objPath)
- : EpochBase(bus, objPath),
- offset(utils::readData<decltype(offset)::rep>(offsetFile))
+HostEpoch::HostEpoch(sdbusplus::bus::bus& bus, const char* objPath) :
+ EpochBase(bus, objPath),
+ offset(utils::readData<decltype(offset)::rep>(offsetFile))
{
// Initialize the diffToSteadyClock
- auto steadyTime = duration_cast<microseconds>(
- steady_clock::now().time_since_epoch());
+ auto steadyTime =
+ duration_cast<microseconds>(steady_clock::now().time_since_epoch());
diffToSteadyClock = getTime() + offset - steadyTime;
}
@@ -52,8 +52,8 @@
MANUAL| BOTH | OK, and set time to BMC
*/
if (timeOwner == Owner::BMC ||
- (timeMode == Mode::NTP
- && (timeOwner == Owner::Host || timeOwner == Owner::Both)))
+ (timeMode == Mode::NTP &&
+ (timeOwner == Owner::Host || timeOwner == Owner::Both)))
{
using namespace xyz::openbmc_project::Time;
elog<NotAllowedError>(
@@ -70,8 +70,8 @@
saveOffset();
// Calculate the diff between host and steady time
- auto steadyTime = duration_cast<microseconds>(
- steady_clock::now().time_since_epoch());
+ auto steadyTime =
+ duration_cast<microseconds>(steady_clock::now().time_since_epoch());
diffToSteadyClock = time - steadyTime;
}
else
@@ -98,8 +98,8 @@
{
// In SPLIT, need to re-calculate the diff between
// host and steady time
- auto steadyTime = duration_cast<microseconds>(
- steady_clock::now().time_since_epoch());
+ auto steadyTime =
+ duration_cast<microseconds>(steady_clock::now().time_since_epoch());
diffToSteadyClock = getTime() - steadyTime;
}
}
@@ -116,8 +116,8 @@
// the offset shall be adjusted
if (timeOwner == Owner::Split)
{
- auto steadyTime = duration_cast<microseconds>(
- steady_clock::now().time_since_epoch());
+ auto steadyTime =
+ duration_cast<microseconds>(steady_clock::now().time_since_epoch());
auto hostTime = steadyTime + diffToSteadyClock;
offset = hostTime - bmcTime;
@@ -127,4 +127,3 @@
} // namespace time
} // namespace phosphor
-
diff --git a/host_epoch.hpp b/host_epoch.hpp
index 1eb3167..bbf9d22 100644
--- a/host_epoch.hpp
+++ b/host_epoch.hpp
@@ -1,7 +1,8 @@
#pragma once
-#include "bmc_time_change_listener.hpp"
#include "config.h"
+
+#include "bmc_time_change_listener.hpp"
#include "epoch_base.hpp"
#include <chrono>
@@ -18,56 +19,54 @@
*/
class HostEpoch : public EpochBase, public BmcTimeChangeListener
{
- public:
- friend class TestHostEpoch;
- HostEpoch(sdbusplus::bus::bus& bus,
- const char* objPath);
+ public:
+ friend class TestHostEpoch;
+ HostEpoch(sdbusplus::bus::bus& bus, const char* objPath);
- /**
- * @brief Get value of Elapsed property
- *
- * @return The elapsed microseconds since UTC
- **/
- uint64_t elapsed() const override;
+ /**
+ * @brief Get value of Elapsed property
+ *
+ * @return The elapsed microseconds since UTC
+ **/
+ uint64_t elapsed() const override;
- /**
- * @brief Set value of Elapsed property
- *
- * @param[in] value - The microseconds since UTC to set
- *
- * @return The updated elapsed microseconds since UTC
- **/
- uint64_t elapsed(uint64_t value) override;
+ /**
+ * @brief Set value of Elapsed property
+ *
+ * @param[in] value - The microseconds since UTC to set
+ *
+ * @return The updated elapsed microseconds since UTC
+ **/
+ uint64_t elapsed(uint64_t value) override;
- /** @brief Notified on time owner changed */
- void onOwnerChanged(Owner owner) override;
+ /** @brief Notified on time owner changed */
+ void onOwnerChanged(Owner owner) override;
- /** @brief Notified on bmc time is changed
- *
- * @param[in] bmcTime - The epoch time in microseconds
- */
- void onBmcTimeChanged(
- const std::chrono::microseconds& bmcTime) override;
+ /** @brief Notified on bmc time is changed
+ *
+ * @param[in] bmcTime - The epoch time in microseconds
+ */
+ void onBmcTimeChanged(const std::chrono::microseconds& bmcTime) override;
- private:
- /** @brief The diff between BMC and Host time */
- std::chrono::microseconds offset;
+ private:
+ /** @brief The diff between BMC and Host time */
+ std::chrono::microseconds offset;
- /**
- * @brief The diff between host time and steady clock
- * @details This diff is used to calculate the host time if BMC time
- * is changed and the owner is SPLIT.
- * Without this the host time is lost if BMC time is changed.
- */
- std::chrono::microseconds diffToSteadyClock;
+ /**
+ * @brief The diff between host time and steady clock
+ * @details This diff is used to calculate the host time if BMC time
+ * is changed and the owner is SPLIT.
+ * Without this the host time is lost if BMC time is changed.
+ */
+ std::chrono::microseconds diffToSteadyClock;
- /** @brief Save the offset value into offsetFile */
- void saveOffset();
+ /** @brief Save the offset value into offsetFile */
+ void saveOffset();
- /** @brief The file to store the offset in File System.
- * Read back when starts
- **/
- static constexpr auto offsetFile = HOST_OFFSET_FILE;
+ /** @brief The file to store the offset in File System.
+ * Read back when starts
+ **/
+ static constexpr auto offsetFile = HOST_OFFSET_FILE;
};
} // namespace time
diff --git a/main.cpp b/main.cpp
index b75c133..8344b38 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,23 +1,22 @@
-#include <sdbusplus/bus.hpp>
-
#include "config.h"
+
#include "bmc_epoch.hpp"
#include "host_epoch.hpp"
#include "manager.hpp"
+#include <sdbusplus/bus.hpp>
+
int main()
{
auto bus = sdbusplus::bus::new_default();
sd_event* event = nullptr;
- auto eventDeleter = [](sd_event* e) {
- e = sd_event_unref(e);
- };
+ auto eventDeleter = [](sd_event* e) { e = sd_event_unref(e); };
using SdEvent = std::unique_ptr<sd_event, decltype(eventDeleter)>;
// acquire a reference to the default event loop
sd_event_default(&event);
- SdEvent sdEvent {event, eventDeleter};
+ SdEvent sdEvent{event, eventDeleter};
event = nullptr;
// attach bus to this event loop
@@ -29,7 +28,7 @@
phosphor::time::Manager manager(bus);
phosphor::time::BmcEpoch bmc(bus, OBJPATH_BMC);
- phosphor::time::HostEpoch host(bus,OBJPATH_HOST);
+ phosphor::time::HostEpoch host(bus, OBJPATH_HOST);
manager.addListener(&bmc);
manager.addListener(&host);
diff --git a/manager.cpp b/manager.cpp
index 8d3d955..6d6c659 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -1,8 +1,9 @@
#include "manager.hpp"
+
#include "utils.hpp"
-#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/State/Host/server.hpp>
@@ -17,7 +18,7 @@
constexpr auto SYSTEMD_TIME_PATH = "/org/freedesktop/timedate1";
constexpr auto SYSTEMD_TIME_INTERFACE = "org.freedesktop.timedate1";
constexpr auto METHOD_SET_NTP = "SetNTP";
-}
+} // namespace
namespace phosphor
{
@@ -26,29 +27,25 @@
using namespace phosphor::logging;
-const std::set<std::string>
-Manager::managedProperties = {PROPERTY_TIME_MODE, PROPERTY_TIME_OWNER};
+const std::set<std::string> Manager::managedProperties = {PROPERTY_TIME_MODE,
+ PROPERTY_TIME_OWNER};
-Manager::Manager(sdbusplus::bus::bus& bus)
- : bus(bus)
+Manager::Manager(sdbusplus::bus::bus& bus) : bus(bus)
{
using namespace sdbusplus::bus::match::rules;
hostStateChangeMatch =
std::make_unique<decltype(hostStateChangeMatch)::element_type>(
- bus,
- propertiesChanged(settings.hostState, settings::hostStateIntf),
- std::bind(std::mem_fn(&Manager::onHostStateChanged),
- this, std::placeholders::_1));
+ bus, propertiesChanged(settings.hostState, settings::hostStateIntf),
+ std::bind(std::mem_fn(&Manager::onHostStateChanged), this,
+ std::placeholders::_1));
settingsMatches.emplace_back(
- bus,
- propertiesChanged(settings.timeOwner, settings::timeOwnerIntf),
- std::bind(std::mem_fn(&Manager::onSettingsChanged),
- this, std::placeholders::_1));
+ bus, propertiesChanged(settings.timeOwner, settings::timeOwnerIntf),
+ std::bind(std::mem_fn(&Manager::onSettingsChanged), this,
+ std::placeholders::_1));
settingsMatches.emplace_back(
- bus,
- propertiesChanged(settings.timeSyncMethod, settings::timeSyncIntf),
- std::bind(std::mem_fn(&Manager::onSettingsChanged),
- this, std::placeholders::_1));
+ bus, propertiesChanged(settings.timeSyncMethod, settings::timeSyncIntf),
+ std::bind(std::mem_fn(&Manager::onSettingsChanged), this,
+ std::placeholders::_1));
checkHostOn();
@@ -57,10 +54,8 @@
// Check the settings daemon to process the new settings
auto mode = getSetting(settings.timeSyncMethod.c_str(),
- settings::timeSyncIntf,
- PROPERTY_TIME_MODE);
- auto owner = getSetting(settings.timeOwner.c_str(),
- settings::timeOwnerIntf,
+ settings::timeSyncIntf, PROPERTY_TIME_MODE);
+ auto owner = getSetting(settings.timeOwner.c_str(), settings::timeOwnerIntf,
PROPERTY_TIME_OWNER);
onPropertyChanged(PROPERTY_TIME_MODE, mode);
@@ -93,14 +88,11 @@
void Manager::checkHostOn()
{
using Host = sdbusplus::xyz::openbmc_project::State::server::Host;
- auto hostService = utils::getService(bus,
- settings.hostState.c_str(),
+ auto hostService = utils::getService(bus, settings.hostState.c_str(),
settings::hostStateIntf);
- auto stateStr = utils::getProperty<std::string>(bus,
- hostService.c_str(),
- settings.hostState.c_str(),
- settings::hostStateIntf,
- HOST_CURRENT_STATE);
+ auto stateStr = utils::getProperty<std::string>(
+ bus, hostService.c_str(), settings.hostState.c_str(),
+ settings::hostStateIntf, HOST_CURRENT_STATE);
auto state = Host::convertHostStateFromString(stateStr);
hostOn = (state == Host::HostState::Running);
}
@@ -142,7 +134,7 @@
msg.read(interface, properties);
- for(const auto& p : properties)
+ for (const auto& p : properties)
{
onPropertyChanged(p.first, p.second.get<std::string>());
}
@@ -187,18 +179,15 @@
{
bool isNtp =
(value == "xyz.openbmc_project.Time.Synchronization.Method.NTP");
- auto method = bus.new_method_call(SYSTEMD_TIME_SERVICE,
- SYSTEMD_TIME_PATH,
- SYSTEMD_TIME_INTERFACE,
- METHOD_SET_NTP);
+ auto method = bus.new_method_call(SYSTEMD_TIME_SERVICE, SYSTEMD_TIME_PATH,
+ SYSTEMD_TIME_INTERFACE, METHOD_SET_NTP);
method.append(isNtp, false); // isNtp: 'true/false' means Enable/Disable
// 'false' meaning no policy-kit
try
{
bus.call_noreply(method);
- log<level::INFO>("Updated NTP setting",
- entry("ENABLED=%d", isNtp));
+ log<level::INFO>("Updated NTP setting", entry("ENABLED=%d", isNtp));
}
catch (const sdbusplus::exception::SdBusError& ex)
{
@@ -220,11 +209,12 @@
msg.read(interface, properties);
- for(const auto& p : properties)
+ for (const auto& p : properties)
{
if (p.first == HOST_CURRENT_STATE)
{
- auto state = Host::convertHostStateFromString(p.second.get<std::string>());
+ auto state =
+ Host::convertHostStateFromString(p.second.get<std::string>());
onHostState(state == Host::HostState::Running);
break;
}
@@ -310,17 +300,13 @@
}
}
-std::string Manager::getSetting(const char* path,
- const char* interface,
+std::string Manager::getSetting(const char* path, const char* interface,
const char* setting) const
{
std::string settingManager = utils::getService(bus, path, interface);
- return utils::getProperty<std::string>(bus,
- settingManager.c_str(),
- path,
- interface,
- setting);
+ return utils::getProperty<std::string>(bus, settingManager.c_str(), path,
+ interface, setting);
}
-}
-}
+} // namespace time
+} // namespace phosphor
diff --git a/manager.hpp b/manager.hpp
index 3256f59..0c672fa 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -1,13 +1,13 @@
#pragma once
#include "config.h"
-#include "types.hpp"
+
#include "property_change_listener.hpp"
#include "settings.hpp"
+#include "types.hpp"
#include <sdbusplus/bus.hpp>
#include <sdbusplus/bus/match.hpp>
-
#include <set>
#include <string>
@@ -24,201 +24,196 @@
*/
class Manager
{
- public:
- friend class TestManager;
+ public:
+ friend class TestManager;
- explicit Manager(sdbusplus::bus::bus& bus);
- Manager(const Manager&) = delete;
- Manager& operator=(const Manager&) = delete;
- Manager(Manager&&) = delete;
- Manager& operator=(Manager&&) = delete;
- ~Manager() = default;
+ explicit Manager(sdbusplus::bus::bus& bus);
+ Manager(const Manager&) = delete;
+ Manager& operator=(const Manager&) = delete;
+ Manager(Manager&&) = delete;
+ Manager& operator=(Manager&&) = delete;
+ ~Manager() = default;
- /** @brief Add a listener that will be called
- * when property is changed
- **/
- void addListener(PropertyChangeListner* listener);
+ /** @brief Add a listener that will be called
+ * when property is changed
+ **/
+ void addListener(PropertyChangeListner* listener);
- private:
- /** @brief Persistent sdbusplus DBus connection */
- sdbusplus::bus::bus& bus;
+ private:
+ /** @brief Persistent sdbusplus DBus connection */
+ sdbusplus::bus::bus& bus;
- /** @brief The match of settings property change */
- std::vector<sdbusplus::bus::match::match> settingsMatches;
+ /** @brief The match of settings property change */
+ std::vector<sdbusplus::bus::match::match> settingsMatches;
- /** @brief The match of host state change */
- std::unique_ptr<sdbusplus::bus::match::match> hostStateChangeMatch;
+ /** @brief The match of host state change */
+ std::unique_ptr<sdbusplus::bus::match::match> hostStateChangeMatch;
- /** @brief The container to hold all the listeners */
- std::set<PropertyChangeListner*> listeners;
+ /** @brief The container to hold all the listeners */
+ std::set<PropertyChangeListner*> listeners;
- /** @brief Settings objects of intereset */
- settings::Objects settings;
+ /** @brief Settings objects of intereset */
+ settings::Objects settings;
- /** @brief The value to indicate if host is on */
- bool hostOn = false;
+ /** @brief The value to indicate if host is on */
+ bool hostOn = false;
- /** @brief The requested time mode when host is on*/
- std::string requestedMode;
+ /** @brief The requested time mode when host is on*/
+ std::string requestedMode;
- /** @brief The requested time owner when host is on*/
- std::string requestedOwner;
+ /** @brief The requested time owner when host is on*/
+ std::string requestedOwner;
- /** @brief The current time mode */
- Mode timeMode = DEFAULT_TIME_MODE;
+ /** @brief The current time mode */
+ Mode timeMode = DEFAULT_TIME_MODE;
- /** @brief The current time owner */
- Owner timeOwner = DEFAULT_TIME_OWNER;
+ /** @brief The current time owner */
+ Owner timeOwner = DEFAULT_TIME_OWNER;
- /** @brief Restore saved settings */
- void restoreSettings();
+ /** @brief Restore saved settings */
+ void restoreSettings();
- /** @brief Check if host is on and update hostOn variable */
- void checkHostOn();
+ /** @brief Check if host is on and update hostOn variable */
+ void checkHostOn();
- /** @brief Get setting from settingsd service
- *
- * @param[in] path - The dbus object path
- * @param[in] interface - The dbus interface
- * @param[in] setting - The string of the setting
- *
- * @return The setting value in string
- */
- std::string getSetting(const char* path,
- const char* interface,
- const char* setting) const;
+ /** @brief Get setting from settingsd service
+ *
+ * @param[in] path - The dbus object path
+ * @param[in] interface - The dbus interface
+ * @param[in] setting - The string of the setting
+ *
+ * @return The setting value in string
+ */
+ std::string getSetting(const char* path, const char* interface,
+ const char* setting) const;
- /** @brief Set current time mode from the time mode string
- *
- * @param[in] mode - The string of time mode
- *
- * @return - true if the mode is updated
- * false if it's the same as before
- */
- bool setCurrentTimeMode(const std::string& mode);
+ /** @brief Set current time mode from the time mode string
+ *
+ * @param[in] mode - The string of time mode
+ *
+ * @return - true if the mode is updated
+ * false if it's the same as before
+ */
+ bool setCurrentTimeMode(const std::string& mode);
- /** @brief Set current time owner from the time owner string
- *
- * @param[in] owner - The string of time owner
- *
- * @return - true if the owner is updated
- * false if it's the same as before
- */
- bool setCurrentTimeOwner(const std::string& owner);
+ /** @brief Set current time owner from the time owner string
+ *
+ * @param[in] owner - The string of time owner
+ *
+ * @return - true if the owner is updated
+ * false if it's the same as before
+ */
+ bool setCurrentTimeOwner(const std::string& owner);
- /** @brief Called on time mode is changed
- *
- * Notify listeners that time mode is changed and update ntp setting
- *
- * @param[in] mode - The string of time mode
- */
- void onTimeModeChanged(const std::string& mode);
+ /** @brief Called on time mode is changed
+ *
+ * Notify listeners that time mode is changed and update ntp setting
+ *
+ * @param[in] mode - The string of time mode
+ */
+ void onTimeModeChanged(const std::string& mode);
- /** @brief Called on time owner is changed
- *
- * Notify listeners that time owner is changed
- */
- void onTimeOwnerChanged();
+ /** @brief Called on time owner is changed
+ *
+ * Notify listeners that time owner is changed
+ */
+ void onTimeOwnerChanged();
- /** @brief Callback to handle change in a setting
- *
- * @param[in] msg - sdbusplus dbusmessage
- *
- * @return 0 on success, < 0 on failure.
- */
- int onSettingsChanged(sdbusplus::message::message& msg);
+ /** @brief Callback to handle change in a setting
+ *
+ * @param[in] msg - sdbusplus dbusmessage
+ *
+ * @return 0 on success, < 0 on failure.
+ */
+ int onSettingsChanged(sdbusplus::message::message& msg);
- /** @brief Notified on settings property changed
- *
- * @param[in] key - The name of property that is changed
- * @param[in] value - The value of the property
- */
- void onPropertyChanged(const std::string& key,
- const std::string& value);
+ /** @brief Notified on settings property changed
+ *
+ * @param[in] key - The name of property that is changed
+ * @param[in] value - The value of the property
+ */
+ void onPropertyChanged(const std::string& key, const std::string& value);
- /** @brief Notified on host state has changed
- *
- * @param[in] msg - sdbusplus dbusmessage
- */
- void onHostStateChanged(sdbusplus::message::message& msg);
+ /** @brief Notified on host state has changed
+ *
+ * @param[in] msg - sdbusplus dbusmessage
+ */
+ void onHostStateChanged(sdbusplus::message::message& msg);
- /** @brief Notified on host state has changed
- *
- * @param[in] on - Indicate if the host is on or off
- */
- void onHostState(bool on);
+ /** @brief Notified on host state has changed
+ *
+ * @param[in] on - Indicate if the host is on or off
+ */
+ void onHostState(bool on);
- /** @brief Set the property as requested time mode/owner
- *
- * @param[in] key - The property name
- * @param[in] value - The property value
- */
- void setPropertyAsRequested(const std::string& key,
- const std::string& value);
+ /** @brief Set the property as requested time mode/owner
+ *
+ * @param[in] key - The property name
+ * @param[in] value - The property value
+ */
+ void setPropertyAsRequested(const std::string& key,
+ const std::string& value);
- /** @brief Set the current mode to user requested one
- * if conditions allow it
- *
- * @param[in] mode - The string of time mode
- */
- void setRequestedMode(const std::string& mode);
+ /** @brief Set the current mode to user requested one
+ * if conditions allow it
+ *
+ * @param[in] mode - The string of time mode
+ */
+ void setRequestedMode(const std::string& mode);
- /** @brief Set the current owner to user requested one
- * if conditions allow it
- *
- * @param[in] owner - The string of time owner
- */
- void setRequestedOwner(const std::string& owner);
+ /** @brief Set the current owner to user requested one
+ * if conditions allow it
+ *
+ * @param[in] owner - The string of time owner
+ */
+ void setRequestedOwner(const std::string& owner);
- /** @brief Update the NTP setting to systemd time service
- *
- * @param[in] value - The time mode value, e.g. "NTP" or "MANUAL"
- */
- void updateNtpSetting(const std::string& value);
+ /** @brief Update the NTP setting to systemd time service
+ *
+ * @param[in] value - The time mode value, e.g. "NTP" or "MANUAL"
+ */
+ void updateNtpSetting(const std::string& value);
- /** @brief The static function called on settings property changed
- *
- * @param[in] msg - Data associated with subscribed signal
- * @param[in] userData - Pointer to this object instance
- * @param[out] retError - Not used but required with signal API
- */
- static int onPropertyChanged(sd_bus_message* msg,
- void* userData,
- sd_bus_error* retError);
+ /** @brief The static function called on settings property changed
+ *
+ * @param[in] msg - Data associated with subscribed signal
+ * @param[in] userData - Pointer to this object instance
+ * @param[out] retError - Not used but required with signal API
+ */
+ static int onPropertyChanged(sd_bus_message* msg, void* userData,
+ sd_bus_error* retError);
- /** @brief The string of time mode property */
- static constexpr auto PROPERTY_TIME_MODE = "TimeSyncMethod";
+ /** @brief The string of time mode property */
+ static constexpr auto PROPERTY_TIME_MODE = "TimeSyncMethod";
- /** @brief The string of time owner property */
- static constexpr auto PROPERTY_TIME_OWNER = "TimeOwner";
+ /** @brief The string of time owner property */
+ static constexpr auto PROPERTY_TIME_OWNER = "TimeOwner";
- using Updater = std::function<void(const std::string&)>;
+ using Updater = std::function<void(const std::string&)>;
- /** @brief Map the property string to functions that shall
- * be called when the property is changed
- */
- const std::map<std::string, Updater> propertyUpdaters =
- {
- {PROPERTY_TIME_MODE, std::bind(&Manager::setCurrentTimeMode,
- this, std::placeholders::_1)},
- {PROPERTY_TIME_OWNER, std::bind(&Manager::setCurrentTimeOwner,
- this, std::placeholders::_1)}
- };
+ /** @brief Map the property string to functions that shall
+ * be called when the property is changed
+ */
+ const std::map<std::string, Updater> propertyUpdaters = {
+ {PROPERTY_TIME_MODE,
+ std::bind(&Manager::setCurrentTimeMode, this, std::placeholders::_1)},
+ {PROPERTY_TIME_OWNER, std::bind(&Manager::setCurrentTimeOwner, this,
+ std::placeholders::_1)}};
- /** @brief The properties that manager shall notify the
- * listeners when changed
- */
- static const std::set<std::string> managedProperties;
+ /** @brief The properties that manager shall notify the
+ * listeners when changed
+ */
+ static const std::set<std::string> managedProperties;
- /** @brief The map that maps the string to Owners */
- static const std::map<std::string, Owner> ownerMap;
+ /** @brief The map that maps the string to Owners */
+ static const std::map<std::string, Owner> ownerMap;
- /** @brief The file name of saved time mode */
- static constexpr auto modeFile = "/var/lib/obmc/saved_time_mode";
+ /** @brief The file name of saved time mode */
+ static constexpr auto modeFile = "/var/lib/obmc/saved_time_mode";
- /** @brief The file name of saved time owner */
- static constexpr auto ownerFile = "/var/lib/obmc/saved_time_owner";
+ /** @brief The file name of saved time owner */
+ static constexpr auto ownerFile = "/var/lib/obmc/saved_time_owner";
};
-}
-}
+} // namespace time
+} // namespace phosphor
diff --git a/property_change_listener.hpp b/property_change_listener.hpp
index de23f47..a19a228 100644
--- a/property_change_listener.hpp
+++ b/property_change_listener.hpp
@@ -9,15 +9,17 @@
class PropertyChangeListner
{
- public:
- virtual ~PropertyChangeListner() {}
+ public:
+ virtual ~PropertyChangeListner()
+ {
+ }
- /** @brief Notified on time mode is changed */
- virtual void onModeChanged(Mode mode) = 0;
+ /** @brief Notified on time mode is changed */
+ virtual void onModeChanged(Mode mode) = 0;
- /** @brief Notified on time owner is changed */
- virtual void onOwnerChanged(Owner owner) = 0;
+ /** @brief Notified on time owner is changed */
+ virtual void onOwnerChanged(Owner owner) = 0;
};
-}
-}
+} // namespace time
+} // namespace phosphor
diff --git a/settings.cpp b/settings.cpp
index 704905a..aeefe64 100644
--- a/settings.cpp
+++ b/settings.cpp
@@ -1,7 +1,9 @@
+#include "settings.hpp"
+
+#include "xyz/openbmc_project/Common/error.hpp"
+
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
-#include "xyz/openbmc_project/Common/error.hpp"
-#include "settings.hpp"
namespace settings
{
@@ -16,13 +18,11 @@
Objects::Objects()
{
auto bus = sdbusplus::bus::new_default();
- std::vector<std::string> settingsIntfs =
- {timeOwnerIntf, timeSyncIntf, hostStateIntf};
+ std::vector<std::string> settingsIntfs = {timeOwnerIntf, timeSyncIntf,
+ hostStateIntf};
auto depth = 0;
- auto mapperCall = bus.new_method_call(mapperService,
- mapperPath,
- mapperIntf,
+ auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf,
"GetSubTree");
mapperCall.append(root);
mapperCall.append(depth);
@@ -48,9 +48,9 @@
for (const auto& iter : result)
{
const Path& path = iter.first;
- for (const auto& service_iter: iter.second)
+ for (const auto& service_iter : iter.second)
{
- for (const Interface& interface: service_iter.second)
+ for (const Interface& interface : service_iter.second)
{
if (timeOwnerIntf == interface)
{
@@ -73,10 +73,8 @@
{
auto bus = sdbusplus::bus::new_default();
using Interfaces = std::vector<Interface>;
- auto mapperCall = bus.new_method_call(mapperService,
- mapperPath,
- mapperIntf,
- "GetObject");
+ auto mapperCall =
+ bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetObject");
mapperCall.append(path);
mapperCall.append(Interfaces({interface}));
diff --git a/settings.hpp b/settings.hpp
index 95d20dc..8a89e74 100644
--- a/settings.hpp
+++ b/settings.hpp
@@ -1,7 +1,7 @@
#pragma once
-#include <string>
#include <sdbusplus/bus.hpp>
+#include <string>
namespace settings
{
@@ -20,37 +20,37 @@
*/
struct Objects
{
- public:
- /** @brief Constructor - fetch settings objects
- *
- * @param[in] bus - The D-bus bus object
- */
- Objects();
- Objects(const Objects&) = default;
- Objects& operator=(const Objects&) = default;
- Objects(Objects&&) = default;
- Objects& operator=(Objects&&) = default;
- ~Objects() = default;
+ public:
+ /** @brief Constructor - fetch settings objects
+ *
+ * @param[in] bus - The D-bus bus object
+ */
+ Objects();
+ Objects(const Objects&) = default;
+ Objects& operator=(const Objects&) = default;
+ Objects(Objects&&) = default;
+ Objects& operator=(Objects&&) = default;
+ ~Objects() = default;
- /** @brief Fetch D-bus service, given a path and an interface. The
- * service can't be cached because mapper returns unique
- * service names.
- *
- * @param[in] path - The D-bus object
- * @param[in] interface - The D-bus interface
- *
- * @return std::string - the D-bus service
- */
- Service service(const Path& path, const Interface& interface) const;
+ /** @brief Fetch D-bus service, given a path and an interface. The
+ * service can't be cached because mapper returns unique
+ * service names.
+ *
+ * @param[in] path - The D-bus object
+ * @param[in] interface - The D-bus interface
+ *
+ * @return std::string - the D-bus service
+ */
+ Service service(const Path& path, const Interface& interface) const;
- /** @brief time owner settings object */
- Path timeOwner;
+ /** @brief time owner settings object */
+ Path timeOwner;
- /** @brief time sync method settings object */
- Path timeSyncMethod;
+ /** @brief time sync method settings object */
+ Path timeSyncMethod;
- /** @brief host state object */
- Path hostState;
+ /** @brief host state object */
+ Path hostState;
};
} // namespace settings
diff --git a/test/TestBmcEpoch.cpp b/test/TestBmcEpoch.cpp
index 18f3218..eb116e5 100644
--- a/test/TestBmcEpoch.cpp
+++ b/test/TestBmcEpoch.cpp
@@ -1,13 +1,15 @@
-#include "bmc_epoch.hpp"
#include "config.h"
-#include "types.hpp"
-#include "mocked_bmc_time_change_listener.hpp"
-#include <gtest/gtest.h>
+#include "bmc_epoch.hpp"
+#include "mocked_bmc_time_change_listener.hpp"
+#include "types.hpp"
+
#include <memory>
#include <sdbusplus/bus.hpp>
#include <xyz/openbmc_project/Time/error.hpp>
+#include <gtest/gtest.h>
+
namespace phosphor
{
namespace time
@@ -15,57 +17,52 @@
using ::testing::_;
using namespace std::chrono;
-using NotAllowed =
- sdbusplus::xyz::openbmc_project::Time::Error::NotAllowed;
+using NotAllowed = sdbusplus::xyz::openbmc_project::Time::Error::NotAllowed;
class TestBmcEpoch : public testing::Test
{
- public:
- sdbusplus::bus::bus bus;
- sd_event* event;
- MockBmcTimeChangeListener listener;
- std::unique_ptr<BmcEpoch> bmcEpoch;
+ public:
+ sdbusplus::bus::bus bus;
+ sd_event* event;
+ MockBmcTimeChangeListener listener;
+ std::unique_ptr<BmcEpoch> bmcEpoch;
- TestBmcEpoch()
- : bus(sdbusplus::bus::new_default())
- {
- // 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->setBmcTimeChangeListener(&listener);
- }
+ TestBmcEpoch() : bus(sdbusplus::bus::new_default())
+ {
+ // 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->setBmcTimeChangeListener(&listener);
+ }
- ~TestBmcEpoch()
- {
- bus.detach_event();
- sd_event_unref(event);
- }
+ ~TestBmcEpoch()
+ {
+ bus.detach_event();
+ sd_event_unref(event);
+ }
- // Proxies for BmcEpoch's private members and functions
- Mode getTimeMode()
- {
- return bmcEpoch->timeMode;
- }
- Owner getTimeOwner()
- {
- return bmcEpoch->timeOwner;
- }
- void setTimeOwner(Owner owner)
- {
- bmcEpoch->timeOwner = owner;
- }
- void setTimeMode(Mode mode)
- {
- bmcEpoch->timeMode = mode;
- }
- void triggerTimeChange()
- {
- bmcEpoch->onTimeChange(nullptr,
- -1,
- 0,
- bmcEpoch.get());
- }
+ // Proxies for BmcEpoch's private members and functions
+ Mode getTimeMode()
+ {
+ return bmcEpoch->timeMode;
+ }
+ Owner getTimeOwner()
+ {
+ return bmcEpoch->timeOwner;
+ }
+ void setTimeOwner(Owner owner)
+ {
+ bmcEpoch->timeOwner = owner;
+ }
+ void setTimeMode(Mode mode)
+ {
+ bmcEpoch->timeMode = mode;
+ }
+ void triggerTimeChange()
+ {
+ bmcEpoch->onTimeChange(nullptr, -1, 0, bmcEpoch.get());
+ }
};
TEST_F(TestBmcEpoch, empty)
@@ -85,15 +82,14 @@
TEST_F(TestBmcEpoch, setElapsedNotAllowed)
{
- auto epochNow = duration_cast<microseconds>(
- system_clock::now().time_since_epoch()).count();
+ auto epochNow =
+ duration_cast<microseconds>(system_clock::now().time_since_epoch())
+ .count();
// In Host owner, setting time is not allowed
setTimeMode(Mode::Manual);
setTimeOwner(Owner::Host);
- EXPECT_THROW(
- bmcEpoch->elapsed(epochNow),
- NotAllowed);
+ EXPECT_THROW(bmcEpoch->elapsed(epochNow), NotAllowed);
}
TEST_F(TestBmcEpoch, setElapsedOK)
@@ -110,5 +106,5 @@
triggerTimeChange();
}
-}
-}
+} // namespace time
+} // namespace phosphor
diff --git a/test/TestEpochBase.cpp b/test/TestEpochBase.cpp
index 6c2ec88..b193969 100644
--- a/test/TestEpochBase.cpp
+++ b/test/TestEpochBase.cpp
@@ -1,8 +1,9 @@
-#include <sdbusplus/bus.hpp>
-#include <gtest/gtest.h>
-
-#include "types.hpp"
#include "epoch_base.hpp"
+#include "types.hpp"
+
+#include <sdbusplus/bus.hpp>
+
+#include <gtest/gtest.h>
namespace phosphor
{
@@ -11,25 +12,23 @@
class TestEpochBase : public testing::Test
{
- public:
- sdbusplus::bus::bus bus;
- EpochBase epochBase;
+ public:
+ sdbusplus::bus::bus bus;
+ EpochBase epochBase;
- TestEpochBase()
- : bus(sdbusplus::bus::new_default()),
- epochBase(bus, "")
- {
- // Empty
- }
+ TestEpochBase() : bus(sdbusplus::bus::new_default()), epochBase(bus, "")
+ {
+ // Empty
+ }
- Mode getMode()
- {
- return epochBase.timeMode;
- }
- Owner getOwner()
- {
- return epochBase.timeOwner;
- }
+ Mode getMode()
+ {
+ return epochBase.timeMode;
+ }
+ Owner getOwner()
+ {
+ return epochBase.timeOwner;
+ }
};
TEST_F(TestEpochBase, onModeChange)
@@ -56,5 +55,5 @@
EXPECT_EQ(Owner::Both, getOwner());
}
-}
-}
+} // namespace time
+} // namespace phosphor
diff --git a/test/TestHostEpoch.cpp b/test/TestHostEpoch.cpp
index 1004dad..7ddf92f 100644
--- a/test/TestHostEpoch.cpp
+++ b/test/TestHostEpoch.cpp
@@ -1,13 +1,13 @@
-#include "host_epoch.hpp"
-#include "utils.hpp"
#include "config.h"
-#include "types.hpp"
-#include <xyz/openbmc_project/Time/error.hpp>
+#include "host_epoch.hpp"
+#include "types.hpp"
+#include "utils.hpp"
#include <sdbusplus/bus.hpp>
-#include <gtest/gtest.h>
+#include <xyz/openbmc_project/Time/error.hpp>
+#include <gtest/gtest.h>
namespace phosphor
{
@@ -16,129 +16,128 @@
using namespace std::chrono;
using namespace std::chrono_literals;
-using NotAllowed =
- sdbusplus::xyz::openbmc_project::Time::Error::NotAllowed;
+using NotAllowed = sdbusplus::xyz::openbmc_project::Time::Error::NotAllowed;
const constexpr microseconds USEC_ZERO{0};
class TestHostEpoch : public testing::Test
{
- public:
- sdbusplus::bus::bus bus;
- HostEpoch hostEpoch;
+ public:
+ sdbusplus::bus::bus bus;
+ HostEpoch hostEpoch;
- static constexpr auto FILE_NOT_EXIST = "path/to/file-not-exist";
- static constexpr auto FILE_OFFSET = "saved_host_offset";
- const microseconds delta = 2s;
+ static constexpr auto FILE_NOT_EXIST = "path/to/file-not-exist";
+ static constexpr auto FILE_OFFSET = "saved_host_offset";
+ const microseconds delta = 2s;
- TestHostEpoch()
- : bus(sdbusplus::bus::new_default()),
- hostEpoch(bus, OBJPATH_HOST)
- {
- // Make sure the file does not exist
- std::remove(FILE_NOT_EXIST);
- }
- ~TestHostEpoch()
- {
- // Cleanup test file
- std::remove(FILE_OFFSET);
- }
+ TestHostEpoch() :
+ bus(sdbusplus::bus::new_default()), hostEpoch(bus, OBJPATH_HOST)
+ {
+ // Make sure the file does not exist
+ std::remove(FILE_NOT_EXIST);
+ }
+ ~TestHostEpoch()
+ {
+ // Cleanup test file
+ std::remove(FILE_OFFSET);
+ }
- // Proxies for HostEpoch's private members and functions
- Mode getTimeMode()
- {
- return hostEpoch.timeMode;
- }
- Owner getTimeOwner()
- {
- return hostEpoch.timeOwner;
- }
- microseconds getOffset()
- {
- return hostEpoch.offset;
- }
- void setOffset(microseconds us)
- {
- hostEpoch.offset = us;
- }
- void setTimeOwner(Owner owner)
- {
- hostEpoch.onOwnerChanged(owner);
- }
- void setTimeMode(Mode mode)
- {
- hostEpoch.onModeChanged(mode);
- }
+ // Proxies for HostEpoch's private members and functions
+ Mode getTimeMode()
+ {
+ return hostEpoch.timeMode;
+ }
+ Owner getTimeOwner()
+ {
+ return hostEpoch.timeOwner;
+ }
+ microseconds getOffset()
+ {
+ return hostEpoch.offset;
+ }
+ void setOffset(microseconds us)
+ {
+ hostEpoch.offset = us;
+ }
+ void setTimeOwner(Owner owner)
+ {
+ hostEpoch.onOwnerChanged(owner);
+ }
+ void setTimeMode(Mode mode)
+ {
+ hostEpoch.onModeChanged(mode);
+ }
- void checkSettingTimeNotAllowed()
- {
- // By default offset shall be 0
- EXPECT_EQ(0, getOffset().count());
+ void checkSettingTimeNotAllowed()
+ {
+ // By default offset shall be 0
+ EXPECT_EQ(0, getOffset().count());
- // Set time is not allowed,
- // so verify offset is still 0 after set time
- microseconds diff = 1min;
- EXPECT_THROW(
- hostEpoch.elapsed(hostEpoch.elapsed() + diff.count()),
- NotAllowed);
- EXPECT_EQ(0, getOffset().count());
- }
+ // Set time is not allowed,
+ // so verify offset is still 0 after set time
+ microseconds diff = 1min;
+ EXPECT_THROW(hostEpoch.elapsed(hostEpoch.elapsed() + diff.count()),
+ NotAllowed);
+ EXPECT_EQ(0, getOffset().count());
+ }
- void checkSetSplitTimeInFuture()
- {
- // Get current time, and set future +1min time
- auto t1 = hostEpoch.elapsed();
- EXPECT_NE(0, t1);
- microseconds diff = 1min;
- auto t2 = t1 + diff.count();
- hostEpoch.elapsed(t2);
+ void checkSetSplitTimeInFuture()
+ {
+ // Get current time, and set future +1min time
+ auto t1 = hostEpoch.elapsed();
+ EXPECT_NE(0, t1);
+ microseconds diff = 1min;
+ auto t2 = t1 + diff.count();
+ hostEpoch.elapsed(t2);
- // Verify that the offset shall be positive,
- // and less or equal to diff, and shall be not too less.
- auto offset = getOffset();
- EXPECT_GT(offset, USEC_ZERO);
- EXPECT_LE(offset, diff);
- diff -= delta;
- EXPECT_GE(offset, diff);
+ // Verify that the offset shall be positive,
+ // and less or equal to diff, and shall be not too less.
+ auto offset = getOffset();
+ EXPECT_GT(offset, USEC_ZERO);
+ EXPECT_LE(offset, diff);
+ diff -= delta;
+ EXPECT_GE(offset, diff);
- // Now get time shall be around future +1min time
- auto epochNow = duration_cast<microseconds>(
- system_clock::now().time_since_epoch()).count();
- auto elapsedGot = hostEpoch.elapsed();
- EXPECT_LT(epochNow, elapsedGot);
- auto epochDiff = elapsedGot - epochNow;
- diff = 1min;
- EXPECT_GT(epochDiff, (diff - delta).count());
- EXPECT_LT(epochDiff, (diff + delta).count());
- }
- void checkSetSplitTimeInPast()
- {
- // Get current time, and set past -1min time
- auto t1 = hostEpoch.elapsed();
- EXPECT_NE(0, t1);
- microseconds diff = 1min;
- auto t2 = t1 - diff.count();
- hostEpoch.elapsed(t2);
+ // Now get time shall be around future +1min time
+ auto epochNow =
+ duration_cast<microseconds>(system_clock::now().time_since_epoch())
+ .count();
+ auto elapsedGot = hostEpoch.elapsed();
+ EXPECT_LT(epochNow, elapsedGot);
+ auto epochDiff = elapsedGot - epochNow;
+ diff = 1min;
+ EXPECT_GT(epochDiff, (diff - delta).count());
+ EXPECT_LT(epochDiff, (diff + delta).count());
+ }
+ void checkSetSplitTimeInPast()
+ {
+ // Get current time, and set past -1min time
+ auto t1 = hostEpoch.elapsed();
+ EXPECT_NE(0, t1);
+ microseconds diff = 1min;
+ auto t2 = t1 - diff.count();
+ hostEpoch.elapsed(t2);
- // Verify that the offset shall be negative, and the absolute value
- // shall be equal or greater than diff, and shall not be too greater
- auto offset = getOffset();
- EXPECT_LT(offset, USEC_ZERO);
- offset = -offset;
- EXPECT_GE(offset, diff);
- diff += 10s;
- EXPECT_LE(offset, diff);
+ // Verify that the offset shall be negative, and the absolute value
+ // shall be equal or greater than diff, and shall not be too greater
+ auto offset = getOffset();
+ EXPECT_LT(offset, USEC_ZERO);
+ offset = -offset;
+ EXPECT_GE(offset, diff);
+ diff += 10s;
+ EXPECT_LE(offset, diff);
- // Now get time shall be around past -1min time
- auto epochNow = duration_cast<microseconds>(
- system_clock::now().time_since_epoch()).count();
- auto elapsedGot = hostEpoch.elapsed();
- EXPECT_LT(elapsedGot, epochNow);
- auto epochDiff = epochNow - elapsedGot;
- diff = 1min;
- EXPECT_GT(epochDiff, (diff - delta).count());
- EXPECT_LT(epochDiff, (diff + delta).count());
- }
+ // Now get time shall be around past -1min time
+ auto epochNow =
+ duration_cast<microseconds>(system_clock::now().time_since_epoch())
+ .count();
+ auto elapsedGot = hostEpoch.elapsed();
+ EXPECT_LT(elapsedGot, epochNow);
+ auto epochDiff = epochNow - elapsedGot;
+ diff = 1min;
+ EXPECT_GT(epochDiff, (diff - delta).count());
+ EXPECT_LT(epochDiff, (diff + delta).count());
+ }
};
TEST_F(TestHostEpoch, empty)
@@ -160,13 +159,13 @@
{
// Write offset to file
microseconds offsetToWrite(1234567);
- utils::writeData<decltype(offsetToWrite)::rep>(
- FILE_OFFSET, offsetToWrite.count());
+ utils::writeData<decltype(offsetToWrite)::rep>(FILE_OFFSET,
+ offsetToWrite.count());
// Read it back
microseconds offsetToRead;
- offsetToRead = microseconds(
- utils::readData<decltype(offsetToRead)::rep>(FILE_OFFSET));
+ offsetToRead =
+ microseconds(utils::readData<decltype(offsetToRead)::rep>(FILE_OFFSET));
EXPECT_EQ(offsetToWrite, offsetToRead);
}
@@ -295,5 +294,5 @@
EXPECT_EQ(USEC_ZERO, getOffset());
}
-}
-}
+} // namespace time
+} // namespace phosphor
diff --git a/test/TestManager.cpp b/test/TestManager.cpp
index aa7a647..c0763c8 100644
--- a/test/TestManager.cpp
+++ b/test/TestManager.cpp
@@ -1,9 +1,10 @@
-#include <sdbusplus/bus.hpp>
-#include <gtest/gtest.h>
-
-#include "types.hpp"
#include "manager.hpp"
#include "mocked_property_change_listener.hpp"
+#include "types.hpp"
+
+#include <sdbusplus/bus.hpp>
+
+#include <gtest/gtest.h>
using ::testing::_;
@@ -14,52 +15,49 @@
class TestManager : public testing::Test
{
- public:
- sdbusplus::bus::bus bus;
- Manager manager;
- MockPropertyChangeListner listener1;
- MockPropertyChangeListner listener2;
+ public:
+ sdbusplus::bus::bus bus;
+ Manager manager;
+ MockPropertyChangeListner listener1;
+ MockPropertyChangeListner listener2;
- TestManager()
- : bus(sdbusplus::bus::new_default()),
- manager(bus)
- {
- // Add two mocked listeners so that we can test
- // the behavior related to listeners
- manager.addListener(&listener1);
- manager.addListener(&listener2);
- }
+ TestManager() : bus(sdbusplus::bus::new_default()), manager(bus)
+ {
+ // Add two mocked listeners so that we can test
+ // the behavior related to listeners
+ manager.addListener(&listener1);
+ manager.addListener(&listener2);
+ }
- // Proxies for Manager's private members and functions
- Mode getTimeMode()
- {
- return manager.timeMode;
- }
- Owner getTimeOwner()
- {
- return manager.timeOwner;
- }
- bool hostOn()
- {
- return manager.hostOn;
- }
- std::string getRequestedMode()
- {
- return manager.requestedMode;
- }
- std::string getRequestedOwner()
- {
- return manager.requestedOwner;
- }
- void notifyPropertyChanged(const std::string& key,
- const std::string& value)
- {
- manager.onPropertyChanged(key, value);
- }
- void notifyOnHostState(bool hostOn)
- {
- manager.onHostState(hostOn);
- }
+ // Proxies for Manager's private members and functions
+ Mode getTimeMode()
+ {
+ return manager.timeMode;
+ }
+ Owner getTimeOwner()
+ {
+ return manager.timeOwner;
+ }
+ bool hostOn()
+ {
+ return manager.hostOn;
+ }
+ std::string getRequestedMode()
+ {
+ return manager.requestedMode;
+ }
+ std::string getRequestedOwner()
+ {
+ return manager.requestedOwner;
+ }
+ void notifyPropertyChanged(const std::string& key, const std::string& value)
+ {
+ manager.onPropertyChanged(key, value);
+ }
+ void notifyOnHostState(bool hostOn)
+ {
+ manager.onHostState(hostOn);
+ }
};
TEST_F(TestManager, DISABLED_empty)
@@ -73,7 +71,6 @@
EXPECT_EQ(Owner::Both, getTimeOwner());
}
-
TEST_F(TestManager, DISABLED_hostStateChange)
{
notifyOnHostState(true);
@@ -96,9 +93,8 @@
notifyPropertyChanged(
"TimeSyncMethod",
"xyz.openbmc_project.Time.Synchronization.Method.Manual");
- notifyPropertyChanged(
- "TimeOwner",
- "xyz.openbmc_project.Time.Owner.Owners.Host");
+ notifyPropertyChanged("TimeOwner",
+ "xyz.openbmc_project.Time.Owner.Owners.Host");
EXPECT_EQ("", getRequestedMode());
EXPECT_EQ("", getRequestedOwner());
@@ -115,16 +111,14 @@
notifyPropertyChanged(
"TimeSyncMethod",
"xyz.openbmc_project.Time.Synchronization.Method.NTP");
- notifyPropertyChanged(
- "TimeOwner",
- "xyz.openbmc_project.Time.Owner.Owners.Split");
+ notifyPropertyChanged("TimeOwner",
+ "xyz.openbmc_project.Time.Owner.Owners.Split");
EXPECT_EQ("xyz.openbmc_project.Time.Synchronization.Method.NTP",
getRequestedMode());
EXPECT_EQ("xyz.openbmc_project.Time.Owner.Owners.Split",
getRequestedOwner());
-
// When host becomes off, the requested mode/owner shall be notified
// to listeners, and be cleared
EXPECT_CALL(listener1, onModeChanged(Mode::NTP)).Times(1);
@@ -149,9 +143,8 @@
notifyPropertyChanged(
"TimeSyncMethod",
"xyz.openbmc_project.Time.Synchronization.Method.Manual");
- notifyPropertyChanged(
- "TimeOwner",
- "xyz.openbmc_project.Time.Owner.Owners.Host");
+ notifyPropertyChanged("TimeOwner",
+ "xyz.openbmc_project.Time.Owner.Owners.Host");
// Set host on
notifyOnHostState(true);
@@ -165,9 +158,8 @@
notifyPropertyChanged(
"TimeSyncMethod",
"xyz.openbmc_project.Time.Synchronization.Method.NTP");
- notifyPropertyChanged(
- "TimeOwner",
- "xyz.openbmc_project.Time.Owner.Owners.Split");
+ notifyPropertyChanged("TimeOwner",
+ "xyz.openbmc_project.Time.Owner.Owners.Split");
// Saved as requested mode/owner
EXPECT_EQ("xyz.openbmc_project.Time.Synchronization.Method.NTP",
@@ -179,9 +171,8 @@
notifyPropertyChanged(
"TimeSyncMethod",
"xyz.openbmc_project.Time.Synchronization.Method.Manual");
- notifyPropertyChanged(
- "TimeOwner",
- "xyz.openbmc_project.Time.Owner.Owners.Host");
+ notifyPropertyChanged("TimeOwner",
+ "xyz.openbmc_project.Time.Owner.Owners.Host");
// Requested mode/owner shall be updated
EXPECT_EQ("xyz.openbmc_project.Time.Synchronization.Method.Manual",
@@ -206,5 +197,5 @@
// TODO: if gmock is ready, add case to test
// updateNtpSetting() and updateNetworkSetting()
-}
-}
+} // namespace time
+} // namespace phosphor
diff --git a/test/TestUtils.cpp b/test/TestUtils.cpp
index 483e82a..1cbc852 100644
--- a/test/TestUtils.cpp
+++ b/test/TestUtils.cpp
@@ -1,8 +1,9 @@
#include "utils.hpp"
-#include <gtest/gtest.h>
#include <xyz/openbmc_project/Common/error.hpp>
+#include <gtest/gtest.h>
+
namespace phosphor
{
namespace time
@@ -14,9 +15,8 @@
TEST(TestUtil, strToMode)
{
- EXPECT_EQ(
- Mode::NTP,
- strToMode("xyz.openbmc_project.Time.Synchronization.Method.NTP"));
+ EXPECT_EQ(Mode::NTP,
+ strToMode("xyz.openbmc_project.Time.Synchronization.Method.NTP"));
EXPECT_EQ(
Mode::Manual,
strToMode("xyz.openbmc_project.Time.Synchronization.Method.Manual"));
@@ -29,7 +29,6 @@
EXPECT_THROW(strToMode("whatever"), InvalidEnumString);
}
-
TEST(TestUtil, strToOwner)
{
EXPECT_EQ(Owner::BMC,
diff --git a/test/mocked_bmc_time_change_listener.hpp b/test/mocked_bmc_time_change_listener.hpp
index 9b2c81c..364b333 100644
--- a/test/mocked_bmc_time_change_listener.hpp
+++ b/test/mocked_bmc_time_change_listener.hpp
@@ -1,16 +1,18 @@
#pragma once
-#include <gmock/gmock.h>
#include "bmc_time_change_listener.hpp"
-namespace phosphor {
-namespace time {
+#include <gmock/gmock.h>
-class MockBmcTimeChangeListener : public BmcTimeChangeListener {
- public:
- MOCK_METHOD1(onBmcTimeChanged,
- void(const std::chrono::microseconds&));
+namespace phosphor
+{
+namespace time
+{
+
+class MockBmcTimeChangeListener : public BmcTimeChangeListener
+{
+ public:
+ MOCK_METHOD1(onBmcTimeChanged, void(const std::chrono::microseconds&));
};
-} // namespace time
-} // namespace phosphor
-
+} // namespace time
+} // namespace phosphor
diff --git a/test/mocked_property_change_listener.hpp b/test/mocked_property_change_listener.hpp
index d581dd3..5d7a3b5 100644
--- a/test/mocked_property_change_listener.hpp
+++ b/test/mocked_property_change_listener.hpp
@@ -1,17 +1,19 @@
#pragma once
-#include <gmock/gmock.h>
#include "property_change_listener.hpp"
-namespace phosphor {
-namespace time {
+#include <gmock/gmock.h>
-class MockPropertyChangeListner : public PropertyChangeListner {
- public:
- MOCK_METHOD1(onModeChanged,
- void(Mode mode));
- MOCK_METHOD1(onOwnerChanged,
- void(Owner owner));
+namespace phosphor
+{
+namespace time
+{
+
+class MockPropertyChangeListner : public PropertyChangeListner
+{
+ public:
+ MOCK_METHOD1(onModeChanged, void(Mode mode));
+ MOCK_METHOD1(onOwnerChanged, void(Owner owner));
};
-} // namespace time
-} // namespace phosphor
+} // namespace time
+} // namespace phosphor
diff --git a/types.hpp b/types.hpp
index e4c2888..0e78432 100644
--- a/types.hpp
+++ b/types.hpp
@@ -7,43 +7,42 @@
{
namespace time
{
- /** @brief Alias to time sync mode class */
- using ModeSetting =
- sdbusplus::xyz::openbmc_project::Time::server::Synchronization;
+/** @brief Alias to time sync mode class */
+using ModeSetting =
+ sdbusplus::xyz::openbmc_project::Time::server::Synchronization;
- /** @brief Alias to time owner class */
- using OwnerSetting = sdbusplus::xyz::openbmc_project::Time::server::Owner;
+/** @brief Alias to time owner class */
+using OwnerSetting = sdbusplus::xyz::openbmc_project::Time::server::Owner;
- /** @brief Supported time sync modes
- * NTP Time sourced by Network Time Server
- * Manual User of the system need to set the time
- */
- using Mode = ModeSetting::Method;
+/** @brief Supported time sync modes
+ * NTP Time sourced by Network Time Server
+ * Manual User of the system need to set the time
+ */
+using Mode = ModeSetting::Method;
- /** @brief Supported time owners
- * BMC Time source may be NTP or Manual but it has to be set natively
- * on the BMC. Meaning, host can not set the time. What it also
- * means is that when BMC gets IPMI_SET_SEL_TIME, then its ignored.
- * similarly, when BMC gets IPMI_GET_SEL_TIME, then the BMC's time
- * is returned.
- *
- * Host Its only IPMI_SEL_SEL_TIME that will set the time on BMC.
- * Meaning, IPMI_GET_SEL_TIME and request to get BMC time will
- * result in same value.
- *
- * Split Both BMC and Host will maintain their individual clocks but then
- * the time information is stored in BMC. BMC can have either NTP
- * or Manual as it's source of time and will set the time directly
- * on the BMC. When IPMI_SET_SEL_TIME is received, then the delta
- * between that and BMC's time is calculated and is stored.
- * When BMC reads the time, the current time is returned.
- * When IPMI_GET_SEL_TIME is received, BMC's time is retrieved and
- * then the delta offset is factored in prior to returning.
- *
- * Both: BMC's time is set with whoever that sets the time. Similarly,
- * BMC's time is returned to whoever that asks the time.
- */
- using Owner = OwnerSetting::Owners;
-}
-}
-
+/** @brief Supported time owners
+ * BMC Time source may be NTP or Manual but it has to be set natively
+ * on the BMC. Meaning, host can not set the time. What it also
+ * means is that when BMC gets IPMI_SET_SEL_TIME, then its ignored.
+ * similarly, when BMC gets IPMI_GET_SEL_TIME, then the BMC's time
+ * is returned.
+ *
+ * Host Its only IPMI_SEL_SEL_TIME that will set the time on BMC.
+ * Meaning, IPMI_GET_SEL_TIME and request to get BMC time will
+ * result in same value.
+ *
+ * Split Both BMC and Host will maintain their individual clocks but then
+ * the time information is stored in BMC. BMC can have either NTP
+ * or Manual as it's source of time and will set the time directly
+ * on the BMC. When IPMI_SET_SEL_TIME is received, then the delta
+ * between that and BMC's time is calculated and is stored.
+ * When BMC reads the time, the current time is returned.
+ * When IPMI_GET_SEL_TIME is received, BMC's time is retrieved and
+ * then the delta offset is factored in prior to returning.
+ *
+ * Both: BMC's time is set with whoever that sets the time. Similarly,
+ * BMC's time is returned to whoever that asks the time.
+ */
+using Owner = OwnerSetting::Owners;
+} // namespace time
+} // namespace phosphor
diff --git a/utils.cpp b/utils.cpp
index 48bae22..4df1910 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -2,7 +2,6 @@
#include <phosphor-logging/log.hpp>
-
namespace phosphor
{
namespace time
@@ -13,21 +12,18 @@
constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
-}
+} // namespace
namespace utils
{
using namespace phosphor::logging;
-std::string getService(sdbusplus::bus::bus& bus,
- const char* path,
+std::string getService(sdbusplus::bus::bus& bus, const char* path,
const char* interface)
{
- auto mapper = bus.new_method_call(MAPPER_BUSNAME,
- MAPPER_PATH,
- MAPPER_INTERFACE,
- "GetObject");
+ auto mapper = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
+ MAPPER_INTERFACE, "GetObject");
mapper.append(path, std::vector<std::string>({interface}));
try
@@ -42,15 +38,15 @@
log<level::ERR>("Error reading mapper response");
throw std::runtime_error("Error reading mapper response");
}
- if (mapperResponse.size() < 1){
+ if (mapperResponse.size() < 1)
+ {
return "";
}
return mapperResponse[0].first;
}
catch (const sdbusplus::exception::SdBusError& ex)
{
- log<level::ERR>("Mapper call failed",
- entry("METHOD=%d", "GetObject"),
+ log<level::ERR>("Mapper call failed", entry("METHOD=%d", "GetObject"),
entry("PATH=%s", path),
entry("INTERFACE=%s", interface));
throw std::runtime_error("Mapper call failed");
@@ -69,12 +65,14 @@
std::string modeToStr(Mode mode)
{
- return sdbusplus::xyz::openbmc_project::Time::server::convertForMessage(mode);
+ return sdbusplus::xyz::openbmc_project::Time::server::convertForMessage(
+ mode);
}
std::string ownerToStr(Owner owner)
{
- return sdbusplus::xyz::openbmc_project::Time::server::convertForMessage(owner);
+ return sdbusplus::xyz::openbmc_project::Time::server::convertForMessage(
+ owner);
}
} // namespace utils
diff --git a/utils.hpp b/utils.hpp
index ac71fba..efcd50c 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -2,11 +2,10 @@
#include "types.hpp"
+#include <fstream>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
-#include <fstream>
-
namespace phosphor
{
namespace time
@@ -60,16 +59,11 @@
* @return The value of the property
*/
template <typename T>
-T getProperty(sdbusplus::bus::bus& bus,
- const char* service,
- const char* path,
- const char* interface,
- const char* propertyName)
+T getProperty(sdbusplus::bus::bus& bus, const char* service, const char* path,
+ const char* interface, const char* propertyName)
{
- auto method = bus.new_method_call(service,
- path,
- "org.freedesktop.DBus.Properties",
- "Get");
+ auto method = bus.new_method_call(service, path,
+ "org.freedesktop.DBus.Properties", "Get");
method.append(interface, propertyName);
try
{
@@ -80,8 +74,7 @@
}
catch (const sdbusplus::exception::SdBusError& ex)
{
- log<level::ERR>("GetProperty call failed",
- entry("PATH=%s", path),
+ log<level::ERR>("GetProperty call failed", entry("PATH=%s", path),
entry("INTERFACE=%s", interface),
entry("PROPERTY=%s", propertyName));
throw std::runtime_error("GetProperty call failed");
@@ -96,8 +89,7 @@
*
* @return The name of the service
*/
-std::string getService(sdbusplus::bus::bus& bus,
- const char* path,
+std::string getService(sdbusplus::bus::bus& bus, const char* path,
const char* interface);
/** @brief Convert a string to enum Mode