1 /*
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 #include <boost/container/flat_map.hpp>
19 #include <sdbusplus/asio/connection.hpp>
20 
21 #include <chrono>
22 #include <cstdint>
23 #include <iostream>
24 
25 namespace CR
26 {
27 
28 using BasicVariantType =
29     std::variant<std::vector<std::string>, std::vector<uint64_t>,
30                  std::vector<uint8_t>, std::string, int64_t, uint64_t, double,
31                  int32_t, uint32_t, int16_t, uint16_t, uint8_t, bool>;
32 
33 using PropertyMapType =
34     boost::container::flat_map<std::string, BasicVariantType>;
35 
36 using GetSubTreeType = std::vector<
37     std::pair<std::string,
38               std::vector<std::pair<std::string, std::vector<std::string>>>>>;
39 
40 constexpr std::chrono::microseconds dbusTimeout(5000);
41 static std::string psuEventPath = "/xyz/openbmc_project/State/Decorator/";
42 
43 enum class PSUState
44 {
45     normal,
46     acLost
47 };
48 
49 /**
50  * Getting PSU Event from PSU D-Bus interfaces
51  *
52  * @param[in] dbusConnection - D-Bus connection
53  * @param[in] psuName - PSU name such as "PSU1"
54  * @param[out] state - PSU state, normal or acLost
55  */
56 void getPSUEvent(
57     const std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
58     const std::string& psuName, PSUState& state);
59 
60 } // namespace CR
61