blob: 25d79fd5eb159d729efe7b406f3772df6d94b476 [file] [log] [blame]
Deepak Kodihalli867f7aa2017-02-27 00:22:50 -06001#include <algorithm>
Deepak Kodihalli867f7aa2017-02-27 00:22:50 -06002#include <org/openbmc/Associations/server.hpp>
Patrick Venturef18bf832018-10-26 18:14:00 -07003#include <sdbusplus/exception.hpp>
4#include <sdbusplus/server.hpp>
Deepak Kodihalli867f7aa2017-02-27 00:22:50 -06005
6namespace sdbusplus
7{
8namespace org
9{
10namespace openbmc
11{
12namespace server
13{
14
Patrick Venturef18bf832018-10-26 18:14:00 -070015Associations::Associations(bus::bus& bus, const char* path) :
16 _org_openbmc_Associations_interface(bus, path, _interface, _vtable, this)
Deepak Kodihalli867f7aa2017-02-27 00:22:50 -060017{
18}
19
Patrick Venturef18bf832018-10-26 18:14:00 -070020Associations::Associations(
21 bus::bus& bus, const char* path,
22 const std::map<std::string, PropertiesVariant>& vals) :
23 Associations(bus, path)
Deepak Kodihalli867f7aa2017-02-27 00:22:50 -060024{
25 for (const auto& v : vals)
26 {
27 setPropertyByName(v.first, v.second);
28 }
29}
30
Patrick Venturef18bf832018-10-26 18:14:00 -070031auto Associations::associations() const
32 -> std::vector<std::tuple<std::string, std::string, std::string>>
Deepak Kodihalli867f7aa2017-02-27 00:22:50 -060033{
34 return _associations;
35}
36
Patrick Venturef18bf832018-10-26 18:14:00 -070037int 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 Kodihalli867f7aa2017-02-27 00:22:50 -060042{
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 Venturef18bf832018-10-26 18:14:00 -070052 sdbusplus::server::transaction::set_id(
53 std::hash<sdbusplus::server::transaction::Transaction>{}(t));
Deepak Kodihalli867f7aa2017-02-27 00:22:50 -060054 }
55#endif
56
57 auto o = static_cast<Associations*>(context);
58 m.append(convertForMessage(o->associations()));
59 }
Patrick Venturef18bf832018-10-26 18:14:00 -070060 catch (sdbusplus::internal_exception_t& e)
Deepak Kodihalli867f7aa2017-02-27 00:22:50 -060061 {
62 sd_bus_error_set_const(error, e.name(), e.description());
63 return -EINVAL;
64 }
65
66 return true;
67}
68
Patrick Venturef18bf832018-10-26 18:14:00 -070069auto 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 Kodihalli867f7aa2017-02-27 00:22:50 -060072{
73 if (_associations != value)
74 {
75 _associations = value;
76 _org_openbmc_Associations_interface.property_changed("associations");
77 }
78
79 return _associations;
80}
81
Patrick Venturef18bf832018-10-26 18:14:00 -070082int 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 Kodihalli867f7aa2017-02-27 00:22:50 -060087{
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 Venturef18bf832018-10-26 18:14:00 -070095 sdbusplus::server::transaction::set_id(
96 std::hash<sdbusplus::server::transaction::Transaction>{}(t));
Deepak Kodihalli867f7aa2017-02-27 00:22:50 -060097 }
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 Venturef18bf832018-10-26 18:14:00 -0700106 catch (sdbusplus::internal_exception_t& e)
Deepak Kodihalli867f7aa2017-02-27 00:22:50 -0600107 {
108 sd_bus_error_set_const(error, e.name(), e.description());
109 return -EINVAL;
110 }
111
112 return true;
113}
114
115namespace details
116{
117namespace Associations
118{
Patrick Venturef18bf832018-10-26 18:14:00 -0700119static 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 Kodihalli867f7aa2017-02-27 00:22:50 -0600122}
Patrick Venturef18bf832018-10-26 18:14:00 -0700123} // namespace details
Deepak Kodihalli867f7aa2017-02-27 00:22:50 -0600124
125void Associations::setPropertyByName(const std::string& name,
126 const PropertiesVariant& val)
127{
128 if (name == "associations")
129 {
Patrick Venturef18bf832018-10-26 18:14:00 -0700130 auto& v = message::variant_ns::get<
131 std::vector<std::tuple<std::string, std::string, std::string>>>(
132 val);
Deepak Kodihalli867f7aa2017-02-27 00:22:50 -0600133 associations(v);
134 return;
135 }
136}
137
Patrick Venturef18bf832018-10-26 18:14:00 -0700138auto Associations::getPropertyByName(const std::string& name)
139 -> PropertiesVariant
Deepak Kodihalli867f7aa2017-02-27 00:22:50 -0600140{
141 if (name == "associations")
142 {
143 return associations();
144 }
145
146 return PropertiesVariant();
147}
148
Deepak Kodihalli867f7aa2017-02-27 00:22:50 -0600149const vtable::vtable_t Associations::_vtable[] = {
150 vtable::start(),
151 vtable::property("associations",
Patrick Venturef18bf832018-10-26 18:14:00 -0700152 details::Associations::_property_associations.data(),
153 _callback_get_associations, _callback_set_associations,
Deepak Kodihalli867f7aa2017-02-27 00:22:50 -0600154 vtable::property_::emits_change),
Patrick Venturef18bf832018-10-26 18:14:00 -0700155 vtable::end()};
Deepak Kodihalli867f7aa2017-02-27 00:22:50 -0600156
157} // namespace server
158} // namespace openbmc
159} // namespace org
160} // namespace sdbusplus