blob: 25a7ebc04cb6d238d0e3828b90208ea4a4bdece2 [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
Konstantin Aladyshevc7a1ae62021-04-30 08:50:43 +000019#include <Utils.hpp>
James Feist8086aba2020-08-25 16:00:59 -070020#include <boost/asio/io_service.hpp>
Ed Tanous16966b52021-09-15 15:06:59 -070021#include <boost/asio/random_access_file.hpp>
Ed Tanous9b4a20e2022-09-06 08:47:11 -070022#include <boost/asio/steady_timer.hpp>
Patrick Venturefd6ba732019-10-31 14:27:39 -070023#include <boost/container/flat_map.hpp>
Cheng C Yang58b2b532019-05-31 00:19:45 +080024#include <sdbusplus/asio/object_server.hpp>
James Feist38fb5982020-05-28 10:09:54 -070025
Ed Tanous16966b52021-09-15 15:06:59 -070026#include <array>
James Feist38fb5982020-05-28 10:09:54 -070027#include <memory>
Patrick Venturefd6ba732019-10-31 14:27:39 -070028#include <set>
29#include <string>
30#include <vector>
Cheng C Yang58b2b532019-05-31 00:19:45 +080031
Yong Libf8b1da2020-04-15 16:32:50 +080032class PSUSubEvent : public std::enable_shared_from_this<PSUSubEvent>
Cheng C Yang58b2b532019-05-31 00:19:45 +080033{
34 public:
35 PSUSubEvent(std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface,
Yong Li3046a022020-04-03 13:01:02 +080036 const std::string& path,
37 std::shared_ptr<sdbusplus::asio::connection>& conn,
Ed Tanous2049bd22022-07-09 07:20:26 -070038 boost::asio::io_service& io, const PowerState& powerState,
Konstantin Aladyshevc7a1ae62021-04-30 08:50:43 +000039 const std::string& groupEventName, const std::string& eventName,
Cheng C Yang58b2b532019-05-31 00:19:45 +080040 std::shared_ptr<std::set<std::string>> asserts,
41 std::shared_ptr<std::set<std::string>> combineEvent,
Lei YU7170a232021-02-04 16:19:27 +080042 std::shared_ptr<bool> state, const std::string& psuName,
43 double pollRate);
Cheng C Yang58b2b532019-05-31 00:19:45 +080044 ~PSUSubEvent();
45
46 std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
47 std::shared_ptr<std::set<std::string>> asserts;
48 std::shared_ptr<std::set<std::string>> combineEvent;
49 std::shared_ptr<bool> assertState;
Yong Libf8b1da2020-04-15 16:32:50 +080050 void setupRead(void);
Cheng C Yang58b2b532019-05-31 00:19:45 +080051
52 private:
53 int value = 0;
Ed Tanousb429f312022-06-27 16:09:53 -070054 size_t errCount{0};
Cheng C Yang58b2b532019-05-31 00:19:45 +080055 std::string path;
56 std::string eventName;
Brad Bishopfeb19ef2019-11-07 18:02:16 -050057
Konstantin Aladyshevc7a1ae62021-04-30 08:50:43 +000058 PowerState readState;
Ed Tanous9b4a20e2022-09-06 08:47:11 -070059 boost::asio::steady_timer waitTimer;
Ed Tanous16966b52021-09-15 15:06:59 -070060 std::shared_ptr<std::array<char, 128>> buffer;
Konstantin Aladyshevc7a1ae62021-04-30 08:50:43 +000061 void restartRead();
Ed Tanous16966b52021-09-15 15:06:59 -070062 void handleResponse(const boost::system::error_code& err,
63 size_t bytesTransferred);
Cheng C Yang58b2b532019-05-31 00:19:45 +080064 void updateValue(const int& newValue);
Ed Tanous16966b52021-09-15 15:06:59 -070065 boost::asio::random_access_file inputDev;
Cheng C Yang5665db22019-07-12 00:57:30 +080066 std::string psuName;
Brad Bishopfeb19ef2019-11-07 18:02:16 -050067 std::string groupEventName;
Cheng C Yang5665db22019-07-12 00:57:30 +080068 std::string fanName;
Cheng C Yang9b53a622019-08-27 22:13:58 +080069 std::string assertMessage;
70 std::string deassertMessage;
Yong Li3046a022020-04-03 13:01:02 +080071 std::shared_ptr<sdbusplus::asio::connection> systemBus;
Lei YU7170a232021-02-04 16:19:27 +080072 unsigned int eventPollMs = defaultEventPollMs;
73 static constexpr unsigned int defaultEventPollMs = 1000;
74 static constexpr size_t warnAfterErrorCount = 10;
Cheng C Yang58b2b532019-05-31 00:19:45 +080075};
76
77class PSUCombineEvent
78{
79 public:
80 PSUCombineEvent(
Ed Tanous2049bd22022-07-09 07:20:26 -070081 sdbusplus::asio::object_server& objectServer,
Yong Li3046a022020-04-03 13:01:02 +080082 std::shared_ptr<sdbusplus::asio::connection>& conn,
Cheng C Yang58b2b532019-05-31 00:19:45 +080083 boost::asio::io_service& io, const std::string& psuName,
Konstantin Aladyshevc7a1ae62021-04-30 08:50:43 +000084 const PowerState& powerState,
Cheng C Yang58b2b532019-05-31 00:19:45 +080085 boost::container::flat_map<std::string, std::vector<std::string>>&
86 eventPathList,
Cheng C Yang202a1ff2020-01-09 09:34:22 +080087 boost::container::flat_map<
88 std::string,
89 boost::container::flat_map<std::string, std::vector<std::string>>>&
90 groupEventPathList,
Lei YU7170a232021-02-04 16:19:27 +080091 const std::string& combineEventName, double pollRate);
Cheng C Yang58b2b532019-05-31 00:19:45 +080092 ~PSUCombineEvent();
93
94 sdbusplus::asio::object_server& objServer;
95 std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
96 boost::container::flat_map<std::string,
Yong Libf8b1da2020-04-15 16:32:50 +080097 std::vector<std::shared_ptr<PSUSubEvent>>>
Cheng C Yang58b2b532019-05-31 00:19:45 +080098 events;
99 std::vector<std::shared_ptr<std::set<std::string>>> asserts;
100 std::vector<std::shared_ptr<bool>> states;
101};