summaryrefslogtreecommitdiffstats
path: root/epoch_base.hpp
blob: 79aca901ad7aabbbfaa9003a68f56b972c806003 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once

#include "config.h"
#include "property_change_listener.hpp"

#include <sdbusplus/bus.hpp>
#include <xyz/openbmc_project/Time/EpochTime/server.hpp>

#include <chrono>

namespace phosphor
{
namespace time
{

/** @class EpochBase
 *  @brief Base class for OpenBMC EpochTime implementation.
 *  @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
{
    public:
        friend class TestEpochBase;

        EpochBase(sdbusplus::bus::bus& bus,
                  const char* objPath);

        /** @brief Notified on time mode changed */
        void onModeChanged(Mode mode) override;

        /** @brief Notified on time owner changed */
        void onOwnerChanged(Owner owner) override;

    protected:
        /** @brief Persistent sdbusplus DBus connection */
        sdbusplus::bus::bus& bus;

        /** @brief The current time mode */
        Mode timeMode = DEFAULT_TIME_MODE;

        /** @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 Get current time
         *
         * @return Microseconds since UTC
         */
        std::chrono::microseconds getTime() const;
};

} // namespace time
} // namespace phosphor
OpenPOWER on IntegriCloud