John Wang | ad6a9b6 | 2024-06-04 15:20:22 +0800 | [diff] [blame^] | 1 | #include <ipmid/api-types.hpp> |
| 2 | #include <ipmid/utils.hpp> |
| 3 | #include <phosphor-logging/lg2.hpp> |
| 4 | |
| 5 | namespace ipmi |
| 6 | { |
| 7 | namespace iei |
| 8 | { |
| 9 | |
| 10 | Cc getAllDbusObjects(ipmi::Context::ptr ctx, const std::string& serviceRoot, |
| 11 | const std::string& interface, ObjectTree& objectTree); |
| 12 | |
| 13 | Cc getService(ipmi::Context::ptr ctx, const std::string& interface, |
| 14 | const std::string& path, std::string& service); |
| 15 | |
| 16 | Cc 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 | |
| 20 | Cc setDbusProperty(ipmi::Context::ptr ctx, const std::string& objPath, |
| 21 | const std::string interface, const std::string property, |
| 22 | const Value& value); |
| 23 | |
| 24 | Cc getAllDbusProperties(Context::ptr ctx, const std::string& service, |
| 25 | const std::string& objPath, |
| 26 | const std::string& interface, PropertyMap& properties); |
| 27 | |
| 28 | template <typename Type> |
| 29 | Cc 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 | |
| 46 | template <typename Type> |
| 47 | Cc 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 | |
| 62 | template <typename... InputArgs> |
| 63 | void 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 | |
| 82 | template <typename RetType, typename... InputArgs> |
| 83 | RetType 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 |