blob: ebf496226312de31cfcc9f6fbadda1825850f6ce [file] [log] [blame]
Patrick Venture863b9242018-03-08 08:29:23 -08001#pragma once
2
3#include <map>
4#include <memory>
5#include <string>
6#include <vector>
7
8#include <sdbusplus/bus.hpp>
9#include <sdbusplus/server.hpp>
10
11#include "sensors/sensor.hpp"
12
13
14/*
15 * The SensorManager holds all sensors across all zones.
16 */
17class SensorManager
18{
19 public:
Patrick Venturefe75b192018-06-08 11:19:43 -070020 SensorManager(sdbusplus::bus::bus&& pass, sdbusplus::bus::bus&& host)
21 : _passiveListeningBus(std::move(pass)),
22 _hostSensorBus(std::move(host))
Patrick Venture863b9242018-03-08 08:29:23 -080023 {
Patrick Venturefe75b192018-06-08 11:19:43 -070024 // manager gets its interface from the bus. :D
Patrick Venture863b9242018-03-08 08:29:23 -080025 sdbusplus::server::manager::manager(_hostSensorBus, SensorRoot);
26 }
27
Patrick Venturefe75b192018-06-08 11:19:43 -070028 SensorManager()
29 : SensorManager(std::move(sdbusplus::bus::new_default()),
30 std::move(sdbusplus::bus::new_default()))
31 {
32 }
33
34 ~SensorManager() = default;
35 SensorManager(const SensorManager&) = delete;
36 SensorManager& operator=(const SensorManager&) = delete;
37 SensorManager(SensorManager&&) = default;
38 SensorManager& operator=(SensorManager&&) = default;
39
Patrick Venture863b9242018-03-08 08:29:23 -080040 /*
41 * Add a Sensor to the Manager.
42 */
43 void addSensor(
44 std::string type,
45 std::string name,
Patrick Venture5e929092018-06-08 10:55:23 -070046 std::unique_ptr<Sensor> sensor);
Patrick Venture863b9242018-03-08 08:29:23 -080047
48 // TODO(venture): Should implement read/write by name.
Patrick Venturea58197c2018-06-11 15:29:45 -070049 Sensor* getSensor(const std::string& name) const
Patrick Venture863b9242018-03-08 08:29:23 -080050 {
Patrick Venturea58197c2018-06-11 15:29:45 -070051 return _sensorMap.at(name).get();
Patrick Venture863b9242018-03-08 08:29:23 -080052 }
53
54 sdbusplus::bus::bus& getPassiveBus(void)
55 {
56 return _passiveListeningBus;
57 }
58
59 sdbusplus::bus::bus& getHostBus(void)
60 {
61 return _hostSensorBus;
62 }
63
64 private:
65 std::map<std::string, std::unique_ptr<Sensor>> _sensorMap;
66 std::map<std::string, std::vector<std::string>> _sensorTypeList;
67
68 sdbusplus::bus::bus _passiveListeningBus;
69 sdbusplus::bus::bus _hostSensorBus;
Patrick Venturefe75b192018-06-08 11:19:43 -070070
71 static constexpr auto SensorRoot = "/xyz/openbmc_project/extsensors";
Patrick Venture863b9242018-03-08 08:29:23 -080072};
73