blob: 104b9103fa18b6c716d6b4b2562d4c9de2a6fb19 [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;
52 std::string messageID = "";
Cheng C Yang58b2b532019-05-31 00:19:45 +080053};
54
55class PSUCombineEvent
56{
57 public:
58 PSUCombineEvent(
59 sdbusplus::asio::object_server& objectSever,
60 boost::asio::io_service& io, const std::string& psuName,
61 boost::container::flat_map<std::string, std::vector<std::string>>&
62 eventPathList,
63 const std::string& combineEventName);
64 ~PSUCombineEvent();
65
66 sdbusplus::asio::object_server& objServer;
67 std::shared_ptr<sdbusplus::asio::dbus_interface> eventInterface;
68 boost::container::flat_map<std::string,
69 std::vector<std::unique_ptr<PSUSubEvent>>>
70 events;
71 std::vector<std::shared_ptr<std::set<std::string>>> asserts;
72 std::vector<std::shared_ptr<bool>> states;
73};