Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 1 | #include <algorithm> |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 2 | #include <org/openbmc/Associations/server.hpp> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 3 | #include <sdbusplus/exception.hpp> |
| 4 | #include <sdbusplus/server.hpp> |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 5 | |
| 6 | namespace sdbusplus |
| 7 | { |
| 8 | namespace org |
| 9 | { |
| 10 | namespace openbmc |
| 11 | { |
| 12 | namespace server |
| 13 | { |
| 14 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 15 | Associations::Associations(bus::bus& bus, const char* path) : |
| 16 | _org_openbmc_Associations_interface(bus, path, _interface, _vtable, this) |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 17 | { |
| 18 | } |
| 19 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 20 | Associations::Associations( |
| 21 | bus::bus& bus, const char* path, |
| 22 | const std::map<std::string, PropertiesVariant>& vals) : |
| 23 | Associations(bus, path) |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 24 | { |
| 25 | for (const auto& v : vals) |
| 26 | { |
| 27 | setPropertyByName(v.first, v.second); |
| 28 | } |
| 29 | } |
| 30 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 31 | auto Associations::associations() const |
| 32 | -> std::vector<std::tuple<std::string, std::string, std::string>> |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 33 | { |
| 34 | return _associations; |
| 35 | } |
| 36 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 37 | int Associations::_callback_get_associations(sd_bus* bus, const char* path, |
| 38 | const char* interface, |
| 39 | const char* property, |
| 40 | sd_bus_message* reply, |
| 41 | void* context, sd_bus_error* error) |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 42 | { |
| 43 | using sdbusplus::server::binding::details::convertForMessage; |
| 44 | |
| 45 | try |
| 46 | { |
| 47 | auto m = message::message(reply); |
| 48 | #ifndef DISABLE_TRANSACTION |
| 49 | { |
| 50 | auto tbus = m.get_bus(); |
| 51 | sdbusplus::server::transaction::Transaction t(tbus, m); |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 52 | sdbusplus::server::transaction::set_id( |
| 53 | std::hash<sdbusplus::server::transaction::Transaction>{}(t)); |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 54 | } |
| 55 | #endif |
| 56 | |
| 57 | auto o = static_cast<Associations*>(context); |
| 58 | m.append(convertForMessage(o->associations())); |
| 59 | } |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 60 | catch (sdbusplus::internal_exception_t& e) |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 61 | { |
| 62 | sd_bus_error_set_const(error, e.name(), e.description()); |
| 63 | return -EINVAL; |
| 64 | } |
| 65 | |
| 66 | return true; |
| 67 | } |
| 68 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 69 | auto Associations::associations( |
| 70 | std::vector<std::tuple<std::string, std::string, std::string>> value) |
| 71 | -> std::vector<std::tuple<std::string, std::string, std::string>> |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 72 | { |
| 73 | if (_associations != value) |
| 74 | { |
| 75 | _associations = value; |
| 76 | _org_openbmc_Associations_interface.property_changed("associations"); |
| 77 | } |
| 78 | |
| 79 | return _associations; |
| 80 | } |
| 81 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 82 | int Associations::_callback_set_associations(sd_bus* bus, const char* path, |
| 83 | const char* interface, |
| 84 | const char* property, |
| 85 | sd_bus_message* value, |
| 86 | void* context, sd_bus_error* error) |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 87 | { |
| 88 | try |
| 89 | { |
| 90 | auto m = message::message(value); |
| 91 | #ifndef DISABLE_TRANSACTION |
| 92 | { |
| 93 | auto tbus = m.get_bus(); |
| 94 | sdbusplus::server::transaction::Transaction t(tbus, m); |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 95 | sdbusplus::server::transaction::set_id( |
| 96 | std::hash<sdbusplus::server::transaction::Transaction>{}(t)); |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 97 | } |
| 98 | #endif |
| 99 | |
| 100 | auto o = static_cast<Associations*>(context); |
| 101 | |
| 102 | std::vector<std::tuple<std::string, std::string, std::string>> v{}; |
| 103 | m.read(v); |
| 104 | o->associations(v); |
| 105 | } |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 106 | catch (sdbusplus::internal_exception_t& e) |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 107 | { |
| 108 | sd_bus_error_set_const(error, e.name(), e.description()); |
| 109 | return -EINVAL; |
| 110 | } |
| 111 | |
| 112 | return true; |
| 113 | } |
| 114 | |
| 115 | namespace details |
| 116 | { |
| 117 | namespace Associations |
| 118 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 119 | static const auto _property_associations = utility::tuple_to_array( |
| 120 | message::types::type_id< |
| 121 | std::vector<std::tuple<std::string, std::string, std::string>>>()); |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 122 | } |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 123 | } // namespace details |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 124 | |
| 125 | void Associations::setPropertyByName(const std::string& name, |
| 126 | const PropertiesVariant& val) |
| 127 | { |
| 128 | if (name == "associations") |
| 129 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 130 | auto& v = message::variant_ns::get< |
| 131 | std::vector<std::tuple<std::string, std::string, std::string>>>( |
| 132 | val); |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 133 | associations(v); |
| 134 | return; |
| 135 | } |
| 136 | } |
| 137 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 138 | auto Associations::getPropertyByName(const std::string& name) |
| 139 | -> PropertiesVariant |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 140 | { |
| 141 | if (name == "associations") |
| 142 | { |
| 143 | return associations(); |
| 144 | } |
| 145 | |
| 146 | return PropertiesVariant(); |
| 147 | } |
| 148 | |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 149 | const vtable::vtable_t Associations::_vtable[] = { |
| 150 | vtable::start(), |
| 151 | vtable::property("associations", |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 152 | details::Associations::_property_associations.data(), |
| 153 | _callback_get_associations, _callback_set_associations, |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 154 | vtable::property_::emits_change), |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 155 | vtable::end()}; |
Deepak Kodihalli | 867f7aa | 2017-02-27 00:22:50 -0600 | [diff] [blame] | 156 | |
| 157 | } // namespace server |
| 158 | } // namespace openbmc |
| 159 | } // namespace org |
| 160 | } // namespace sdbusplus |