blob: 4756cad8b516b78788d664e240eeeb9edff1ab12 [file] [log] [blame]
Vijay Khemka7452a862020-08-11 16:01:23 -07001#include "dbusUtils.hpp"
2
3#include <sdbusplus/bus.hpp>
Vijay Khemka51f898e2020-09-09 22:24:18 -07004#include <sdbusplus/server.hpp>
Vijay Khemka7452a862020-08-11 16:01:23 -07005
6const char* sensorIntf = "xyz.openbmc_project.Sensor.Value";
7
Vijay Khemka51f898e2020-09-09 22:24:18 -07008int handleDbusSignal(sd_bus_message* msg, void* usrData, sd_bus_error* err);
9
Vijay Khemka7452a862020-08-11 16:01:23 -070010class DbusSensor
11{
12 public:
13 DbusSensor() = delete;
14 virtual ~DbusSensor() = default;
15
16 /** @brief Constructs DbusSensor
17 *
18 * @param[in] bus - Handle to system dbus
19 * @param[in] path - The Dbus path of sensor
20 */
Vijay Khemka51f898e2020-09-09 22:24:18 -070021 DbusSensor(sdbusplus::bus::bus& bus, const std::string& path, void* ctx) :
22 bus(bus), path(path),
23 signal(
24 bus,
25 sdbusplus::bus::match::rules::propertiesChanged(path, sensorIntf),
26 handleDbusSignal, ctx)
Vijay Khemka7452a862020-08-11 16:01:23 -070027 {
28 servName = getService(bus, path, sensorIntf);
29 }
30
31 /** @brief Get sensor value property from D-bus interface */
32 double getSensorValue()
33 {
34 return getDbusProperty<double>(bus, servName, path, sensorIntf,
35 "Value");
36 }
37
38 private:
39 /** @brief sdbusplus bus client connection. */
40 sdbusplus::bus::bus& bus;
41 /** @brief complete path for sensor */
42 std::string path;
43 /** @brief service name for the sensor daemon */
44 std::string servName;
Vijay Khemka51f898e2020-09-09 22:24:18 -070045 /** @brief signal for sensor value change */
46 sdbusplus::server::match::match signal;
Vijay Khemka7452a862020-08-11 16:01:23 -070047};