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 <ipmid/api.hpp>
20 #include <sdbusplus/bus.hpp>
21 
22 #include <iostream>
23 #include <map>
24 #include <string>
25 #include <tuple>
26 #include <utility>
27 #include <vector>
28 
29 static constexpr bool debug = false;
30 
printRegistration(unsigned int netfn,unsigned int cmd)31 inline static void printRegistration(unsigned int netfn, unsigned int cmd)
32 {
33     if constexpr (debug)
34     {
35         std::cout << "Registering NetFn:[0x" << std::hex << std::uppercase
36                   << netfn << "], Cmd:[0x" << cmd << "]\n";
37     }
38 }
39 
ipmiPrintAndRegister(ipmi_netfn_t netfn,ipmi_cmd_t cmd,ipmi_context_t context,ipmid_callback_t handler,ipmi_cmd_privilege_t priv)40 inline static void ipmiPrintAndRegister(
41     ipmi_netfn_t netfn, ipmi_cmd_t cmd, ipmi_context_t context,
42     ipmid_callback_t handler, ipmi_cmd_privilege_t priv)
43 {
44     printRegistration(netfn, cmd);
45     ipmi_register_callback(netfn, cmd, context, handler, priv);
46 }
47 
printCommand(unsigned int netfn,unsigned int cmd)48 inline static void printCommand(unsigned int netfn, unsigned int cmd)
49 {
50     if constexpr (debug)
51     {
52         std::cout << "Executing NetFn:[0x" << std::hex << std::uppercase
53                   << netfn << "], Cmd:[0x" << cmd << "]\n";
54     }
55 }
56