blob: cc9a0e604d6f5a8f3826da2c28e97d4846c5c959 [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>
Cheng C Yang58b2b532019-05-31 00:19:45 +080020#include <sdbusplus/asio/object_server.hpp>
James Feist38fb5982020-05-28 10:09:54 -070021
22#include <memory>
Patrick Venturefd6ba732019-10-31 14:27:39 -070023#include <set>
24#include <string>
25#include <vector>
Cheng C Yang58b2b532019-05-31 00:19:45 +080026
Yong Libf8b1da2020-04-15 16:32:50 +080027class PSUSubEvent : public std::enable_shared_from_this<PSUSubEvent>
Cheng C Yang58b2b532019-05-31 00:19:45 +080028{
29 public:
30 PSUSubEvent(std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface,
Yong Li3046a022020-04-03 13:01:02 +080031 const std::string& path,
32 std::shared_ptr<sdbusplus::asio::connection>& conn,
33 boost::asio::io_service& io, const std::string& groupEventName,
34 const std::string& eventName,
Cheng C Yang58b2b532019-05-31 00:19:45 +080035 std::shared_ptr<std::set<std::string>> asserts,
36 std::shared_ptr<std::set<std::string>> combineEvent,
Cheng C Yang5665db22019-07-12 00:57:30 +080037 std::shared_ptr<bool> state, const std::string& psuName);
Cheng C Yang58b2b532019-05-31 00:19:45 +080038 ~PSUSubEvent();
39
40 std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
41 std::shared_ptr<std::set<std::string>> asserts;
42 std::shared_ptr<std::set<std::string>> combineEvent;
43 std::shared_ptr<bool> assertState;
Yong Libf8b1da2020-04-15 16:32:50 +080044 void setupRead(void);
Cheng C Yang58b2b532019-05-31 00:19:45 +080045
46 private:
47 int value = 0;
Cheng C Yanga97f1342020-02-11 15:10:41 +080048 int fd;
Brad Bishopfbb44ad2019-11-08 09:42:37 -050049 size_t errCount;
Cheng C Yang58b2b532019-05-31 00:19:45 +080050 std::string path;
51 std::string eventName;
Cheng C Yang202a1ff2020-01-09 09:34:22 +080052 std::string groupEventName;
Cheng C Yang58b2b532019-05-31 00:19:45 +080053 boost::asio::deadline_timer waitTimer;
Yong Libf8b1da2020-04-15 16:32:50 +080054 std::shared_ptr<boost::asio::streambuf> readBuf;
Cheng C Yang58b2b532019-05-31 00:19:45 +080055 void handleResponse(const boost::system::error_code& err);
56 void updateValue(const int& newValue);
Yong Li3046a022020-04-03 13:01:02 +080057 void beep(const uint8_t& beepPriority);
58 static constexpr uint8_t beepPSUFailure = 2;
Cheng C Yang58b2b532019-05-31 00:19:45 +080059 boost::asio::posix::stream_descriptor inputDev;
60 static constexpr unsigned int eventPollMs = 1000;
61 static constexpr size_t warnAfterErrorCount = 10;
Cheng C Yang5665db22019-07-12 00:57:30 +080062 std::string psuName;
63 std::string fanName;
Cheng C Yang9b53a622019-08-27 22:13:58 +080064 std::string assertMessage;
65 std::string deassertMessage;
Yong Li3046a022020-04-03 13:01:02 +080066 std::shared_ptr<sdbusplus::asio::connection> systemBus;
Cheng C Yang58b2b532019-05-31 00:19:45 +080067};
68
69class PSUCombineEvent
70{
71 public:
72 PSUCombineEvent(
73 sdbusplus::asio::object_server& objectSever,
Yong Li3046a022020-04-03 13:01:02 +080074 std::shared_ptr<sdbusplus::asio::connection>& conn,
Cheng C Yang58b2b532019-05-31 00:19:45 +080075 boost::asio::io_service& io, const std::string& psuName,
76 boost::container::flat_map<std::string, std::vector<std::string>>&
77 eventPathList,
Cheng C Yang202a1ff2020-01-09 09:34:22 +080078 boost::container::flat_map<
79 std::string,
80 boost::container::flat_map<std::string, std::vector<std::string>>>&
81 groupEventPathList,
Cheng C Yang58b2b532019-05-31 00:19:45 +080082 const std::string& combineEventName);
83 ~PSUCombineEvent();
84
85 sdbusplus::asio::object_server& objServer;
86 std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
87 boost::container::flat_map<std::string,
Yong Libf8b1da2020-04-15 16:32:50 +080088 std::vector<std::shared_ptr<PSUSubEvent>>>
Cheng C Yang58b2b532019-05-31 00:19:45 +080089 events;
90 std::vector<std::shared_ptr<std::set<std::string>>> asserts;
91 std::vector<std::shared_ptr<bool>> states;
92};