blob: 165ac929b9b706c692c64bc96c46543bbef97587 [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
19#include <sdbusplus/asio/object_server.hpp>
20
21class PSUSubEvent
22{
23 public:
24 PSUSubEvent(std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface,
25 const std::string& path, boost::asio::io_service& io,
26 const std::string& eventName,
27 std::shared_ptr<std::set<std::string>> asserts,
28 std::shared_ptr<std::set<std::string>> combineEvent,
Cheng C Yang5665db22019-07-12 00:57:30 +080029 std::shared_ptr<bool> state, const std::string& psuName);
Cheng C Yang58b2b532019-05-31 00:19:45 +080030 ~PSUSubEvent();
31
32 std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
33 std::shared_ptr<std::set<std::string>> asserts;
34 std::shared_ptr<std::set<std::string>> combineEvent;
35 std::shared_ptr<bool> assertState;
36
37 private:
38 int value = 0;
39 int errCount;
40 std::string path;
41 std::string eventName;
42 boost::asio::deadline_timer waitTimer;
43 boost::asio::streambuf readBuf;
44 void setupRead(void);
45 void handleResponse(const boost::system::error_code& err);
46 void updateValue(const int& newValue);
47 boost::asio::posix::stream_descriptor inputDev;
48 static constexpr unsigned int eventPollMs = 1000;
49 static constexpr size_t warnAfterErrorCount = 10;
Cheng C Yang5665db22019-07-12 00:57:30 +080050 std::string psuName;
51 std::string fanName;
Cheng C Yang9b53a622019-08-27 22:13:58 +080052 std::string assertMessage;
53 std::string deassertMessage;
Cheng C Yang58b2b532019-05-31 00:19:45 +080054};
55
56class PSUCombineEvent
57{
58 public:
59 PSUCombineEvent(
60 sdbusplus::asio::object_server& objectSever,
61 boost::asio::io_service& io, const std::string& psuName,
62 boost::container::flat_map<std::string, std::vector<std::string>>&
63 eventPathList,
64 const std::string& combineEventName);
65 ~PSUCombineEvent();
66
67 sdbusplus::asio::object_server& objServer;
68 std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
69 boost::container::flat_map<std::string,
70 std::vector<std::unique_ptr<PSUSubEvent>>>
71 events;
72 std::vector<std::shared_ptr<std::set<std::string>>> asserts;
73 std::vector<std::shared_ptr<bool>> states;
74};