blob: 231c1c94a4c026d6c52f2933a118a9389eb5dd4f [file] [log] [blame]
John Wangad6a9b62024-06-04 15:20:22 +08001#include <ipmid/api-types.hpp>
2#include <ipmid/utils.hpp>
3#include <phosphor-logging/lg2.hpp>
4
5namespace ipmi
6{
7namespace iei
8{
9
10Cc getAllDbusObjects(ipmi::Context::ptr ctx, const std::string& serviceRoot,
11 const std::string& interface, ObjectTree& objectTree);
12
13Cc getService(ipmi::Context::ptr ctx, const std::string& interface,
14 const std::string& path, std::string& service);
15
16Cc setDbusProperty(ipmi::Context::ptr ctx, const std::string& service,
17 const std::string& objPath, const std::string interface,
18 const std::string property, const Value& value);
19
20Cc setDbusProperty(ipmi::Context::ptr ctx, const std::string& objPath,
21 const std::string interface, const std::string property,
22 const Value& value);
23
24Cc getAllDbusProperties(Context::ptr ctx, const std::string& service,
25 const std::string& objPath,
26 const std::string& interface, PropertyMap& properties);
27
28template <typename Type>
29Cc getDbusProperty(Context::ptr ctx, const std::string& service,
30 const std::string& objPath, const std::string& interface,
31 const std::string& property, Type& propertyValue)
32{
33 auto ec = ipmi::getDbusProperty(ctx, service, objPath, interface, property,
34 propertyValue);
35 if (ec)
36 {
37 lg2::error(
38 "getDbusProperty for (service:{SERVICE}, path:{PATH}, interface:{INTERFACE}, property:{PROPERTY}) failed with {ERRMSG}",
39 "SERVICE", service, "PATH", objPath, "INTERFACE", interface,
40 "PROPERTY", property, "ERRMSG", ec.message());
41 return ccUnspecifiedError;
42 }
43 return ccSuccess;
44}
45
46template <typename Type>
47Cc getDbusProperty(Context::ptr ctx, const std::string& objPath,
48 const std::string& interface, const std::string& property,
49 Type& propertyValue)
50{
51 std::string service;
52 auto cc = iei::getService(ctx, interface, objPath, service);
53 if (cc != ccSuccess)
54 {
55 return cc;
56 }
57
58 return iei::getDbusProperty(ctx, service, objPath, interface, property,
59 propertyValue);
60}
61
62template <typename... InputArgs>
63void callDbusMethod(ipmi::Context::ptr ctx, Cc& cc, const std::string& service,
64 const std::string& objPath, const std::string& interface,
65 const std::string& method, const InputArgs&... a)
66{
67 boost::system::error_code ec;
68 cc = ccSuccess;
69 ctx->bus->yield_method_call(ctx->yield, ec, service, objPath, interface,
70 method, a...);
71 if (ec)
72 {
73 lg2::error(
74 "callDbusMethod for (service:{SERVICE}, path:{PATH}, interface:{INTERFACE}, method:{METHOD}) failed with {ERRMSG}",
75 "SERVICE", service, "PATH", objPath, "INTERFACE", interface,
76 "METHOD", method, "ERRMSG", ec.message());
77 cc = ccUnspecifiedError;
78 }
79 return;
80}
81
82template <typename RetType, typename... InputArgs>
83RetType callDbusMethod(ipmi::Context::ptr ctx, Cc& cc,
84 const std::string& service, const std::string& objPath,
85 const std::string& interface, const std::string& method,
86 const InputArgs&... a)
87{
88 boost::system::error_code ec;
89 cc = ccSuccess;
90 auto rc = ctx->bus->yield_method_call<RetType>(
91 ctx->yield, ec, service, objPath, interface, method, a...);
92 if (ec)
93 {
94 lg2::error(
95 "callDbusMethod for (service:{SERVICE}, path:{PATH}, interface:{INTERFACE}, method:{METHOD}) failed with {ERRMSG}",
96 "SERVICE", service, "PATH", objPath, "INTERFACE", interface,
97 "METHOD", method, "ERRMSG", ec.message());
98 cc = ccUnspecifiedError;
99 }
100 return rc;
101}
102
103} // namespace iei
104} // namespace ipmi