blob: e47670ba4a44db7e88b31d7fa30c1d518d5ba0c9 [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,
30 const std::string& path, boost::asio::io_service& io,
31 const std::string& eventName,
32 std::shared_ptr<std::set<std::string>> asserts,
33 std::shared_ptr<std::set<std::string>> combineEvent,
Cheng C Yang5665db22019-07-12 00:57:30 +080034 std::shared_ptr<bool> state, const std::string& psuName);
Cheng C Yang58b2b532019-05-31 00:19:45 +080035 ~PSUSubEvent();
36
37 std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
38 std::shared_ptr<std::set<std::string>> asserts;
39 std::shared_ptr<std::set<std::string>> combineEvent;
40 std::shared_ptr<bool> assertState;
41
42 private:
43 int value = 0;
44 int errCount;
45 std::string path;
46 std::string eventName;
47 boost::asio::deadline_timer waitTimer;
48 boost::asio::streambuf readBuf;
49 void setupRead(void);
50 void handleResponse(const boost::system::error_code& err);
51 void updateValue(const int& newValue);
52 boost::asio::posix::stream_descriptor inputDev;
53 static constexpr unsigned int eventPollMs = 1000;
54 static constexpr size_t warnAfterErrorCount = 10;
Cheng C Yang5665db22019-07-12 00:57:30 +080055 std::string psuName;
56 std::string fanName;
Cheng C Yang9b53a622019-08-27 22:13:58 +080057 std::string assertMessage;
58 std::string deassertMessage;
Cheng C Yang58b2b532019-05-31 00:19:45 +080059};
60
61class PSUCombineEvent
62{
63 public:
64 PSUCombineEvent(
65 sdbusplus::asio::object_server& objectSever,
66 boost::asio::io_service& io, const std::string& psuName,
67 boost::container::flat_map<std::string, std::vector<std::string>>&
68 eventPathList,
69 const std::string& combineEventName);
70 ~PSUCombineEvent();
71
72 sdbusplus::asio::object_server& objServer;
73 std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
74 boost::container::flat_map<std::string,
75 std::vector<std::unique_ptr<PSUSubEvent>>>
76 events;
77 std::vector<std::shared_ptr<std::set<std::string>>> asserts;
78 std::vector<std::shared_ptr<bool>> states;
79};