blob: f5bc155e245ee2ffe47eb66099020db358b8e327 [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,
Yong Li3046a022020-04-03 13:01:02 +080030 const std::string& path,
31 std::shared_ptr<sdbusplus::asio::connection>& conn,
32 boost::asio::io_service& io, const std::string& groupEventName,
33 const std::string& eventName,
Cheng C Yang58b2b532019-05-31 00:19:45 +080034 std::shared_ptr<std::set<std::string>> asserts,
35 std::shared_ptr<std::set<std::string>> combineEvent,
Cheng C Yang5665db22019-07-12 00:57:30 +080036 std::shared_ptr<bool> state, const std::string& psuName);
Cheng C Yang58b2b532019-05-31 00:19:45 +080037 ~PSUSubEvent();
38
39 std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
40 std::shared_ptr<std::set<std::string>> asserts;
41 std::shared_ptr<std::set<std::string>> combineEvent;
42 std::shared_ptr<bool> assertState;
43
44 private:
45 int value = 0;
Cheng C Yanga97f1342020-02-11 15:10:41 +080046 int fd;
Brad Bishopfbb44ad2019-11-08 09:42:37 -050047 size_t errCount;
Cheng C Yang58b2b532019-05-31 00:19:45 +080048 std::string path;
49 std::string eventName;
Cheng C Yang202a1ff2020-01-09 09:34:22 +080050 std::string groupEventName;
Cheng C Yang58b2b532019-05-31 00:19:45 +080051 boost::asio::deadline_timer waitTimer;
52 boost::asio::streambuf readBuf;
53 void setupRead(void);
54 void handleResponse(const boost::system::error_code& err);
55 void updateValue(const int& newValue);
Yong Li3046a022020-04-03 13:01:02 +080056 void beep(const uint8_t& beepPriority);
57 static constexpr uint8_t beepPSUFailure = 2;
Cheng C Yang58b2b532019-05-31 00:19:45 +080058 boost::asio::posix::stream_descriptor inputDev;
59 static constexpr unsigned int eventPollMs = 1000;
60 static constexpr size_t warnAfterErrorCount = 10;
Cheng C Yang5665db22019-07-12 00:57:30 +080061 std::string psuName;
62 std::string fanName;
Cheng C Yang9b53a622019-08-27 22:13:58 +080063 std::string assertMessage;
64 std::string deassertMessage;
Yong Li3046a022020-04-03 13:01:02 +080065 std::shared_ptr<sdbusplus::asio::connection> systemBus;
Cheng C Yang58b2b532019-05-31 00:19:45 +080066};
67
68class PSUCombineEvent
69{
70 public:
71 PSUCombineEvent(
72 sdbusplus::asio::object_server& objectSever,
Yong Li3046a022020-04-03 13:01:02 +080073 std::shared_ptr<sdbusplus::asio::connection>& conn,
Cheng C Yang58b2b532019-05-31 00:19:45 +080074 boost::asio::io_service& io, const std::string& psuName,
75 boost::container::flat_map<std::string, std::vector<std::string>>&
76 eventPathList,
Cheng C Yang202a1ff2020-01-09 09:34:22 +080077 boost::container::flat_map<
78 std::string,
79 boost::container::flat_map<std::string, std::vector<std::string>>>&
80 groupEventPathList,
Cheng C Yang58b2b532019-05-31 00:19:45 +080081 const std::string& combineEventName);
82 ~PSUCombineEvent();
83
84 sdbusplus::asio::object_server& objServer;
85 std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
86 boost::container::flat_map<std::string,
87 std::vector<std::unique_ptr<PSUSubEvent>>>
88 events;
89 std::vector<std::shared_ptr<std::set<std::string>>> asserts;
90 std::vector<std::shared_ptr<bool>> states;
91};