xref: /openbmc/phosphor-fan-presence/control/functor.hpp (revision 1b4de26acb4d7732f86dcdbe78338ed944d962dd)
138a93a8aSMatthew Barth #pragma once
238a93a8aSMatthew Barth 
338a93a8aSMatthew Barth #include "types.hpp"
4336f18a5SMatthew Barth #include "sdbusplus.hpp"
538a93a8aSMatthew Barth #include <phosphor-logging/log.hpp>
638a93a8aSMatthew Barth 
738a93a8aSMatthew Barth namespace phosphor
838a93a8aSMatthew Barth {
938a93a8aSMatthew Barth namespace fan
1038a93a8aSMatthew Barth {
1138a93a8aSMatthew Barth namespace control
1238a93a8aSMatthew Barth {
1338a93a8aSMatthew Barth class Zone;
1438a93a8aSMatthew Barth 
15336f18a5SMatthew Barth using namespace phosphor::fan;
165a302576SMatthew Barth using namespace sdbusplus::bus::match;
1738a93a8aSMatthew Barth using namespace phosphor::logging;
1838a93a8aSMatthew Barth 
1938a93a8aSMatthew Barth /**
201b3e9602SMatthew Barth  * @brief Create a zone handler function object
211b3e9602SMatthew Barth  *
221b3e9602SMatthew Barth  * @param[in] handler - The handler being created
231b3e9602SMatthew Barth  *
241b3e9602SMatthew Barth  * @return - The created zone handler function object
251b3e9602SMatthew Barth  */
261b3e9602SMatthew Barth template <typename T>
271b3e9602SMatthew Barth auto make_zoneHandler(T&& handler)
281b3e9602SMatthew Barth {
291b3e9602SMatthew Barth     return ZoneHandler(std::forward<T>(handler));
301b3e9602SMatthew Barth }
311b3e9602SMatthew Barth 
321b3e9602SMatthew Barth /**
33*1b4de26aSMatthew Barth  * @brief Create a trigger function object
34*1b4de26aSMatthew Barth  *
35*1b4de26aSMatthew Barth  * @param[in] trigger - The trigger being created
36*1b4de26aSMatthew Barth  *
37*1b4de26aSMatthew Barth  * @return - The created trigger function object
38*1b4de26aSMatthew Barth  */
39*1b4de26aSMatthew Barth template <typename T>
40*1b4de26aSMatthew Barth auto make_trigger(T&& trigger)
41*1b4de26aSMatthew Barth {
42*1b4de26aSMatthew Barth    return Trigger(std::forward<T>(trigger));
43*1b4de26aSMatthew Barth }
44*1b4de26aSMatthew Barth 
45*1b4de26aSMatthew Barth /**
4638a93a8aSMatthew Barth  * @brief Create a handler function object
4738a93a8aSMatthew Barth  *
4838a93a8aSMatthew Barth  * @param[in] handler - The handler being created
4938a93a8aSMatthew Barth  *
5038a93a8aSMatthew Barth  * @return - The created handler function object
5138a93a8aSMatthew Barth  */
5238a93a8aSMatthew Barth template <typename T>
5338a93a8aSMatthew Barth auto make_handler(T&& handler)
5438a93a8aSMatthew Barth {
5538a93a8aSMatthew Barth     return Handler(std::forward<T>(handler));
5638a93a8aSMatthew Barth }
5738a93a8aSMatthew Barth 
5838a93a8aSMatthew Barth /**
5917d1fe23SMatthew Barth  * @brief Create an action function object
6017d1fe23SMatthew Barth  *
6117d1fe23SMatthew Barth  * @param[in] action - The action being created
6217d1fe23SMatthew Barth  *
6317d1fe23SMatthew Barth  * @return - The created action function object
6417d1fe23SMatthew Barth  */
6517d1fe23SMatthew Barth template <typename T>
6617d1fe23SMatthew Barth auto make_action(T&& action)
6717d1fe23SMatthew Barth {
6817d1fe23SMatthew Barth     return Action(std::forward<T>(action));
6917d1fe23SMatthew Barth }
7017d1fe23SMatthew Barth 
7117d1fe23SMatthew Barth /**
7238a93a8aSMatthew Barth  * @struct Property Changed
7338a93a8aSMatthew Barth  * @brief A match filter functor for Dbus property value changed signals
7438a93a8aSMatthew Barth  *
7538a93a8aSMatthew Barth  * @tparam T - The type of the property value
7638a93a8aSMatthew Barth  * @tparam U - The type of the handler
7738a93a8aSMatthew Barth  */
7838a93a8aSMatthew Barth template <typename T, typename U>
7938a93a8aSMatthew Barth struct PropertyChanged
8038a93a8aSMatthew Barth {
8138a93a8aSMatthew Barth     PropertyChanged() = delete;
8238a93a8aSMatthew Barth     ~PropertyChanged() = default;
8338a93a8aSMatthew Barth     PropertyChanged(const PropertyChanged&) = default;
8438a93a8aSMatthew Barth     PropertyChanged& operator=(const PropertyChanged&) = default;
8538a93a8aSMatthew Barth     PropertyChanged(PropertyChanged&&) = default;
8638a93a8aSMatthew Barth     PropertyChanged& operator=(PropertyChanged&&) = default;
87336f18a5SMatthew Barth     PropertyChanged(const char* path,
88336f18a5SMatthew Barth                     const char* iface,
8938a93a8aSMatthew Barth                     const char* property,
9038a93a8aSMatthew Barth                     U&& handler) :
91336f18a5SMatthew Barth         _path(path),
9238a93a8aSMatthew Barth         _iface(iface),
9338a93a8aSMatthew Barth         _property(property),
9438a93a8aSMatthew Barth         _handler(std::forward<U>(handler)) { }
9538a93a8aSMatthew Barth 
9638a93a8aSMatthew Barth     /** @brief Run signal handler function
9738a93a8aSMatthew Barth      *
9838a93a8aSMatthew Barth      * Extract the property from the PropertiesChanged
99336f18a5SMatthew Barth      * message (or read the property when the message is null)
100336f18a5SMatthew Barth      * and run the handler function.
10138a93a8aSMatthew Barth      */
102336f18a5SMatthew Barth     void operator()(sdbusplus::bus::bus& bus,
10338a93a8aSMatthew Barth                     sdbusplus::message::message& msg,
10438a93a8aSMatthew Barth                     Zone& zone) const
10538a93a8aSMatthew Barth     {
106336f18a5SMatthew Barth         if (msg)
107336f18a5SMatthew Barth         {
10838a93a8aSMatthew Barth             std::map<std::string, sdbusplus::message::variant<T>> properties;
109d5cfdbe0SMatthew Barth             std::string iface;
11038a93a8aSMatthew Barth 
11138a93a8aSMatthew Barth             msg.read(iface);
112d5cfdbe0SMatthew Barth             if (iface != _iface)
11338a93a8aSMatthew Barth             {
11438a93a8aSMatthew Barth                 return;
11538a93a8aSMatthew Barth             }
11638a93a8aSMatthew Barth 
11738a93a8aSMatthew Barth             msg.read(properties);
11838a93a8aSMatthew Barth             auto it = properties.find(_property);
11938a93a8aSMatthew Barth             if (it == properties.cend())
12038a93a8aSMatthew Barth             {
12138a93a8aSMatthew Barth                 log<level::ERR>("Unable to find property on interface",
12238a93a8aSMatthew Barth                                 entry("PROPERTY=%s", _property),
123e65f617cSMatthew Barth                                 entry("INTERFACE=%s", _iface),
124e65f617cSMatthew Barth                                 entry("PATH=%s", _path));
12538a93a8aSMatthew Barth                 return;
12638a93a8aSMatthew Barth             }
12738a93a8aSMatthew Barth 
1284978e06cSWilliam A. Kennington III             _handler(zone, std::forward<T>(
1294978e06cSWilliam A. Kennington III                          sdbusplus::message::variant_ns::get<T>(it->second)));
13038a93a8aSMatthew Barth         }
131336f18a5SMatthew Barth         else
132336f18a5SMatthew Barth         {
133336f18a5SMatthew Barth             try
134336f18a5SMatthew Barth             {
135766f8545SMatthew Barth                 auto val = zone.getPropertyByName<T>(_path, _iface, _property);
136336f18a5SMatthew Barth                 _handler(zone, std::forward<T>(val));
137336f18a5SMatthew Barth             }
13886be476bSMatthew Barth             catch (const sdbusplus::exception::SdBusError&)
13986be476bSMatthew Barth             {
14086be476bSMatthew Barth                 // Property will not be used unless a property changed
14186be476bSMatthew Barth                 // signal message is received for this property.
14286be476bSMatthew Barth             }
14386be476bSMatthew Barth             catch (const util::DBusError&)
144336f18a5SMatthew Barth             {
145336f18a5SMatthew Barth                 // Property will not be used unless a property changed
146336f18a5SMatthew Barth                 // signal message is received for this property.
147336f18a5SMatthew Barth             }
148336f18a5SMatthew Barth         }
149336f18a5SMatthew Barth     }
15038a93a8aSMatthew Barth 
15138a93a8aSMatthew Barth private:
152336f18a5SMatthew Barth     const char* _path;
15338a93a8aSMatthew Barth     const char* _iface;
15438a93a8aSMatthew Barth     const char* _property;
15538a93a8aSMatthew Barth     U _handler;
15638a93a8aSMatthew Barth };
15738a93a8aSMatthew Barth 
15838a93a8aSMatthew Barth /**
15938a93a8aSMatthew Barth  * @brief Used to process a Dbus property changed signal event
16038a93a8aSMatthew Barth  *
161336f18a5SMatthew Barth  * @param[in] path - Object path
162336f18a5SMatthew Barth  * @param[in] iface - Object interface
163336f18a5SMatthew Barth  * @param[in] property - Object property
16438a93a8aSMatthew Barth  * @param[in] handler - Handler function to perform
16538a93a8aSMatthew Barth  *
16638a93a8aSMatthew Barth  * @tparam T - The type of the property
16738a93a8aSMatthew Barth  * @tparam U - The type of the handler
16838a93a8aSMatthew Barth  */
16938a93a8aSMatthew Barth template <typename T, typename U>
170336f18a5SMatthew Barth auto propertySignal(const char* path,
171336f18a5SMatthew Barth                     const char* iface,
17238a93a8aSMatthew Barth                     const char* property,
17338a93a8aSMatthew Barth                     U&& handler)
17438a93a8aSMatthew Barth {
175336f18a5SMatthew Barth     return PropertyChanged<T, U>(path,
176336f18a5SMatthew Barth                                  iface,
177336f18a5SMatthew Barth                                  property,
178336f18a5SMatthew Barth                                  std::forward<U>(handler));
17938a93a8aSMatthew Barth }
18038a93a8aSMatthew Barth 
181eb639c57SMatthew Barth /**
182eb639c57SMatthew Barth  * @struct Interface Added
183eb639c57SMatthew Barth  * @brief A match filter functor for Dbus interface added signals
184eb639c57SMatthew Barth  *
185eb639c57SMatthew Barth  * @tparam T - The type of the property value
186eb639c57SMatthew Barth  * @tparam U - The type of the handler
187eb639c57SMatthew Barth  */
188eb639c57SMatthew Barth template <typename T, typename U>
189eb639c57SMatthew Barth struct InterfaceAdded
190eb639c57SMatthew Barth {
191eb639c57SMatthew Barth     InterfaceAdded() = delete;
192eb639c57SMatthew Barth     ~InterfaceAdded() = default;
193eb639c57SMatthew Barth     InterfaceAdded(const InterfaceAdded&) = default;
194eb639c57SMatthew Barth     InterfaceAdded& operator=(const InterfaceAdded&) = default;
195eb639c57SMatthew Barth     InterfaceAdded(InterfaceAdded&&) = default;
196eb639c57SMatthew Barth     InterfaceAdded& operator=(InterfaceAdded&&) = default;
197eb639c57SMatthew Barth     InterfaceAdded(const char* path,
198eb639c57SMatthew Barth                    const char* iface,
199eb639c57SMatthew Barth                    const char* property,
200eb639c57SMatthew Barth                    U&& handler) :
201eb639c57SMatthew Barth         _path(path),
202eb639c57SMatthew Barth         _iface(iface),
203eb639c57SMatthew Barth         _property(property),
204eb639c57SMatthew Barth         _handler(std::forward<U>(handler)) { }
205eb639c57SMatthew Barth 
206eb639c57SMatthew Barth     /** @brief Run signal handler function
207eb639c57SMatthew Barth      *
208eb639c57SMatthew Barth      * Extract the property from the InterfacesAdded
209eb639c57SMatthew Barth      * message and run the handler function.
210eb639c57SMatthew Barth      */
211eb639c57SMatthew Barth     void operator()(sdbusplus::bus::bus&,
212eb639c57SMatthew Barth                     sdbusplus::message::message& msg,
213eb639c57SMatthew Barth                     Zone& zone) const
214eb639c57SMatthew Barth     {
215336f18a5SMatthew Barth         if (msg)
216336f18a5SMatthew Barth         {
217eb639c57SMatthew Barth             std::map<std::string,
218eb639c57SMatthew Barth                      std::map<std::string,
219eb639c57SMatthew Barth                               sdbusplus::message::variant<T>>> intfProp;
220eb639c57SMatthew Barth             sdbusplus::message::object_path op;
221eb639c57SMatthew Barth 
222eb639c57SMatthew Barth             msg.read(op);
223d5cfdbe0SMatthew Barth             if (static_cast<const std::string&>(op) != _path)
224eb639c57SMatthew Barth             {
225eb639c57SMatthew Barth                 // Object path does not match this handler's path
226eb639c57SMatthew Barth                 return;
227eb639c57SMatthew Barth             }
228eb639c57SMatthew Barth 
229eb639c57SMatthew Barth             msg.read(intfProp);
230eb639c57SMatthew Barth             auto itIntf = intfProp.find(_iface);
231eb639c57SMatthew Barth             if (itIntf == intfProp.cend())
232eb639c57SMatthew Barth             {
233eb639c57SMatthew Barth                 // Interface not found on this handler's path
234eb639c57SMatthew Barth                 return;
235eb639c57SMatthew Barth             }
236eb639c57SMatthew Barth             auto itProp = itIntf->second.find(_property);
237eb639c57SMatthew Barth             if (itProp == itIntf->second.cend())
238eb639c57SMatthew Barth             {
239eb639c57SMatthew Barth                 // Property not found on this handler's path
240eb639c57SMatthew Barth                 return;
241eb639c57SMatthew Barth             }
242eb639c57SMatthew Barth 
2434978e06cSWilliam A. Kennington III             _handler(zone, std::forward<T>(
2444978e06cSWilliam A. Kennington III                          sdbusplus::message::variant_ns::get<T>(itProp->second)));
245eb639c57SMatthew Barth         }
246336f18a5SMatthew Barth     }
247eb639c57SMatthew Barth 
248eb639c57SMatthew Barth private:
249eb639c57SMatthew Barth     const char* _path;
250eb639c57SMatthew Barth     const char* _iface;
251eb639c57SMatthew Barth     const char* _property;
252eb639c57SMatthew Barth     U _handler;
253eb639c57SMatthew Barth };
254eb639c57SMatthew Barth 
255eb639c57SMatthew Barth /**
256eb639c57SMatthew Barth  * @brief Used to process a Dbus interface added signal event
257eb639c57SMatthew Barth  *
258eb639c57SMatthew Barth  * @param[in] path - Object path
259eb639c57SMatthew Barth  * @param[in] iface - Object interface
260eb639c57SMatthew Barth  * @param[in] property - Object property
261eb639c57SMatthew Barth  * @param[in] handler - Handler function to perform
262eb639c57SMatthew Barth  *
263eb639c57SMatthew Barth  * @tparam T - The type of the property
264eb639c57SMatthew Barth  * @tparam U - The type of the handler
265eb639c57SMatthew Barth  */
266eb639c57SMatthew Barth template <typename T, typename U>
267eb639c57SMatthew Barth auto objectSignal(const char* path,
268eb639c57SMatthew Barth                   const char* iface,
269eb639c57SMatthew Barth                   const char* property,
270eb639c57SMatthew Barth                   U&& handler)
271eb639c57SMatthew Barth {
272eb639c57SMatthew Barth     return InterfaceAdded<T, U>(path,
273eb639c57SMatthew Barth                                 iface,
274eb639c57SMatthew Barth                                 property,
275eb639c57SMatthew Barth                                 std::forward<U>(handler));
276eb639c57SMatthew Barth }
277eb639c57SMatthew Barth 
2788fa02dabSMatthew Barth /**
2791499a5c3SMatthew Barth  * @struct Interface Removed
2801499a5c3SMatthew Barth  * @brief A match filter functor for Dbus interface removed signals
2811499a5c3SMatthew Barth  *
2821499a5c3SMatthew Barth  * @tparam U - The type of the handler
2831499a5c3SMatthew Barth  */
2841499a5c3SMatthew Barth template <typename U>
2851499a5c3SMatthew Barth struct InterfaceRemoved
2861499a5c3SMatthew Barth {
2871499a5c3SMatthew Barth     InterfaceRemoved() = delete;
2881499a5c3SMatthew Barth     ~InterfaceRemoved() = default;
2891499a5c3SMatthew Barth     InterfaceRemoved(const InterfaceRemoved&) = default;
2901499a5c3SMatthew Barth     InterfaceRemoved& operator=(const InterfaceRemoved&) = default;
2911499a5c3SMatthew Barth     InterfaceRemoved(InterfaceRemoved&&) = default;
2921499a5c3SMatthew Barth     InterfaceRemoved& operator=(InterfaceRemoved&&) = default;
2931499a5c3SMatthew Barth     InterfaceRemoved(const char* path,
2941499a5c3SMatthew Barth                      const char* iface,
2951499a5c3SMatthew Barth                      U&& handler) :
2961499a5c3SMatthew Barth         _path(path),
2971499a5c3SMatthew Barth         _iface(iface),
2981499a5c3SMatthew Barth         _handler(std::forward<U>(handler)) { }
2991499a5c3SMatthew Barth 
3001499a5c3SMatthew Barth     /** @brief Run signal handler function
3011499a5c3SMatthew Barth      *
3021499a5c3SMatthew Barth      * Extract the property from the InterfacesRemoved
3031499a5c3SMatthew Barth      * message and run the handler function.
3041499a5c3SMatthew Barth      */
3051499a5c3SMatthew Barth     void operator()(sdbusplus::bus::bus&,
3061499a5c3SMatthew Barth                     sdbusplus::message::message& msg,
3071499a5c3SMatthew Barth                     Zone& zone) const
3081499a5c3SMatthew Barth     {
3091499a5c3SMatthew Barth         if (msg)
3101499a5c3SMatthew Barth         {
3111499a5c3SMatthew Barth             std::vector<std::string> intfs;
3121499a5c3SMatthew Barth             sdbusplus::message::object_path op;
3131499a5c3SMatthew Barth 
3141499a5c3SMatthew Barth             msg.read(op);
3151499a5c3SMatthew Barth             if (static_cast<const std::string&>(op) != _path)
3161499a5c3SMatthew Barth             {
3171499a5c3SMatthew Barth                 // Object path does not match this handler's path
3181499a5c3SMatthew Barth                 return;
3191499a5c3SMatthew Barth             }
3201499a5c3SMatthew Barth 
3211499a5c3SMatthew Barth             msg.read(intfs);
3221499a5c3SMatthew Barth             auto itIntf = std::find(intfs.begin(), intfs.end(), _iface);
3231499a5c3SMatthew Barth             if (itIntf == intfs.cend())
3241499a5c3SMatthew Barth             {
3251499a5c3SMatthew Barth                 // Interface not found on this handler's path
3261499a5c3SMatthew Barth                 return;
3271499a5c3SMatthew Barth             }
3281499a5c3SMatthew Barth 
3291499a5c3SMatthew Barth             _handler(zone);
3301499a5c3SMatthew Barth         }
3311499a5c3SMatthew Barth     }
3321499a5c3SMatthew Barth 
3331499a5c3SMatthew Barth private:
3341499a5c3SMatthew Barth     const char* _path;
3351499a5c3SMatthew Barth     const char* _iface;
3361499a5c3SMatthew Barth     U _handler;
3371499a5c3SMatthew Barth };
3381499a5c3SMatthew Barth 
3391499a5c3SMatthew Barth /**
3401499a5c3SMatthew Barth  * @brief Used to process a Dbus interface removed signal event
3411499a5c3SMatthew Barth  *
3421499a5c3SMatthew Barth  * @param[in] path - Object path
3431499a5c3SMatthew Barth  * @param[in] iface - Object interface
3441499a5c3SMatthew Barth  * @param[in] handler - Handler function to perform
3451499a5c3SMatthew Barth  *
3461499a5c3SMatthew Barth  * @tparam U - The type of the handler
3471499a5c3SMatthew Barth  */
3481499a5c3SMatthew Barth template <typename U>
3491499a5c3SMatthew Barth auto objectSignal(const char* path,
3501499a5c3SMatthew Barth                   const char* iface,
3511499a5c3SMatthew Barth                   U&& handler)
3521499a5c3SMatthew Barth {
3531499a5c3SMatthew Barth     return InterfaceRemoved<U>(path,
3541499a5c3SMatthew Barth                                iface,
3551499a5c3SMatthew Barth                                std::forward<U>(handler));
3561499a5c3SMatthew Barth }
3571499a5c3SMatthew Barth 
3581499a5c3SMatthew Barth /**
3598fa02dabSMatthew Barth  * @struct Name Owner Changed
3608fa02dabSMatthew Barth  * @brief A match filter functor for Dbus name owner changed signals
3618fa02dabSMatthew Barth  *
3628fa02dabSMatthew Barth  * @tparam U - The type of the handler
3638fa02dabSMatthew Barth  */
3648fa02dabSMatthew Barth template <typename U>
3658fa02dabSMatthew Barth struct NameOwnerChanged
3668fa02dabSMatthew Barth {
3678fa02dabSMatthew Barth     NameOwnerChanged() = delete;
3688fa02dabSMatthew Barth     ~NameOwnerChanged() = default;
3698fa02dabSMatthew Barth     NameOwnerChanged(const NameOwnerChanged&) = default;
3708fa02dabSMatthew Barth     NameOwnerChanged& operator=(const NameOwnerChanged&) = default;
3718fa02dabSMatthew Barth     NameOwnerChanged(NameOwnerChanged&&) = default;
3728fa02dabSMatthew Barth     NameOwnerChanged& operator=(NameOwnerChanged&&) = default;
3738fa02dabSMatthew Barth     NameOwnerChanged(const char* path,
3748fa02dabSMatthew Barth                      const char* iface,
3758fa02dabSMatthew Barth                      U&& handler) :
3768fa02dabSMatthew Barth         _path(path),
3778fa02dabSMatthew Barth         _iface(iface),
3788fa02dabSMatthew Barth         _handler(std::forward<U>(handler)) { }
3798fa02dabSMatthew Barth 
3808fa02dabSMatthew Barth     /** @brief Run signal handler function
3818fa02dabSMatthew Barth      *
3828fa02dabSMatthew Barth      * Extract the name owner from the NameOwnerChanged
3838fa02dabSMatthew Barth      * message (or read the name owner when the message is null)
3848fa02dabSMatthew Barth      * and run the handler function.
3858fa02dabSMatthew Barth      */
3868fa02dabSMatthew Barth     void operator()(sdbusplus::bus::bus& bus,
3878fa02dabSMatthew Barth                     sdbusplus::message::message& msg,
3888fa02dabSMatthew Barth                     Zone& zone) const
3898fa02dabSMatthew Barth     {
3905a302576SMatthew Barth         std::string name;
3915a302576SMatthew Barth         bool hasOwner = false;
3928fa02dabSMatthew Barth         if (msg)
3938fa02dabSMatthew Barth         {
3945a302576SMatthew Barth             // Handle NameOwnerChanged signals
3955a302576SMatthew Barth             msg.read(name);
3965a302576SMatthew Barth 
3975a302576SMatthew Barth             std::string oldOwn;
3985a302576SMatthew Barth             msg.read(oldOwn);
3995a302576SMatthew Barth 
4005a302576SMatthew Barth             std::string newOwn;
4015a302576SMatthew Barth             msg.read(newOwn);
4025a302576SMatthew Barth             if (!newOwn.empty())
4035a302576SMatthew Barth             {
4045a302576SMatthew Barth                 hasOwner = true;
4055a302576SMatthew Barth             }
4068fa02dabSMatthew Barth         }
4078fa02dabSMatthew Barth         else
4088fa02dabSMatthew Barth         {
4095a302576SMatthew Barth             try
4105a302576SMatthew Barth             {
4115a302576SMatthew Barth                 // Initialize NameOwnerChanged data store with service name
412c72b8911SMatthew Barth                 name = zone.getService(_path, _iface);
4135a302576SMatthew Barth                 hasOwner = util::SDBusPlus::callMethodAndRead<bool>(
4145a302576SMatthew Barth                         bus,
4155a302576SMatthew Barth                         "org.freedesktop.DBus",
4165a302576SMatthew Barth                         "/org/freedesktop/DBus",
4175a302576SMatthew Barth                         "org.freedesktop.DBus",
4185a302576SMatthew Barth                         "NameHasOwner",
4195a302576SMatthew Barth                         name);
4208fa02dabSMatthew Barth             }
421ba7b5feaSMatt Spinler             catch (const util::DBusMethodError& e)
4225a302576SMatthew Barth             {
4235a302576SMatthew Barth                 // Failed to get service name owner state
4245a302576SMatthew Barth                 hasOwner = false;
4255a302576SMatthew Barth             }
4265a302576SMatthew Barth         }
4275a302576SMatthew Barth 
4285a302576SMatthew Barth         _handler(zone, name, hasOwner);
4298fa02dabSMatthew Barth     }
4308fa02dabSMatthew Barth 
4318fa02dabSMatthew Barth private:
4328fa02dabSMatthew Barth     const char* _path;
4338fa02dabSMatthew Barth     const char* _iface;
4348fa02dabSMatthew Barth     U _handler;
4358fa02dabSMatthew Barth };
4368fa02dabSMatthew Barth 
4378fa02dabSMatthew Barth /**
4388fa02dabSMatthew Barth  * @brief Used to process a Dbus name owner changed signal event
4398fa02dabSMatthew Barth  *
4408fa02dabSMatthew Barth  * @param[in] path - Object path
4418fa02dabSMatthew Barth  * @param[in] iface - Object interface
4428fa02dabSMatthew Barth  * @param[in] handler - Handler function to perform
4438fa02dabSMatthew Barth  *
4448fa02dabSMatthew Barth  * @tparam U - The type of the handler
4458fa02dabSMatthew Barth  *
4468fa02dabSMatthew Barth  * @return - The NameOwnerChanged signal struct
4478fa02dabSMatthew Barth  */
4488fa02dabSMatthew Barth template <typename U>
4498fa02dabSMatthew Barth auto ownerSignal(const char* path,
4508fa02dabSMatthew Barth                  const char* iface,
4518fa02dabSMatthew Barth                  U&& handler)
4528fa02dabSMatthew Barth {
4538fa02dabSMatthew Barth     return NameOwnerChanged<U>(path,
4548fa02dabSMatthew Barth                                iface,
4558fa02dabSMatthew Barth                                std::forward<U>(handler));
4568fa02dabSMatthew Barth }
4578fa02dabSMatthew Barth 
45838a93a8aSMatthew Barth } // namespace control
45938a93a8aSMatthew Barth } // namespace fan
46038a93a8aSMatthew Barth } // namespace phosphor
461