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