summaryrefslogtreecommitdiffstats
path: root/dbus/dbuspassive.hpp
blob: f00a2ea31745d3cd10ee02a448c5b5242c2fc69e (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
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once

#include "conf.hpp"
#include "dbuspassiveredundancy.hpp"
#include "interfaces.hpp"
#include "util.hpp"

#include <chrono>
#include <cmath>
#include <iostream>
#include <map>
#include <memory>
#include <mutex>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/message.hpp>
#include <sdbusplus/server.hpp>
#include <set>
#include <string>
#include <tuple>
#include <vector>

int dbusHandleSignal(sd_bus_message* msg, void* data, sd_bus_error* err);

/*
 * This ReadInterface will passively listen for Value updates from whomever
 * owns the associated dbus object.
 *
 * This requires another modification in phosphor-dbus-interfaces that will
 * signal a value update every time it's read instead of only when it changes
 * to help us:
 * - ensure we're still receiving data (since we don't control the reader)
 * - simplify stale data detection
 * - simplify error detection
 */
class DbusPassive : public ReadInterface
{
  public:
    static std::unique_ptr<ReadInterface> createDbusPassive(
        sdbusplus::bus::bus& bus, const std::string& type,
        const std::string& id, DbusHelperInterface* helper,
        const conf::SensorConfig* info,
        const std::shared_ptr<DbusPassiveRedundancy>& redundancy);

    DbusPassive(sdbusplus::bus::bus& bus, const std::string& type,
                const std::string& id, DbusHelperInterface* helper,
                const struct SensorProperties& settings, bool failed,
                const std::string& path,
                const std::shared_ptr<DbusPassiveRedundancy>& redundancy);

    ReadReturn read(void) override;
    bool getFailed(void) const override;

    void setValue(double value);
    void setFailed(bool value);
    int64_t getScale(void);
    std::string getID(void);
    double getMax(void);
    double getMin(void);

  private:
    sdbusplus::bus::bus& _bus;
    sdbusplus::server::match::match _signal;
    int64_t _scale;
    std::string _id; // for debug identification
    DbusHelperInterface* _helper;

    std::mutex _lock;
    double _value = 0;
    double _max = 0;
    double _min = 0;
    bool _failed = false;

    std::string path;
    std::shared_ptr<DbusPassiveRedundancy> redundancy;
    /* The last time the value was refreshed, not necessarily changed. */
    std::chrono::high_resolution_clock::time_point _updated;
};

int handleSensorValue(sdbusplus::message::message& msg, DbusPassive* owner);
OpenPOWER on IntegriCloud