138a93a8aSMatthew Barth #pragma once
238a93a8aSMatthew Barth
3336f18a5SMatthew Barth #include "sdbusplus.hpp"
43e1bb274SMatthew Barth #include "types.hpp"
53b3efc50SMatthew Barth #include "zone.hpp"
63e1bb274SMatthew Barth
738a93a8aSMatthew Barth #include <phosphor-logging/log.hpp>
838a93a8aSMatthew Barth
938a93a8aSMatthew Barth namespace phosphor
1038a93a8aSMatthew Barth {
1138a93a8aSMatthew Barth namespace fan
1238a93a8aSMatthew Barth {
1338a93a8aSMatthew Barth namespace control
1438a93a8aSMatthew Barth {
1538a93a8aSMatthew Barth class Zone;
1638a93a8aSMatthew Barth
17336f18a5SMatthew Barth using namespace phosphor::fan;
185a302576SMatthew Barth using namespace sdbusplus::bus::match;
1938a93a8aSMatthew Barth using namespace phosphor::logging;
2038a93a8aSMatthew Barth
2138a93a8aSMatthew Barth /**
221b3e9602SMatthew Barth * @brief Create a zone handler function object
231b3e9602SMatthew Barth *
241b3e9602SMatthew Barth * @param[in] handler - The handler being created
251b3e9602SMatthew Barth *
261b3e9602SMatthew Barth * @return - The created zone handler function object
271b3e9602SMatthew Barth */
281b3e9602SMatthew Barth template <typename T>
make_zoneHandler(T && handler)291b3e9602SMatthew Barth auto make_zoneHandler(T&& handler)
301b3e9602SMatthew Barth {
311b3e9602SMatthew Barth return ZoneHandler(std::forward<T>(handler));
321b3e9602SMatthew Barth }
331b3e9602SMatthew Barth
341b3e9602SMatthew Barth /**
351b4de26aSMatthew Barth * @brief Create a trigger function object
361b4de26aSMatthew Barth *
371b4de26aSMatthew Barth * @param[in] trigger - The trigger being created
381b4de26aSMatthew Barth *
391b4de26aSMatthew Barth * @return - The created trigger function object
401b4de26aSMatthew Barth */
411b4de26aSMatthew Barth template <typename T>
make_trigger(T && trigger)421b4de26aSMatthew Barth auto make_trigger(T&& trigger)
431b4de26aSMatthew Barth {
441b4de26aSMatthew Barth return Trigger(std::forward<T>(trigger));
451b4de26aSMatthew Barth }
461b4de26aSMatthew Barth
471b4de26aSMatthew Barth /**
4838a93a8aSMatthew Barth * @brief Create a handler function object
4938a93a8aSMatthew Barth *
5038a93a8aSMatthew Barth * @param[in] handler - The handler being created
5138a93a8aSMatthew Barth *
5238a93a8aSMatthew Barth * @return - The created handler function object
5338a93a8aSMatthew Barth */
54926df663SMatthew Barth template <typename T, typename U>
make_handler(U && handler)55926df663SMatthew Barth auto make_handler(U&& handler)
5638a93a8aSMatthew Barth {
57926df663SMatthew Barth return T(std::forward<U>(handler));
5838a93a8aSMatthew Barth }
5938a93a8aSMatthew Barth
6038a93a8aSMatthew Barth /**
6117d1fe23SMatthew Barth * @brief Create an action function object
6217d1fe23SMatthew Barth *
6317d1fe23SMatthew Barth * @param[in] action - The action being created
6417d1fe23SMatthew Barth *
6517d1fe23SMatthew Barth * @return - The created action function object
6617d1fe23SMatthew Barth */
6717d1fe23SMatthew Barth template <typename T>
make_action(T && action)6817d1fe23SMatthew Barth auto make_action(T&& action)
6917d1fe23SMatthew Barth {
7017d1fe23SMatthew Barth return Action(std::forward<T>(action));
7117d1fe23SMatthew Barth }
7217d1fe23SMatthew Barth
7317d1fe23SMatthew Barth /**
74926df663SMatthew Barth * @struct Properties
75926df663SMatthew Barth * @brief A set of match filter functors for Dbus property values. Each
76926df663SMatthew Barth * functor provides an associated process for retrieving the value
77926df663SMatthew Barth * for a given property and providing it to the given handler function.
7838a93a8aSMatthew Barth *
7938a93a8aSMatthew Barth * @tparam T - The type of the property value
8038a93a8aSMatthew Barth * @tparam U - The type of the handler
8138a93a8aSMatthew Barth */
8238a93a8aSMatthew Barth template <typename T, typename U>
83926df663SMatthew Barth struct Properties
8438a93a8aSMatthew Barth {
85926df663SMatthew Barth Properties() = delete;
86926df663SMatthew Barth ~Properties() = default;
87926df663SMatthew Barth Properties(const Properties&) = default;
88926df663SMatthew Barth Properties& operator=(const Properties&) = default;
89926df663SMatthew Barth Properties(Properties&&) = default;
90926df663SMatthew Barth Properties& operator=(Properties&&) = default;
Propertiesphosphor::fan::control::Properties919f93bd35SMatthew Barth explicit Properties(U&& handler) :
929f93bd35SMatthew Barth _path(""), _intf(""), _prop(""), _handler(std::forward<U>(handler))
933e1bb274SMatthew Barth {}
Propertiesphosphor::fan::control::Properties943e1bb274SMatthew Barth Properties(const char* path, const char* intf, const char* prop,
9538a93a8aSMatthew Barth U&& handler) :
96*dfddd648SPatrick Williams _path(path), _intf(intf), _prop(prop),
97*dfddd648SPatrick Williams _handler(std::forward<U>(handler))
983e1bb274SMatthew Barth {}
9938a93a8aSMatthew Barth
10038a93a8aSMatthew Barth /** @brief Run signal handler function
10138a93a8aSMatthew Barth *
10238a93a8aSMatthew Barth * Extract the property from the PropertiesChanged
103926df663SMatthew Barth * message and run the handler function.
10438a93a8aSMatthew Barth */
operator ()phosphor::fan::control::Properties105a081956fSMike Capps void operator()(sdbusplus::bus_t&, sdbusplus::message_t& msg,
10638a93a8aSMatthew Barth Zone& zone) const
10738a93a8aSMatthew Barth {
108336f18a5SMatthew Barth if (msg)
109336f18a5SMatthew Barth {
110469d1366SMatthew Barth std::string intf;
111469d1366SMatthew Barth msg.read(intf);
112469d1366SMatthew Barth if (intf != _intf)
11338a93a8aSMatthew Barth {
114469d1366SMatthew Barth // Interface name does not match on object
11538a93a8aSMatthew Barth return;
11638a93a8aSMatthew Barth }
11738a93a8aSMatthew Barth
1187f4c548dSMatthew Barth std::map<std::string, PropertyVariantType> props;
119469d1366SMatthew Barth msg.read(props);
120469d1366SMatthew Barth auto it = props.find(_prop);
121469d1366SMatthew Barth if (it == props.cend())
12238a93a8aSMatthew Barth {
123469d1366SMatthew Barth // Property not included in dictionary of properties changed
12438a93a8aSMatthew Barth return;
12538a93a8aSMatthew Barth }
12638a93a8aSMatthew Barth
1277f4c548dSMatthew Barth // Retrieve the property's value applying any visitors necessary
128*dfddd648SPatrick Williams auto value =
129*dfddd648SPatrick Williams zone.getPropertyValueVisitor<T>(_intf, _prop, it->second);
1307f4c548dSMatthew Barth
1317f4c548dSMatthew Barth _handler(zone, _path, _intf, _prop, std::forward<T>(value));
13238a93a8aSMatthew Barth }
133336f18a5SMatthew Barth else
134336f18a5SMatthew Barth {
135336f18a5SMatthew Barth try
136336f18a5SMatthew Barth {
137469d1366SMatthew Barth auto val = zone.getPropertyByName<T>(_path, _intf, _prop);
138469d1366SMatthew Barth _handler(zone, _path, _intf, _prop, std::forward<T>(val));
139336f18a5SMatthew Barth }
140cb356d48SPatrick Williams catch (const sdbusplus::exception_t&)
14186be476bSMatthew Barth {
14286be476bSMatthew Barth // Property will not be used unless a property changed
14386be476bSMatthew Barth // signal message is received for this property.
14486be476bSMatthew Barth }
14586be476bSMatthew Barth catch (const util::DBusError&)
146336f18a5SMatthew Barth {
147336f18a5SMatthew Barth // Property will not be used unless a property changed
148336f18a5SMatthew Barth // signal message is received for this property.
149336f18a5SMatthew Barth }
150336f18a5SMatthew Barth }
151336f18a5SMatthew Barth }
15238a93a8aSMatthew Barth
153926df663SMatthew Barth /** @brief Run init handler function
154926df663SMatthew Barth *
155926df663SMatthew Barth * Get the property from each member object of the group
156926df663SMatthew Barth * and run the handler function.
157926df663SMatthew Barth */
operator ()phosphor::fan::control::Properties158926df663SMatthew Barth void operator()(Zone& zone, const Group& group) const
159926df663SMatthew Barth {
160926df663SMatthew Barth std::for_each(
1613e1bb274SMatthew Barth group.begin(), group.end(),
16261b73296SPatrick Williams [&zone, handler = std::move(_handler)](const auto& member) {
163926df663SMatthew Barth auto path = std::get<pathPos>(member);
164926df663SMatthew Barth auto intf = std::get<intfPos>(member);
165926df663SMatthew Barth auto prop = std::get<propPos>(member);
166926df663SMatthew Barth try
167926df663SMatthew Barth {
168926df663SMatthew Barth auto val = zone.getPropertyByName<T>(path, intf, prop);
169469d1366SMatthew Barth handler(zone, path, intf, prop, std::forward<T>(val));
170926df663SMatthew Barth }
171cb356d48SPatrick Williams catch (const sdbusplus::exception_t&)
172926df663SMatthew Barth {
173926df663SMatthew Barth // Property value not sent to handler
174926df663SMatthew Barth }
175926df663SMatthew Barth catch (const util::DBusError&)
176926df663SMatthew Barth {
177926df663SMatthew Barth // Property value not sent to handler
178926df663SMatthew Barth }
1793e1bb274SMatthew Barth });
180926df663SMatthew Barth }
181926df663SMatthew Barth
18238a93a8aSMatthew Barth private:
183336f18a5SMatthew Barth const char* _path;
184469d1366SMatthew Barth const char* _intf;
185469d1366SMatthew Barth const char* _prop;
18638a93a8aSMatthew Barth U _handler;
18738a93a8aSMatthew Barth };
18838a93a8aSMatthew Barth
18938a93a8aSMatthew Barth /**
190469d1366SMatthew Barth * @brief Used to process a Dbus properties changed signal event
19138a93a8aSMatthew Barth *
192336f18a5SMatthew Barth * @param[in] path - Object path
193469d1366SMatthew Barth * @param[in] intf - Object interface
194469d1366SMatthew Barth * @param[in] prop - Object property
19538a93a8aSMatthew Barth * @param[in] handler - Handler function to perform
19638a93a8aSMatthew Barth *
19738a93a8aSMatthew Barth * @tparam T - The type of the property
19838a93a8aSMatthew Barth * @tparam U - The type of the handler
19938a93a8aSMatthew Barth */
20038a93a8aSMatthew Barth template <typename T, typename U>
propertiesChanged(const char * path,const char * intf,const char * prop,U && handler)2013e1bb274SMatthew Barth auto propertiesChanged(const char* path, const char* intf, const char* prop,
20238a93a8aSMatthew Barth U&& handler)
20338a93a8aSMatthew Barth {
2043e1bb274SMatthew Barth return Properties<T, U>(path, intf, prop, std::forward<U>(handler));
20538a93a8aSMatthew Barth }
20638a93a8aSMatthew Barth
207eb639c57SMatthew Barth /**
208469d1366SMatthew Barth * @brief Used to get the properties of an event's group
209926df663SMatthew Barth *
210926df663SMatthew Barth * @param[in] handler - Handler function to perform
211926df663SMatthew Barth *
212469d1366SMatthew Barth * @tparam T - The type of all the properties
213926df663SMatthew Barth * @tparam U - The type of the handler
214926df663SMatthew Barth */
215926df663SMatthew Barth template <typename T, typename U>
getProperties(U && handler)216469d1366SMatthew Barth auto getProperties(U&& handler)
217926df663SMatthew Barth {
218926df663SMatthew Barth return Properties<T, U>(std::forward<U>(handler));
219926df663SMatthew Barth }
220926df663SMatthew Barth
221926df663SMatthew Barth /**
222469d1366SMatthew Barth * @struct Interfaces Added
223469d1366SMatthew Barth * @brief A match filter functor for Dbus interfaces added signals
224eb639c57SMatthew Barth *
225eb639c57SMatthew Barth * @tparam T - The type of the property value
226eb639c57SMatthew Barth * @tparam U - The type of the handler
227eb639c57SMatthew Barth */
228eb639c57SMatthew Barth template <typename T, typename U>
229469d1366SMatthew Barth struct InterfacesAdded
230eb639c57SMatthew Barth {
231469d1366SMatthew Barth InterfacesAdded() = delete;
232469d1366SMatthew Barth ~InterfacesAdded() = default;
233469d1366SMatthew Barth InterfacesAdded(const InterfacesAdded&) = default;
234469d1366SMatthew Barth InterfacesAdded& operator=(const InterfacesAdded&) = default;
235469d1366SMatthew Barth InterfacesAdded(InterfacesAdded&&) = default;
236469d1366SMatthew Barth InterfacesAdded& operator=(InterfacesAdded&&) = default;
InterfacesAddedphosphor::fan::control::InterfacesAdded2373e1bb274SMatthew Barth InterfacesAdded(const char* path, const char* intf, const char* prop,
238eb639c57SMatthew Barth U&& handler) :
239*dfddd648SPatrick Williams _path(path), _intf(intf), _prop(prop),
240*dfddd648SPatrick Williams _handler(std::forward<U>(handler))
2413e1bb274SMatthew Barth {}
242eb639c57SMatthew Barth
243eb639c57SMatthew Barth /** @brief Run signal handler function
244eb639c57SMatthew Barth *
245eb639c57SMatthew Barth * Extract the property from the InterfacesAdded
246eb639c57SMatthew Barth * message and run the handler function.
247eb639c57SMatthew Barth */
operator ()phosphor::fan::control::InterfacesAdded248cb356d48SPatrick Williams void operator()(sdbusplus::bus_t&, sdbusplus::message_t& msg,
249eb639c57SMatthew Barth Zone& zone) const
250eb639c57SMatthew Barth {
251336f18a5SMatthew Barth if (msg)
252336f18a5SMatthew Barth {
253eb639c57SMatthew Barth sdbusplus::message::object_path op;
254eb639c57SMatthew Barth
255eb639c57SMatthew Barth msg.read(op);
256d5cfdbe0SMatthew Barth if (static_cast<const std::string&>(op) != _path)
257eb639c57SMatthew Barth {
258eb639c57SMatthew Barth // Object path does not match this handler's path
259eb639c57SMatthew Barth return;
260eb639c57SMatthew Barth }
261eb639c57SMatthew Barth
2623e1bb274SMatthew Barth std::map<std::string, std::map<std::string, PropertyVariantType>>
2633e1bb274SMatthew Barth intfProp;
264eb639c57SMatthew Barth msg.read(intfProp);
265469d1366SMatthew Barth auto itIntf = intfProp.find(_intf);
266eb639c57SMatthew Barth if (itIntf == intfProp.cend())
267eb639c57SMatthew Barth {
268eb639c57SMatthew Barth // Interface not found on this handler's path
269eb639c57SMatthew Barth return;
270eb639c57SMatthew Barth }
271469d1366SMatthew Barth auto itProp = itIntf->second.find(_prop);
272eb639c57SMatthew Barth if (itProp == itIntf->second.cend())
273eb639c57SMatthew Barth {
274eb639c57SMatthew Barth // Property not found on this handler's path
275eb639c57SMatthew Barth return;
276eb639c57SMatthew Barth }
277eb639c57SMatthew Barth
2787f4c548dSMatthew Barth // Retrieve the property's value applying any visitors necessary
279*dfddd648SPatrick Williams auto value =
280*dfddd648SPatrick Williams zone.getPropertyValueVisitor<T>(_intf, _prop, itProp->second);
2817f4c548dSMatthew Barth
2827f4c548dSMatthew Barth _handler(zone, _path, _intf, _prop, std::forward<T>(value));
283eb639c57SMatthew Barth }
284336f18a5SMatthew Barth }
285eb639c57SMatthew Barth
286eb639c57SMatthew Barth private:
287eb639c57SMatthew Barth const char* _path;
288469d1366SMatthew Barth const char* _intf;
289469d1366SMatthew Barth const char* _prop;
290eb639c57SMatthew Barth U _handler;
291eb639c57SMatthew Barth };
292eb639c57SMatthew Barth
293eb639c57SMatthew Barth /**
294926df663SMatthew Barth * @brief Used to process a Dbus interfaces added signal event
295eb639c57SMatthew Barth *
296eb639c57SMatthew Barth * @param[in] path - Object path
297469d1366SMatthew Barth * @param[in] intf - Object interface
298469d1366SMatthew Barth * @param[in] prop - Object property
299eb639c57SMatthew Barth * @param[in] handler - Handler function to perform
300eb639c57SMatthew Barth *
301eb639c57SMatthew Barth * @tparam T - The type of the property
302eb639c57SMatthew Barth * @tparam U - The type of the handler
303eb639c57SMatthew Barth */
304eb639c57SMatthew Barth template <typename T, typename U>
interfacesAdded(const char * path,const char * intf,const char * prop,U && handler)3053e1bb274SMatthew Barth auto interfacesAdded(const char* path, const char* intf, const char* prop,
306eb639c57SMatthew Barth U&& handler)
307eb639c57SMatthew Barth {
3083e1bb274SMatthew Barth return InterfacesAdded<T, U>(path, intf, prop, std::forward<U>(handler));
309eb639c57SMatthew Barth }
310eb639c57SMatthew Barth
3118fa02dabSMatthew Barth /**
312469d1366SMatthew Barth * @struct Interfaces Removed
313469d1366SMatthew Barth * @brief A match filter functor for Dbus interfaces removed signals
3141499a5c3SMatthew Barth *
3151499a5c3SMatthew Barth * @tparam U - The type of the handler
3161499a5c3SMatthew Barth */
3171499a5c3SMatthew Barth template <typename U>
318469d1366SMatthew Barth struct InterfacesRemoved
3191499a5c3SMatthew Barth {
320469d1366SMatthew Barth InterfacesRemoved() = delete;
321469d1366SMatthew Barth ~InterfacesRemoved() = default;
322469d1366SMatthew Barth InterfacesRemoved(const InterfacesRemoved&) = default;
323469d1366SMatthew Barth InterfacesRemoved& operator=(const InterfacesRemoved&) = default;
324469d1366SMatthew Barth InterfacesRemoved(InterfacesRemoved&&) = default;
325469d1366SMatthew Barth InterfacesRemoved& operator=(InterfacesRemoved&&) = default;
InterfacesRemovedphosphor::fan::control::InterfacesRemoved3263e1bb274SMatthew Barth InterfacesRemoved(const char* path, const char* intf, U&& handler) :
3273e1bb274SMatthew Barth _path(path), _intf(intf), _handler(std::forward<U>(handler))
3283e1bb274SMatthew Barth {}
3291499a5c3SMatthew Barth
3301499a5c3SMatthew Barth /** @brief Run signal handler function
3311499a5c3SMatthew Barth *
332469d1366SMatthew Barth * Extract the interfaces from the InterfacesRemoved
3331499a5c3SMatthew Barth * message and run the handler function.
3341499a5c3SMatthew Barth */
operator ()phosphor::fan::control::InterfacesRemoved335cb356d48SPatrick Williams void operator()(sdbusplus::bus_t&, sdbusplus::message_t& msg,
3361499a5c3SMatthew Barth Zone& zone) const
3371499a5c3SMatthew Barth {
3381499a5c3SMatthew Barth if (msg)
3391499a5c3SMatthew Barth {
3401499a5c3SMatthew Barth std::vector<std::string> intfs;
3411499a5c3SMatthew Barth sdbusplus::message::object_path op;
3421499a5c3SMatthew Barth
3431499a5c3SMatthew Barth msg.read(op);
3441499a5c3SMatthew Barth if (static_cast<const std::string&>(op) != _path)
3451499a5c3SMatthew Barth {
3461499a5c3SMatthew Barth // Object path does not match this handler's path
3471499a5c3SMatthew Barth return;
3481499a5c3SMatthew Barth }
3491499a5c3SMatthew Barth
3501499a5c3SMatthew Barth msg.read(intfs);
351469d1366SMatthew Barth auto itIntf = std::find(intfs.begin(), intfs.end(), _intf);
3521499a5c3SMatthew Barth if (itIntf == intfs.cend())
3531499a5c3SMatthew Barth {
3541499a5c3SMatthew Barth // Interface not found on this handler's path
3551499a5c3SMatthew Barth return;
3561499a5c3SMatthew Barth }
3571499a5c3SMatthew Barth
3581499a5c3SMatthew Barth _handler(zone);
3591499a5c3SMatthew Barth }
3601499a5c3SMatthew Barth }
3611499a5c3SMatthew Barth
3621499a5c3SMatthew Barth private:
3631499a5c3SMatthew Barth const char* _path;
364469d1366SMatthew Barth const char* _intf;
3651499a5c3SMatthew Barth U _handler;
3661499a5c3SMatthew Barth };
3671499a5c3SMatthew Barth
3681499a5c3SMatthew Barth /**
369926df663SMatthew Barth * @brief Used to process a Dbus interfaces removed signal event
3701499a5c3SMatthew Barth *
3711499a5c3SMatthew Barth * @param[in] path - Object path
372469d1366SMatthew Barth * @param[in] intf - Object interface
3731499a5c3SMatthew Barth * @param[in] handler - Handler function to perform
3741499a5c3SMatthew Barth *
3751499a5c3SMatthew Barth * @tparam U - The type of the handler
3761499a5c3SMatthew Barth */
3771499a5c3SMatthew Barth template <typename U>
interfacesRemoved(const char * path,const char * intf,U && handler)3783e1bb274SMatthew Barth auto interfacesRemoved(const char* path, const char* intf, U&& handler)
3791499a5c3SMatthew Barth {
3803e1bb274SMatthew Barth return InterfacesRemoved<U>(path, intf, std::forward<U>(handler));
3811499a5c3SMatthew Barth }
3821499a5c3SMatthew Barth
3831499a5c3SMatthew Barth /**
384926df663SMatthew Barth * @struct Name Owner
385926df663SMatthew Barth * @brief A functor for Dbus name owner signals and methods
3868fa02dabSMatthew Barth *
3878fa02dabSMatthew Barth * @tparam U - The type of the handler
3888fa02dabSMatthew Barth */
3898fa02dabSMatthew Barth template <typename U>
390926df663SMatthew Barth struct NameOwner
3918fa02dabSMatthew Barth {
392926df663SMatthew Barth NameOwner() = delete;
393926df663SMatthew Barth ~NameOwner() = default;
394926df663SMatthew Barth NameOwner(const NameOwner&) = default;
395926df663SMatthew Barth NameOwner& operator=(const NameOwner&) = default;
396926df663SMatthew Barth NameOwner(NameOwner&&) = default;
397926df663SMatthew Barth NameOwner& operator=(NameOwner&&) = default;
NameOwnerphosphor::fan::control::NameOwner39861b73296SPatrick Williams explicit NameOwner(U&& handler) : _handler(std::forward<U>(handler)) {}
3998fa02dabSMatthew Barth
4008fa02dabSMatthew Barth /** @brief Run signal handler function
4018fa02dabSMatthew Barth *
4028fa02dabSMatthew Barth * Extract the name owner from the NameOwnerChanged
403926df663SMatthew Barth * message and run the handler function.
4048fa02dabSMatthew Barth */
operator ()phosphor::fan::control::NameOwner405a081956fSMike Capps void operator()(sdbusplus::bus_t&, sdbusplus::message_t& msg,
4068fa02dabSMatthew Barth Zone& zone) const
4078fa02dabSMatthew Barth {
4088fa02dabSMatthew Barth if (msg)
4098fa02dabSMatthew Barth {
4109f93bd35SMatthew Barth std::string name;
4119f93bd35SMatthew Barth bool hasOwner = false;
4129f93bd35SMatthew Barth
4135a302576SMatthew Barth // Handle NameOwnerChanged signals
4145a302576SMatthew Barth msg.read(name);
4155a302576SMatthew Barth
4165a302576SMatthew Barth std::string oldOwn;
4175a302576SMatthew Barth msg.read(oldOwn);
4185a302576SMatthew Barth
4195a302576SMatthew Barth std::string newOwn;
4205a302576SMatthew Barth msg.read(newOwn);
4215a302576SMatthew Barth if (!newOwn.empty())
4225a302576SMatthew Barth {
4235a302576SMatthew Barth hasOwner = true;
4245a302576SMatthew Barth }
425926df663SMatthew Barth _handler(zone, name, hasOwner);
4268fa02dabSMatthew Barth }
427926df663SMatthew Barth }
428926df663SMatthew Barth
operator ()phosphor::fan::control::NameOwner4293e1bb274SMatthew Barth void operator()(Zone& zone, const Group& group) const
4308fa02dabSMatthew Barth {
431926df663SMatthew Barth std::string name = "";
432926df663SMatthew Barth bool hasOwner = false;
433*dfddd648SPatrick Williams std::for_each(
434*dfddd648SPatrick Williams group.begin(), group.end(),
4353e1bb274SMatthew Barth [&zone, &group, &name, &hasOwner,
43661b73296SPatrick Williams handler = std::move(_handler)](const auto& member) {
437926df663SMatthew Barth auto path = std::get<pathPos>(member);
438926df663SMatthew Barth auto intf = std::get<intfPos>(member);
4395a302576SMatthew Barth try
4405a302576SMatthew Barth {
441926df663SMatthew Barth auto servName = zone.getService(path, intf);
442926df663SMatthew Barth if (name != servName)
443926df663SMatthew Barth {
444926df663SMatthew Barth name = servName;
4455a302576SMatthew Barth hasOwner = util::SDBusPlus::callMethodAndRead<bool>(
4463e1bb274SMatthew Barth zone.getBus(), "org.freedesktop.DBus",
4473e1bb274SMatthew Barth "/org/freedesktop/DBus", "org.freedesktop.DBus",
4483e1bb274SMatthew Barth "NameHasOwner", name);
449926df663SMatthew Barth // Update service name owner state list of a group
450926df663SMatthew Barth handler(zone, name, hasOwner);
451926df663SMatthew Barth }
4528fa02dabSMatthew Barth }
453ba7b5feaSMatt Spinler catch (const util::DBusMethodError& e)
4545a302576SMatthew Barth {
4555a302576SMatthew Barth // Failed to get service name owner state
456926df663SMatthew Barth name = "";
4575a302576SMatthew Barth hasOwner = false;
4585a302576SMatthew Barth }
4593e1bb274SMatthew Barth });
4608fa02dabSMatthew Barth }
4618fa02dabSMatthew Barth
4628fa02dabSMatthew Barth private:
4638fa02dabSMatthew Barth U _handler;
4648fa02dabSMatthew Barth };
4658fa02dabSMatthew Barth
4668fa02dabSMatthew Barth /**
4678fa02dabSMatthew Barth * @brief Used to process a Dbus name owner changed signal event
4688fa02dabSMatthew Barth *
4698fa02dabSMatthew Barth * @param[in] handler - Handler function to perform
4708fa02dabSMatthew Barth *
4718fa02dabSMatthew Barth * @tparam U - The type of the handler
4728fa02dabSMatthew Barth *
4738fa02dabSMatthew Barth * @return - The NameOwnerChanged signal struct
4748fa02dabSMatthew Barth */
4758fa02dabSMatthew Barth template <typename U>
nameOwnerChanged(U && handler)476926df663SMatthew Barth auto nameOwnerChanged(U&& handler)
4778fa02dabSMatthew Barth {
478926df663SMatthew Barth return NameOwner<U>(std::forward<U>(handler));
479926df663SMatthew Barth }
480926df663SMatthew Barth
481926df663SMatthew Barth /**
482926df663SMatthew Barth * @brief Used to process the init of a name owner event
483926df663SMatthew Barth *
484926df663SMatthew Barth * @param[in] handler - Handler function to perform
485926df663SMatthew Barth *
486926df663SMatthew Barth * @tparam U - The type of the handler
487926df663SMatthew Barth *
488926df663SMatthew Barth * @return - The NameOwnerChanged signal struct
489926df663SMatthew Barth */
490926df663SMatthew Barth template <typename U>
nameHasOwner(U && handler)491926df663SMatthew Barth auto nameHasOwner(U&& handler)
492926df663SMatthew Barth {
493926df663SMatthew Barth return NameOwner<U>(std::forward<U>(handler));
4948fa02dabSMatthew Barth }
4958fa02dabSMatthew Barth
49638a93a8aSMatthew Barth } // namespace control
49738a93a8aSMatthew Barth } // namespace fan
49838a93a8aSMatthew Barth } // namespace phosphor
499