Run astyle
Change-Id: Iec4802e9837465a7deb1fd7fd57a2068cc18c50d
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/actions.hpp b/actions.hpp
index bac934f..c314532 100644
--- a/actions.hpp
+++ b/actions.hpp
@@ -40,12 +40,15 @@
{
/** @brief The default action. */
-inline void noop(Manager &mgr) noexcept { }
+inline void noop(Manager& mgr) noexcept { }
/** @brief Destroy an object action. */
-inline auto destroyObject(const char *path)
+inline auto destroyObject(const char* path)
{
- return [path](auto &m){m.destroyObject(path);};
+ return [path](auto & m)
+ {
+ m.destroyObject(path);
+ };
}
/** @brief Set a property action.
@@ -69,15 +72,15 @@
*/
template <typename T, typename U, typename V>
decltype(auto) setProperty(
- const char *path, const char *iface,
- U &&member, V &&value)
+ const char* path, const char* iface,
+ U&& member, V&& value)
{
// The manager is the only parameter passed to actions.
// Bind the path, interface, interface member function pointer,
// and value to a lambda. When it is called, forward the
// path, interface and value on to the manager member function.
return [path, iface, member,
- value = std::forward<V>(value)](auto &m)
+ value = std::forward<V>(value)](auto & m)
{
m.template invokeMethod<T>(
path, iface, member, value);
diff --git a/app.cpp b/app.cpp
index 6b6f562..8b3c745 100644
--- a/app.cpp
+++ b/app.cpp
@@ -20,18 +20,20 @@
#include <iostream>
#include <exception>
-int main(int argc, char *argv[])
+int main(int argc, char* argv[])
{
- try {
+ try
+ {
auto manager = phosphor::inventory::manager::Manager(
- sdbusplus::bus::new_system(),
- BUSNAME,
- INVENTORY_ROOT,
- IFACE);
+ sdbusplus::bus::new_system(),
+ BUSNAME,
+ INVENTORY_ROOT,
+ IFACE);
manager.run();
exit(EXIT_SUCCESS);
}
- catch (const std::exception &e) {
+ catch (const std::exception& e)
+ {
std::cerr << e.what() << std::endl;
}
exit(EXIT_FAILURE);
diff --git a/events.hpp b/events.hpp
index c52e668..90c1024 100644
--- a/events.hpp
+++ b/events.hpp
@@ -15,12 +15,12 @@
class Manager;
namespace details
{
-using FilterBase = holder::CallableBase<
- bool, sdbusplus::message::message&, Manager&>;
+using FilterBase = holder::CallableBase <
+ bool, sdbusplus::message::message&, Manager& >;
using FilterBasePtr = std::shared_ptr<FilterBase>;
template <typename T>
-using Filter = holder::CallableHolder<
- T, bool, sdbusplus::message::message&, Manager&>;
+using Filter = holder::CallableHolder <
+ T, bool, sdbusplus::message::message&, Manager& >;
/** @struct Event
* @brief Event object interface.
@@ -52,11 +52,11 @@
*/
struct DbusSignal final :
public Event,
- public std::tuple<const char *, FilterBasePtr>
+ public std::tuple<const char*, FilterBasePtr>
{
virtual ~DbusSignal() = default;
DbusSignal(const DbusSignal&) = default;
- DbusSignal & operator=(const DbusSignal&) = delete;
+ DbusSignal& operator=(const DbusSignal&) = delete;
DbusSignal(DbusSignal&&) = default;
DbusSignal& operator=(DbusSignal&&) = default;
@@ -65,10 +65,10 @@
* @param[in] sig - The DBus match signature.
* @param[in] filter - A DBus signal match callback filtering function.
*/
- DbusSignal(const char *sig, FilterBasePtr filter) :
+ DbusSignal(const char* sig, FilterBasePtr filter) :
Event(Type::DBUS_SIGNAL),
- std::tuple<const char *, FilterBasePtr>(
- sig, std::move(filter)) {}
+ std::tuple<const char*, FilterBasePtr>(
+ sig, std::move(filter)) {}
};
/** @brief make_filter
@@ -104,52 +104,56 @@
template <typename T, typename U>
struct PropertyCondition
{
- PropertyCondition() = delete;
- ~PropertyCondition() = default;
- PropertyCondition(const PropertyCondition&) = default;
- PropertyCondition & operator=(const PropertyCondition&) = delete;
- PropertyCondition(PropertyCondition&&) = default;
- PropertyCondition& operator=(PropertyCondition&&) = default;
- PropertyCondition(const char *iface, const char *property, U &&condition) :
- _iface(iface),
- _property(property),
- _condition(std::forward<U>(condition)) { }
+ PropertyCondition() = delete;
+ ~PropertyCondition() = default;
+ PropertyCondition(const PropertyCondition&) = default;
+ PropertyCondition& operator=(const PropertyCondition&) = delete;
+ PropertyCondition(PropertyCondition&&) = default;
+ PropertyCondition& operator=(PropertyCondition&&) = default;
+ PropertyCondition(const char* iface, const char* property, U&& condition) :
+ _iface(iface),
+ _property(property),
+ _condition(std::forward<U>(condition)) { }
- /** @brief Test a property value.
- *
- * Extract the property from the PropertiesChanged
- * message and run the condition test.
- */
- bool operator()(sdbusplus::message::message &msg, Manager &) const
- {
- std::map<
+ /** @brief Test a property value.
+ *
+ * Extract the property from the PropertiesChanged
+ * message and run the condition test.
+ */
+ bool operator()(sdbusplus::message::message& msg, Manager&) const
+ {
+ std::map <
std::string,
- sdbusplus::message::variant<T>> properties;
- const char *iface = nullptr;
+ sdbusplus::message::variant<T >> properties;
+ const char* iface = nullptr;
- msg.read(iface);
- if(strcmp(iface, _iface))
+ msg.read(iface);
+ if (strcmp(iface, _iface))
+ {
return false;
+ }
- msg.read(properties);
- auto it = properties.find(_property);
- if(it == properties.cend())
- return false;
+ msg.read(properties);
+ auto it = properties.find(_property);
+ if (it == properties.cend())
+ {
+ return false;
+ }
- return _condition(it->second.template get<T>());
- }
+ return _condition(it->second.template get<T>());
+ }
private:
- const char *_iface;
- const char *_property;
- U _condition;
+ const char* _iface;
+ const char* _property;
+ U _condition;
};
} // namespace property_condition
} // namespace details
/** @brief The default filter. */
-inline bool none(sdbusplus::message::message &, Manager &) noexcept
+inline bool none(sdbusplus::message::message&, Manager&) noexcept
{
return true;
}
@@ -157,17 +161,17 @@
/** @brief Implicit type deduction for constructing PropertyCondition. */
template <typename T>
auto propertyChangedTo(
- const char *iface,
- const char *property,
- T val)
+ const char* iface,
+ const char* property,
+ T val)
{
- auto condition = [val = std::move(val)](const std::string &arg)
+ auto condition = [val = std::move(val)](const std::string & arg)
{
return arg == val;
};
using U = decltype(condition);
return details::property_condition::PropertyCondition<T, U>(
- iface, property, std::move(condition));
+ iface, property, std::move(condition));
}
} // namespace filters
diff --git a/manager.cpp b/manager.cpp
index 4286e54..c516d40 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -31,20 +31,22 @@
* Extracts per-signal specific context and forwards the call to the manager
* instance.
*/
-auto _signal(sd_bus_message *m, void *data, sd_bus_error *e) noexcept
+auto _signal(sd_bus_message* m, void* data, sd_bus_error* e) noexcept
{
- try {
+ try
+ {
auto msg = sdbusplus::message::message(m);
- auto &args = *static_cast<Manager::SigArg*>(data);
+ auto& args = *static_cast<Manager::SigArg*>(data);
sd_bus_message_ref(m);
- auto &mgr = *std::get<0>(args);
+ auto& mgr = *std::get<0>(args);
mgr.signal(
- msg,
- static_cast<const details::DbusSignal &>(
- *std::get<1>(args)),
- *std::get<2>(args));
+ msg,
+ static_cast<const details::DbusSignal&>(
+ *std::get<1>(args)),
+ *std::get<2>(args));
}
- catch (const std::exception &e) {
+ catch (const std::exception& e)
+ {
std::cerr << e.what() << std::endl;
}
@@ -54,45 +56,47 @@
} // namespace details
Manager::Manager(
- sdbusplus::bus::bus &&bus,
- const char *busname,
- const char *root,
- const char *iface) :
+ sdbusplus::bus::bus&& bus,
+ const char* busname,
+ const char* root,
+ const char* iface) :
details::ServerObject<details::ManagerIface>(bus, root),
_shutdown(false),
_root(root),
_bus(std::move(bus)),
_manager(sdbusplus::server::manager::manager(_bus, root))
{
- for (auto &group: _events)
+ for (auto& group : _events)
{
- for (auto pEvent: std::get<0>(group))
+ for (auto pEvent : std::get<0>(group))
{
if (pEvent->type !=
- details::Event::Type::DBUS_SIGNAL)
+ details::Event::Type::DBUS_SIGNAL)
+ {
continue;
+ }
// Create a callback context for this event group.
- auto dbusEvent = static_cast<details::DbusSignal *>(
- pEvent.get());
+ auto dbusEvent = static_cast<details::DbusSignal*>(
+ pEvent.get());
// Go ahead and store an iterator pointing at
// the event data to avoid lookups later since
// additional signal callbacks aren't added
// after the manager is constructed.
_sigargs.emplace_back(
- std::make_unique<SigArg>(
- this,
- dbusEvent,
- &group));
+ std::make_unique<SigArg>(
+ this,
+ dbusEvent,
+ &group));
// Register our callback and the context for
// each signal event.
_matches.emplace_back(
- _bus,
- std::get<0>(*dbusEvent),
- details::_signal,
- _sigargs.back().get());
+ _bus,
+ std::get<0>(*dbusEvent),
+ details::_signal,
+ _sigargs.back().get());
}
}
@@ -106,12 +110,15 @@
void Manager::run() noexcept
{
- while(!_shutdown) {
- try {
+ while (!_shutdown)
+ {
+ try
+ {
_bus.process_discard();
_bus.wait(5000000);
}
- catch (const std::exception &e) {
+ catch (const std::exception& e)
+ {
std::cerr << e.what() << std::endl;
}
}
@@ -119,86 +126,92 @@
void Manager::notify(std::string path, Object object)
{
- try {
- if(object.cbegin() == object.cend())
+ try
+ {
+ if (object.cbegin() == object.cend())
throw std::runtime_error(
- "No interfaces in " + path);
+ "No interfaces in " + path);
path.insert(0, _root);
auto obj = _refs.find(path);
- if(obj != _refs.end())
+ if (obj != _refs.end())
throw std::runtime_error(
- obj->first + " already exists");
+ obj->first + " already exists");
// Create an interface holder for each interface
// provided by the client and group them into
// a container.
InterfaceComposite ref;
- for (auto &x: object) {
+ for (auto& x : object)
+ {
auto maker = _makers.find(x.first.c_str());
- if(maker == _makers.end())
+ if (maker == _makers.end())
throw std::runtime_error(
- "Unimplemented interface: " + x.first);
+ "Unimplemented interface: " + x.first);
ref.emplace(x.first,
- (maker->second)(_bus, path.c_str()));
+ (maker->second)(_bus, path.c_str()));
}
// Hang on to a reference to the object (interfaces)
// so it stays on the bus, and so we can make calls
// to it if needed.
_refs.emplace(
- path, std::move(ref));
+ path, std::move(ref));
}
- catch (const std::exception &e) {
+ catch (const std::exception& e)
+ {
std::cerr << e.what() << std::endl;
}
}
void Manager::signal(
- sdbusplus::message::message &msg,
- const details::DbusSignal &event,
- const EventInfo &info)
+ sdbusplus::message::message& msg,
+ const details::DbusSignal& event,
+ const EventInfo& info)
{
- auto &filter = *std::get<1>(event);
- auto &actions = std::get<1>(info);
+ auto& filter = *std::get<1>(event);
+ auto& actions = std::get<1>(info);
- if(filter(msg, *this)) {
- for (auto &action: actions)
+ if (filter(msg, *this))
+ {
+ for (auto& action : actions)
+ {
(*action)(*this);
+ }
}
}
-void Manager::destroyObject(const char *path)
+void Manager::destroyObject(const char* path)
{
std::string p{path};
_refs.erase(_root + p);
}
details::holder::Base& Manager::getInterfaceHolder(
- const char *path, const char *interface)
+ const char* path, const char* interface)
{
- return const_cast<const Manager *>(
- this)->getInterfaceHolder(path, interface);
+ return const_cast<const Manager*>(
+ this)->getInterfaceHolder(path, interface);
}
details::holder::Base& Manager::getInterfaceHolder(
- const char *path, const char *interface) const
+ const char* path, const char* interface) const
{
std::string p{path};
auto oit = _refs.find(_root + p);
- if(oit == _refs.end())
+ if (oit == _refs.end())
throw std::runtime_error(
- _root + p + " was not found");
+ _root + p + " was not found");
- auto &obj = oit->second;
+ auto& obj = oit->second;
auto iit = obj.find(interface);
- if(iit == obj.end())
+ if (iit == obj.end())
throw std::runtime_error(
- "interface was not found");
+ "interface was not found");
return *iit->second;
}
diff --git a/manager.hpp b/manager.hpp
index 0954953..1c060bc 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -35,15 +35,15 @@
template <typename T>
struct MakeInterface
{
- static decltype(auto) make(sdbusplus::bus::bus &bus, const char *path)
+ static decltype(auto) make(sdbusplus::bus::bus& bus, const char* path)
{
using HolderType = holder::Holder<std::unique_ptr<T>>;
return static_cast<std::unique_ptr<holder::Base>>(
- HolderType::template make_unique<HolderType>(
- std::forward<std::unique_ptr<T>>(
- std::make_unique<T>(
- std::forward<decltype(bus)>(bus),
- std::forward<decltype(path)>(path)))));
+ HolderType::template make_unique<HolderType>(
+ std::forward<std::unique_ptr<T>>(
+ std::make_unique<T>(
+ std::forward<decltype(bus)>(bus),
+ std::forward<decltype(path)>(path)))));
}
};
} // namespace details
@@ -58,159 +58,159 @@
public details::ServerObject<details::ManagerIface>
{
public:
- Manager() = delete;
- Manager(const Manager&) = delete;
- Manager& operator=(const Manager&) = delete;
- Manager(Manager&&) = default;
- Manager& operator=(Manager&&) = default;
- ~Manager() = default;
+ Manager() = delete;
+ Manager(const Manager&) = delete;
+ Manager& operator=(const Manager&) = delete;
+ Manager(Manager&&) = default;
+ Manager& operator=(Manager&&) = default;
+ ~Manager() = default;
- /** @brief Construct an inventory manager.
- *
- * @param[in] bus - An sdbusplus bus connection.
- * @param[in] busname - The DBus busname to own.
- * @param[in] root - The DBus path on which to implement
- * an inventory manager.
- * @param[in] iface - The DBus inventory interface to implement.
- */
- Manager(sdbusplus::bus::bus &&, const char *, const char*, const char*);
+ /** @brief Construct an inventory manager.
+ *
+ * @param[in] bus - An sdbusplus bus connection.
+ * @param[in] busname - The DBus busname to own.
+ * @param[in] root - The DBus path on which to implement
+ * an inventory manager.
+ * @param[in] iface - The DBus inventory interface to implement.
+ */
+ Manager(sdbusplus::bus::bus&&, const char*, const char*, const char*);
- using Object = std::map<
- std::string, std::map<
- std::string, sdbusplus::message::variant<std::string>>>;
- using EventInfo = std::tuple<
- std::vector<details::EventBasePtr>,
- std::vector<details::ActionBasePtr>>;
+ using Object = std::map <
+ std::string, std::map <
+ std::string, sdbusplus::message::variant<std::string >>>;
+ using EventInfo = std::tuple <
+ std::vector<details::EventBasePtr>,
+ std::vector<details::ActionBasePtr >>;
- /** @brief Start processing DBus messages. */
- void run() noexcept;
+ /** @brief Start processing DBus messages. */
+ void run() noexcept;
- /** @brief Provided for testing only. */
- void shutdown() noexcept;
+ /** @brief Provided for testing only. */
+ void shutdown() noexcept;
- /** @brief sd_bus Notify method implementation callback. */
- void notify(std::string path, Object) override;
+ /** @brief sd_bus Notify method implementation callback. */
+ void notify(std::string path, Object) override;
- /** @brief sd_bus signal callback. */
- void signal(sdbusplus::message::message&,
- const details::DbusSignal &event,
- const EventInfo &info);
+ /** @brief sd_bus signal callback. */
+ void signal(sdbusplus::message::message&,
+ const details::DbusSignal& event,
+ const EventInfo& info);
- /** @brief Drop an object from DBus. */
- void destroyObject(const char *);
+ /** @brief Drop an object from DBus. */
+ void destroyObject(const char*);
- /** @brief Invoke an sdbusplus server binding method.
- *
- * Invoke the requested method with a reference to the requested
- * sdbusplus server binding interface as a parameter.
- *
- * @tparam T - The sdbusplus server binding interface type.
- * @tparam U - The type of the sdbusplus server binding member.
- * @tparam Args - Argument types of the binding member.
- *
- * @param[in] path - The DBus path on which the method should
- * be invoked.
- * @param[in] interface - The DBus interface hosting the method.
- * @param[in] member - Pointer to sdbusplus server binding member.
- * @param[in] args - Arguments to forward to the binding member.
- *
- * @returns - The return/value type of the binding method being
- * called.
- */
- template<typename T, typename U, typename ...Args>
- decltype(auto) invokeMethod(const char *path, const char *interface,
- U&& member, Args&&...args)
- {
- auto &holder = getInterface<std::unique_ptr<T>>(path, interface);
- auto &iface = *holder.get();
- return (iface.*member)(std::forward<Args>(args)...);
- }
+ /** @brief Invoke an sdbusplus server binding method.
+ *
+ * Invoke the requested method with a reference to the requested
+ * sdbusplus server binding interface as a parameter.
+ *
+ * @tparam T - The sdbusplus server binding interface type.
+ * @tparam U - The type of the sdbusplus server binding member.
+ * @tparam Args - Argument types of the binding member.
+ *
+ * @param[in] path - The DBus path on which the method should
+ * be invoked.
+ * @param[in] interface - The DBus interface hosting the method.
+ * @param[in] member - Pointer to sdbusplus server binding member.
+ * @param[in] args - Arguments to forward to the binding member.
+ *
+ * @returns - The return/value type of the binding method being
+ * called.
+ */
+ template<typename T, typename U, typename ...Args>
+ decltype(auto) invokeMethod(const char* path, const char* interface,
+ U&& member, Args&& ...args)
+ {
+ auto& holder = getInterface<std::unique_ptr<T>>(path, interface);
+ auto& iface = *holder.get();
+ return (iface.*member)(std::forward<Args>(args)...);
+ }
- using SigArgs = std::vector<
- std::unique_ptr<
- std::tuple<
- Manager *,
- const details::DbusSignal *,
- const EventInfo *>>>;
- using SigArg = SigArgs::value_type::element_type;
+ using SigArgs = std::vector <
+ std::unique_ptr <
+ std::tuple <
+ Manager*,
+ const details::DbusSignal*,
+ const EventInfo* >>>;
+ using SigArg = SigArgs::value_type::element_type;
private:
- using HolderPtr = std::unique_ptr<details::holder::Base>;
- using InterfaceComposite = std::map<std::string, HolderPtr>;
- using ObjectReferences = std::map<std::string, InterfaceComposite>;
- using Events = std::vector<EventInfo>;
- using MakerType = HolderPtr(*)(
- sdbusplus::bus::bus &, const char *);
- using Makers = std::map<std::string, MakerType>;
+ using HolderPtr = std::unique_ptr<details::holder::Base>;
+ using InterfaceComposite = std::map<std::string, HolderPtr>;
+ using ObjectReferences = std::map<std::string, InterfaceComposite>;
+ using Events = std::vector<EventInfo>;
+ using MakerType = HolderPtr(*)(
+ sdbusplus::bus::bus&, const char*);
+ using Makers = std::map<std::string, MakerType>;
- /** @brief Provides weak references to interface holders.
- *
- * Common code for all types for the templated getInterface
- * methods.
- *
- * @param[in] path - The DBus path for which the interface
- * holder instance should be provided.
- * @param[in] interface - The DBus interface for which the
- * holder instance should be provided.
- *
- * @returns A weak reference to the holder instance.
- */
- details::holder::Base& getInterfaceHolder(
- const char *, const char *) const;
- details::holder::Base& getInterfaceHolder(
- const char *, const char *);
+ /** @brief Provides weak references to interface holders.
+ *
+ * Common code for all types for the templated getInterface
+ * methods.
+ *
+ * @param[in] path - The DBus path for which the interface
+ * holder instance should be provided.
+ * @param[in] interface - The DBus interface for which the
+ * holder instance should be provided.
+ *
+ * @returns A weak reference to the holder instance.
+ */
+ details::holder::Base& getInterfaceHolder(
+ const char*, const char*) const;
+ details::holder::Base& getInterfaceHolder(
+ const char*, const char*);
- /** @brief Provides weak references to interface holders.
- *
- * @tparam T - The sdbusplus server binding interface type.
- *
- * @param[in] path - The DBus path for which the interface
- * should be provided.
- * @param[in] interface - The DBus interface to obtain.
- *
- * @returns A weak reference to the interface holder.
- */
- template<typename T>
- auto& getInterface(const char *path, const char *interface)
- {
- auto &holder = getInterfaceHolder(path, interface);
- return static_cast<
- details::holder::Holder<T> &>(holder);
- }
- template<typename T>
- auto& getInterface(const char *path, const char *interface) const
- {
- auto &holder = getInterfaceHolder(path, interface);
- return static_cast<
- const details::holder::Holder<T> &>(holder);
- }
+ /** @brief Provides weak references to interface holders.
+ *
+ * @tparam T - The sdbusplus server binding interface type.
+ *
+ * @param[in] path - The DBus path for which the interface
+ * should be provided.
+ * @param[in] interface - The DBus interface to obtain.
+ *
+ * @returns A weak reference to the interface holder.
+ */
+ template<typename T>
+ auto& getInterface(const char* path, const char* interface)
+ {
+ auto& holder = getInterfaceHolder(path, interface);
+ return static_cast <
+ details::holder::Holder<T>& >(holder);
+ }
+ template<typename T>
+ auto& getInterface(const char* path, const char* interface) const
+ {
+ auto& holder = getInterfaceHolder(path, interface);
+ return static_cast <
+ const details::holder::Holder<T>& >(holder);
+ }
- /** @brief Provided for testing only. */
- bool _shutdown;
+ /** @brief Provided for testing only. */
+ bool _shutdown;
- /** @brief Path prefix applied to any relative paths. */
- const char * _root;
+ /** @brief Path prefix applied to any relative paths. */
+ const char* _root;
- /** @brief A container of sdbusplus server interface references. */
- ObjectReferences _refs;
+ /** @brief A container of sdbusplus server interface references. */
+ ObjectReferences _refs;
- /** @brief A container contexts for signal callbacks. */
- SigArgs _sigargs;
+ /** @brief A container contexts for signal callbacks. */
+ SigArgs _sigargs;
- /** @brief A container of sdbusplus signal matches. */
- std::vector<sdbusplus::server::match::match> _matches;
+ /** @brief A container of sdbusplus signal matches. */
+ std::vector<sdbusplus::server::match::match> _matches;
- /** @brief Persistent sdbusplus DBus bus connection. */
- sdbusplus::bus::bus _bus;
+ /** @brief Persistent sdbusplus DBus bus connection. */
+ sdbusplus::bus::bus _bus;
- /** @brief sdbusplus org.freedesktop.DBus.ObjectManager reference. */
- sdbusplus::server::manager::manager _manager;
+ /** @brief sdbusplus org.freedesktop.DBus.ObjectManager reference. */
+ sdbusplus::server::manager::manager _manager;
- /** @brief A container of pimgen generated events and responses. */
- static const Events _events;
+ /** @brief A container of pimgen generated events and responses. */
+ static const Events _events;
- /** @brief A container of pimgen generated factory methods. */
- static const Makers _makers;
+ /** @brief A container of pimgen generated factory methods. */
+ static const Makers _makers;
};
} // namespace manager
diff --git a/test/test.cpp b/test/test.cpp
index 13b8934..550e83f 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -23,13 +23,13 @@
constexpr auto INTERFACE = IFACE;
constexpr auto ROOT = "/testing/inventory";
-auto server_thread(void *data)
+auto server_thread(void* data)
{
auto mgr = static_cast<phosphor::inventory::manager::Manager*>(data);
mgr->run();
- return static_cast<void *>(nullptr);
+ return static_cast<void*>(nullptr);
}
/** @class SignalQueue
@@ -38,109 +38,113 @@
class SignalQueue
{
public:
- ~SignalQueue() = default;
- SignalQueue() = delete;
- SignalQueue(const SignalQueue &) = delete;
- SignalQueue(SignalQueue &&) = default;
- SignalQueue& operator=(const SignalQueue &) = delete;
- SignalQueue& operator=(SignalQueue &&) = default;
- explicit SignalQueue(const std::string &match) :
- _bus(sdbusplus::bus::new_default()),
- _match(_bus, match.c_str(), &callback, this),
- _next(nullptr)
- {
- }
-
- auto &&pop(unsigned timeout=1000000)
- {
- while(timeout > 0 && !_next)
+ ~SignalQueue() = default;
+ SignalQueue() = delete;
+ SignalQueue(const SignalQueue&) = delete;
+ SignalQueue(SignalQueue&&) = default;
+ SignalQueue& operator=(const SignalQueue&) = delete;
+ SignalQueue& operator=(SignalQueue&&) = default;
+ explicit SignalQueue(const std::string& match) :
+ _bus(sdbusplus::bus::new_default()),
+ _match(_bus, match.c_str(), &callback, this),
+ _next(nullptr)
{
- _bus.process_discard();
- _bus.wait(50000);
- timeout -= 50000;
}
- return std::move(_next);
- }
+
+ auto&& pop(unsigned timeout = 1000000)
+ {
+ while (timeout > 0 && !_next)
+ {
+ _bus.process_discard();
+ _bus.wait(50000);
+ timeout -= 50000;
+ }
+ return std::move(_next);
+ }
private:
- static int callback(sd_bus_message *m, void *context, sd_bus_error *)
- {
- auto *me = static_cast<SignalQueue *>(context);
- sd_bus_message_ref(m);
- sdbusplus::message::message msg{m};
- me->_next = std::move(msg);
- return 0;
- }
+ static int callback(sd_bus_message* m, void* context, sd_bus_error*)
+ {
+ auto* me = static_cast<SignalQueue*>(context);
+ sd_bus_message_ref(m);
+ sdbusplus::message::message msg{m};
+ me->_next = std::move(msg);
+ return 0;
+ }
- sdbusplus::bus::bus _bus;
- sdbusplus::server::match::match _match;
- sdbusplus::message::message _next;
+ sdbusplus::bus::bus _bus;
+ sdbusplus::server::match::match _match;
+ sdbusplus::message::message _next;
};
template <typename ...T>
-using Object = std::map<
- std::string,
- std::map<
- std::string,
- sdbusplus::message::variant<T...>>>;
+using Object = std::map <
+ std::string,
+ std::map <
+ std::string,
+ sdbusplus::message::variant<T... >>>;
using ObjectPath = std::string;
/**@brief Find a subset of interfaces and properties in an object. */
template <typename ...T>
-auto hasProperties(const Object<T...> &l, const Object<T...> &r)
+auto hasProperties(const Object<T...>& l, const Object<T...>& r)
{
Object<T...> result;
std::set_difference(
- r.cbegin(),
- r.cend(),
- l.cbegin(),
- l.cend(),
- std::inserter(result, result.end()));
+ r.cbegin(),
+ r.cend(),
+ l.cbegin(),
+ l.cend(),
+ std::inserter(result, result.end()));
return result.empty();
}
/**@brief Check an object for one or more interfaces. */
template <typename ...T>
-auto hasInterfaces(const std::vector<std::string> &l, const Object<T...> &r)
+auto hasInterfaces(const std::vector<std::string>& l, const Object<T...>& r)
{
std::vector<std::string> stripped, interfaces;
std::transform(
- r.cbegin(),
- r.cend(),
- std::back_inserter(stripped),
- [](auto &p){ return p.first; });
+ r.cbegin(),
+ r.cend(),
+ std::back_inserter(stripped),
+ [](auto & p)
+ {
+ return p.first;
+ });
std::set_difference(
- stripped.cbegin(),
- stripped.cend(),
- l.cbegin(),
- l.cend(),
- std::back_inserter(interfaces));
+ stripped.cbegin(),
+ stripped.cend(),
+ l.cbegin(),
+ l.cend(),
+ std::back_inserter(interfaces));
return interfaces.empty();
}
-void runTests(phosphor::inventory::manager::Manager &mgr)
+void runTests(phosphor::inventory::manager::Manager& mgr)
{
const std::string root{ROOT};
auto b = sdbusplus::bus::new_default();
auto notify = [&]()
{
return b.new_method_call(
- SERVICE,
- ROOT,
- INTERFACE,
- "Notify");
+ SERVICE,
+ ROOT,
+ INTERFACE,
+ "Notify");
};
- auto set = [&](const std::string &path)
+ auto set = [&](const std::string & path)
{
return b.new_method_call(
- SERVICE,
- path.c_str(),
- "org.freedesktop.DBus.Properties",
- "Set");
+ SERVICE,
+ path.c_str(),
+ "org.freedesktop.DBus.Properties",
+ "Set");
};
- Object<std::string> obj{
+ Object<std::string> obj
+ {
{
"xyz.openbmc_project.Example.Iface1",
{{"ExampleProperty1", "test1"}}
@@ -157,7 +161,7 @@
ObjectPath path{root + relPath};
SignalQueue queue(
- "path='" + root + "',member='InterfacesAdded'");
+ "path='" + root + "',member='InterfacesAdded'");
auto m = notify();
m.append(relPath);
@@ -210,7 +214,7 @@
// Set a property that should not trigger due to a filter.
{
SignalQueue queue(
- "path='" + root + "',member='InterfacesRemoved'");
+ "path='" + root + "',member='InterfacesRemoved'");
auto m = set(triggerOne);
m.append("xyz.openbmc_project.Example.Iface2");
m.append("ExampleProperty2");
@@ -223,7 +227,7 @@
// Set a property that should trigger.
{
SignalQueue queue(
- "path='" + root + "',member='InterfacesRemoved'");
+ "path='" + root + "',member='InterfacesRemoved'");
auto m = set(triggerOne);
m.append("xyz.openbmc_project.Example.Iface2");
@@ -287,7 +291,7 @@
// Trigger and validate the change.
{
SignalQueue queue(
- "path='" + changeMe + "',member='PropertiesChanged'");
+ "path='" + changeMe + "',member='PropertiesChanged'");
auto m = set(triggerTwo);
m.append("xyz.openbmc_project.Example.Iface2");
m.append("ExampleProperty2");
@@ -295,9 +299,9 @@
b.call(m);
std::string sigInterface;
- std::map<
- std::string,
- sdbusplus::message::variant<std::string>> sigProperties;
+ std::map <
+ std::string,
+ sdbusplus::message::variant<std::string >> sigProperties;
{
std::vector<std::string> interfaces;
auto sig{queue.pop()};
@@ -316,8 +320,8 @@
int main()
{
auto mgr = phosphor::inventory::manager::Manager(
- sdbusplus::bus::new_default(),
- SERVICE, ROOT, INTERFACE);
+ sdbusplus::bus::new_default(),
+ SERVICE, ROOT, INTERFACE);
pthread_t t;
{
diff --git a/utils.hpp b/utils.hpp
index 4ebb2a3..1ea7fc1 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -37,57 +37,57 @@
template <typename T>
struct Holder : public Base
{
- Holder() = delete;
- virtual ~Holder() = default;
- Holder(const Holder&) = delete;
- Holder & operator=(const Holder&) = delete;
- Holder(Holder&&) = default;
- Holder& operator=(Holder&&) = default;
- explicit Holder(T&& held) : _held(std::forward<T>(held)) {}
+ Holder() = delete;
+ virtual ~Holder() = default;
+ Holder(const Holder&) = delete;
+ Holder& operator=(const Holder&) = delete;
+ Holder(Holder&&) = default;
+ Holder& operator=(Holder&&) = default;
+ explicit Holder(T&& held) : _held(std::forward<T>(held)) {}
- /** @brief Construct an adapter.
- *
- * @param[in] held - The object to be adapted.
- *
- * @returns - std::unique pointer to the adapted object.
- *
- * @tparam Ret - The type of the pointer to be returned.
- * @tparam Held - The type of the object to be adapted.
- */
- template <typename Ret, typename Held>
- static auto make_unique(Held&& held)
- {
- return std::make_unique<Ret>(
- std::forward<Held>(held));
- }
+ /** @brief Construct an adapter.
+ *
+ * @param[in] held - The object to be adapted.
+ *
+ * @returns - std::unique pointer to the adapted object.
+ *
+ * @tparam Ret - The type of the pointer to be returned.
+ * @tparam Held - The type of the object to be adapted.
+ */
+ template <typename Ret, typename Held>
+ static auto make_unique(Held&& held)
+ {
+ return std::make_unique<Ret>(
+ std::forward<Held>(held));
+ }
- /** @brief Construct an adapter.
- *
- * @param[in] held - The object to be adapted.
- *
- * @returns - std::shared pointer to the adapted object.
- *
- * @tparam Ret - The type of the pointer to be returned.
- * @tparam Held - The type of the object to be adapted.
- */
- template <typename Ret, typename Held>
- static auto make_shared(Held&& held)
- {
- return std::make_shared<Ret>(
- std::forward<Held>(held));
- }
+ /** @brief Construct an adapter.
+ *
+ * @param[in] held - The object to be adapted.
+ *
+ * @returns - std::shared pointer to the adapted object.
+ *
+ * @tparam Ret - The type of the pointer to be returned.
+ * @tparam Held - The type of the object to be adapted.
+ */
+ template <typename Ret, typename Held>
+ static auto make_shared(Held&& held)
+ {
+ return std::make_shared<Ret>(
+ std::forward<Held>(held));
+ }
- /** @brief Provides a weak reference to the held interface. */
- T& get()
- {
- return _held;
- }
+ /** @brief Provides a weak reference to the held interface. */
+ T& get()
+ {
+ return _held;
+ }
- /** @brief Provides a weak reference to the held interface. */
- const T& get() const
- {
- return _held;
- }
+ /** @brief Provides a weak reference to the held interface. */
+ const T& get() const
+ {
+ return _held;
+ }
protected:
T _held;
@@ -112,11 +112,11 @@
CallableBase(CallableBase&&) = default;
CallableBase& operator=(CallableBase&&) = default;
- virtual Ret operator()(Args&&...args) const = 0;
- virtual Ret operator()(Args&&...args)
+ virtual Ret operator()(Args&& ...args) const = 0;
+ virtual Ret operator()(Args&& ...args)
{
return const_cast<const CallableBase&>(*this)(
- std::forward<Args>(args)...);
+ std::forward<Args>(args)...);
}
};
@@ -137,17 +137,17 @@
CallableHolder() = delete;
~CallableHolder() = default;
CallableHolder(const CallableHolder&) = delete;
- CallableHolder & operator=(const CallableHolder&) = delete;
+ CallableHolder& operator=(const CallableHolder&) = delete;
CallableHolder(CallableHolder&&) = default;
CallableHolder& operator=(CallableHolder&&) = default;
explicit CallableHolder(T&& func) : Holder<T>(std::forward<T>(func)) {}
- virtual Ret operator()(Args&&...args) const override
+ virtual Ret operator()(Args&& ...args) const override
{
return this->_held(std::forward<Args>(args)...);
}
- virtual Ret operator()(Args&&...args) override
+ virtual Ret operator()(Args&& ...args) override
{
return this->_held(std::forward<Args>(args)...);
}