blob: 71fd5d08c2142504784fee9afec92c56d6690f75 [file] [log] [blame]
Cheng C Yang58b2b532019-05-31 00:19:45 +08001/*
2// Copyright (c) 2019 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
17#pragma once
18
Patrick Venturefd6ba732019-10-31 14:27:39 -070019#include <boost/container/flat_map.hpp>
20#include <memory>
Cheng C Yang58b2b532019-05-31 00:19:45 +080021#include <sdbusplus/asio/object_server.hpp>
Patrick Venturefd6ba732019-10-31 14:27:39 -070022#include <set>
23#include <string>
24#include <vector>
Cheng C Yang58b2b532019-05-31 00:19:45 +080025
26class PSUSubEvent
27{
28 public:
29 PSUSubEvent(std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface,
30 const std::string& path, boost::asio::io_service& io,
Cheng C Yang202a1ff2020-01-09 09:34:22 +080031 const std::string& groupEventName, const std::string& eventName,
Cheng C Yang58b2b532019-05-31 00:19:45 +080032 std::shared_ptr<std::set<std::string>> asserts,
33 std::shared_ptr<std::set<std::string>> combineEvent,
Cheng C Yang5665db22019-07-12 00:57:30 +080034 std::shared_ptr<bool> state, const std::string& psuName);
Cheng C Yang58b2b532019-05-31 00:19:45 +080035 ~PSUSubEvent();
36
37 std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
38 std::shared_ptr<std::set<std::string>> asserts;
39 std::shared_ptr<std::set<std::string>> combineEvent;
40 std::shared_ptr<bool> assertState;
41
42 private:
43 int value = 0;
Brad Bishopfbb44ad2019-11-08 09:42:37 -050044 size_t errCount;
Cheng C Yang58b2b532019-05-31 00:19:45 +080045 std::string path;
46 std::string eventName;
Cheng C Yang202a1ff2020-01-09 09:34:22 +080047 std::string groupEventName;
Cheng C Yang58b2b532019-05-31 00:19:45 +080048 boost::asio::deadline_timer waitTimer;
49 boost::asio::streambuf readBuf;
50 void setupRead(void);
51 void handleResponse(const boost::system::error_code& err);
52 void updateValue(const int& newValue);
53 boost::asio::posix::stream_descriptor inputDev;
54 static constexpr unsigned int eventPollMs = 1000;
55 static constexpr size_t warnAfterErrorCount = 10;
Cheng C Yang5665db22019-07-12 00:57:30 +080056 std::string psuName;
57 std::string fanName;
Cheng C Yang9b53a622019-08-27 22:13:58 +080058 std::string assertMessage;
59 std::string deassertMessage;
Cheng C Yang58b2b532019-05-31 00:19:45 +080060};
61
62class PSUCombineEvent
63{
64 public:
65 PSUCombineEvent(
66 sdbusplus::asio::object_server& objectSever,
67 boost::asio::io_service& io, const std::string& psuName,
68 boost::container::flat_map<std::string, std::vector<std::string>>&
69 eventPathList,
Cheng C Yang202a1ff2020-01-09 09:34:22 +080070 boost::container::flat_map<
71 std::string,
72 boost::container::flat_map<std::string, std::vector<std::string>>>&
73 groupEventPathList,
Cheng C Yang58b2b532019-05-31 00:19:45 +080074 const std::string& combineEventName);
75 ~PSUCombineEvent();
76
77 sdbusplus::asio::object_server& objServer;
78 std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
79 boost::container::flat_map<std::string,
80 std::vector<std::unique_ptr<PSUSubEvent>>>
81 events;
82 std::vector<std::shared_ptr<std::set<std::string>>> asserts;
83 std::vector<std::shared_ptr<bool>> states;
84};