1 /*
2 // Copyright (c) 2017 2018 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 <iostream>
20 #include <ipmid/api.hpp>
21 #include <sdbusplus/bus.hpp>
22 #include <string>
23 #include <utility>
24 #include <vector>
25 
26 static constexpr bool debug = false;
27 
28 inline static void printRegistration(unsigned int netfn, unsigned int cmd)
29 {
30     if constexpr (debug)
31     {
32         std::cout << "Registering NetFn:[0x" << std::hex << std::uppercase
33                   << netfn << "], Cmd:[0x" << cmd << "]\n";
34     }
35 }
36 
37 inline static void ipmiPrintAndRegister(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
38                                         ipmi_context_t context,
39                                         ipmid_callback_t handler,
40                                         ipmi_cmd_privilege_t priv)
41 {
42     printRegistration(netfn, cmd);
43     ipmi_register_callback(netfn, cmd, context, handler, priv);
44 }
45 
46 inline static void printCommand(unsigned int netfn, unsigned int cmd)
47 {
48     if constexpr (debug)
49     {
50         std::cout << "Executing NetFn:[0x" << std::hex << std::uppercase
51                   << netfn << "], Cmd:[0x" << cmd << "]\n";
52     }
53 }
54 
55 namespace ipmi
56 {
57 using DbusVariant =
58     sdbusplus::message::variant<std::string, bool, uint8_t, uint16_t, int16_t,
59                                 uint32_t, int32_t, uint64_t, int64_t, double>;
60 using GetSubTreeType = std::vector<
61     std::pair<std::string,
62               std::vector<std::pair<std::string, std::vector<std::string>>>>>;
63 } // namespace ipmi
64