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