blob: 8dfa3eaf7c3c51cd14f66e9f56f7b10e8fbbae41 [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
James Feist8086aba2020-08-25 16:00:59 -070019#include <boost/asio/deadline_timer.hpp>
20#include <boost/asio/io_service.hpp>
21#include <boost/asio/streambuf.hpp>
Patrick Venturefd6ba732019-10-31 14:27:39 -070022#include <boost/container/flat_map.hpp>
Cheng C Yang58b2b532019-05-31 00:19:45 +080023#include <sdbusplus/asio/object_server.hpp>
James Feist38fb5982020-05-28 10:09:54 -070024
25#include <memory>
Patrick Venturefd6ba732019-10-31 14:27:39 -070026#include <set>
27#include <string>
28#include <vector>
Cheng C Yang58b2b532019-05-31 00:19:45 +080029
Yong Libf8b1da2020-04-15 16:32:50 +080030class PSUSubEvent : public std::enable_shared_from_this<PSUSubEvent>
Cheng C Yang58b2b532019-05-31 00:19:45 +080031{
32 public:
33 PSUSubEvent(std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface,
Yong Li3046a022020-04-03 13:01:02 +080034 const std::string& path,
35 std::shared_ptr<sdbusplus::asio::connection>& conn,
36 boost::asio::io_service& io, const std::string& groupEventName,
37 const std::string& eventName,
Cheng C Yang58b2b532019-05-31 00:19:45 +080038 std::shared_ptr<std::set<std::string>> asserts,
39 std::shared_ptr<std::set<std::string>> combineEvent,
Cheng C Yang5665db22019-07-12 00:57:30 +080040 std::shared_ptr<bool> state, const std::string& psuName);
Cheng C Yang58b2b532019-05-31 00:19:45 +080041 ~PSUSubEvent();
42
43 std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
44 std::shared_ptr<std::set<std::string>> asserts;
45 std::shared_ptr<std::set<std::string>> combineEvent;
46 std::shared_ptr<bool> assertState;
Yong Libf8b1da2020-04-15 16:32:50 +080047 void setupRead(void);
Cheng C Yang58b2b532019-05-31 00:19:45 +080048
49 private:
50 int value = 0;
Cheng C Yanga97f1342020-02-11 15:10:41 +080051 int fd;
Brad Bishopfbb44ad2019-11-08 09:42:37 -050052 size_t errCount;
Cheng C Yang58b2b532019-05-31 00:19:45 +080053 std::string path;
54 std::string eventName;
Cheng C Yang202a1ff2020-01-09 09:34:22 +080055 std::string groupEventName;
Cheng C Yang58b2b532019-05-31 00:19:45 +080056 boost::asio::deadline_timer waitTimer;
Yong Libf8b1da2020-04-15 16:32:50 +080057 std::shared_ptr<boost::asio::streambuf> readBuf;
Cheng C Yang58b2b532019-05-31 00:19:45 +080058 void handleResponse(const boost::system::error_code& err);
59 void updateValue(const int& newValue);
Yong Li3046a022020-04-03 13:01:02 +080060 void beep(const uint8_t& beepPriority);
61 static constexpr uint8_t beepPSUFailure = 2;
Cheng C Yang58b2b532019-05-31 00:19:45 +080062 boost::asio::posix::stream_descriptor inputDev;
63 static constexpr unsigned int eventPollMs = 1000;
64 static constexpr size_t warnAfterErrorCount = 10;
Cheng C Yang5665db22019-07-12 00:57:30 +080065 std::string psuName;
66 std::string fanName;
Cheng C Yang9b53a622019-08-27 22:13:58 +080067 std::string assertMessage;
68 std::string deassertMessage;
Yong Li3046a022020-04-03 13:01:02 +080069 std::shared_ptr<sdbusplus::asio::connection> systemBus;
Cheng C Yang58b2b532019-05-31 00:19:45 +080070};
71
72class PSUCombineEvent
73{
74 public:
75 PSUCombineEvent(
76 sdbusplus::asio::object_server& objectSever,
Yong Li3046a022020-04-03 13:01:02 +080077 std::shared_ptr<sdbusplus::asio::connection>& conn,
Cheng C Yang58b2b532019-05-31 00:19:45 +080078 boost::asio::io_service& io, const std::string& psuName,
79 boost::container::flat_map<std::string, std::vector<std::string>>&
80 eventPathList,
Cheng C Yang202a1ff2020-01-09 09:34:22 +080081 boost::container::flat_map<
82 std::string,
83 boost::container::flat_map<std::string, std::vector<std::string>>>&
84 groupEventPathList,
Cheng C Yang58b2b532019-05-31 00:19:45 +080085 const std::string& combineEventName);
86 ~PSUCombineEvent();
87
88 sdbusplus::asio::object_server& objServer;
89 std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
90 boost::container::flat_map<std::string,
Yong Libf8b1da2020-04-15 16:32:50 +080091 std::vector<std::shared_ptr<PSUSubEvent>>>
Cheng C Yang58b2b532019-05-31 00:19:45 +080092 events;
93 std::vector<std::shared_ptr<std::set<std::string>>> asserts;
94 std::vector<std::shared_ptr<bool>> states;
95};