From 0b02be925a29357f69abbc9e9a58e7c5aaed2eab Mon Sep 17 00:00:00 2001 From: Patrick Venture Date: Fri, 31 Aug 2018 11:55:55 -0700 Subject: add .clang-format Change-Id: I7c2a527b4751a560703a61fcbe9638b150546af5 Signed-off-by: Patrick Venture --- utils.hpp | 168 +++++++++++++++++++++++++++++--------------------------------- 1 file changed, 78 insertions(+), 90 deletions(-) (limited to 'utils.hpp') diff --git a/utils.hpp b/utils.hpp index 535ea66..8b69b09 100644 --- a/utils.hpp +++ b/utils.hpp @@ -1,9 +1,9 @@ #pragma once +#include "types.hpp" + #include #include -#include "types.hpp" - namespace ipmi { @@ -29,54 +29,56 @@ constexpr auto METHOD_SET = "Set"; * require. This class reduces the number of such calls by caching * the lookup for a specific service. */ -class ServiceCache { - public: - /** @brief Creates a new service cache for the given interface - * and path. - * - * @param[in] intf - The interface used for each lookup - * @param[in] path - The path used for each lookup - */ - ServiceCache(const std::string& intf, const std::string& path); - ServiceCache(std::string&& intf, std::string&& path); - - /** @brief Gets the service name from the cache or does in a - * lookup when invalid. - * - * @param[in] bus - The bus associated with and used for looking - * up the service. - */ - const std::string& getService(sdbusplus::bus::bus& bus); - - /** @brief Invalidates the current service name */ - void invalidate(); - - /** @brief A wrapper around sdbusplus bus.new_method_call - * - * @param[in] bus - The bus used for calling the method - * @param[in] intf - The interface containing the method - * @param[in] method - The method name - * @return The message containing the method call. - */ - sdbusplus::message::message newMethodCall(sdbusplus::bus::bus& bus, - const char *intf, - const char *method); - - /** @brief Check to see if the current cache is valid - * - * @param[in] bus - The bus used for the service lookup - * @return True if the cache is valid false otherwise. - */ - bool isValid(sdbusplus::bus::bus& bus) const; - private: - /** @brief DBUS interface provided by the service */ - const std::string intf; - /** @brief DBUS path provided by the service */ - const std::string path; - /** @brief The name of the service if valid */ - std::experimental::optional cachedService; - /** @brief The name of the bus used in the service lookup */ - std::experimental::optional cachedBusName; +class ServiceCache +{ + public: + /** @brief Creates a new service cache for the given interface + * and path. + * + * @param[in] intf - The interface used for each lookup + * @param[in] path - The path used for each lookup + */ + ServiceCache(const std::string& intf, const std::string& path); + ServiceCache(std::string&& intf, std::string&& path); + + /** @brief Gets the service name from the cache or does in a + * lookup when invalid. + * + * @param[in] bus - The bus associated with and used for looking + * up the service. + */ + const std::string& getService(sdbusplus::bus::bus& bus); + + /** @brief Invalidates the current service name */ + void invalidate(); + + /** @brief A wrapper around sdbusplus bus.new_method_call + * + * @param[in] bus - The bus used for calling the method + * @param[in] intf - The interface containing the method + * @param[in] method - The method name + * @return The message containing the method call. + */ + sdbusplus::message::message newMethodCall(sdbusplus::bus::bus& bus, + const char* intf, + const char* method); + + /** @brief Check to see if the current cache is valid + * + * @param[in] bus - The bus used for the service lookup + * @return True if the cache is valid false otherwise. + */ + bool isValid(sdbusplus::bus::bus& bus) const; + + private: + /** @brief DBUS interface provided by the service */ + const std::string intf; + /** @brief DBUS path provided by the service */ + const std::string path; + /** @brief The name of the service if valid */ + std::experimental::optional cachedService; + /** @brief The name of the bus used in the service lookup */ + std::experimental::optional cachedBusName; }; /** @@ -87,8 +89,7 @@ class ServiceCache { * @param[in] path - DBUS Object Path * */ -std::string getService(sdbusplus::bus::bus& bus, - const std::string& intf, +std::string getService(sdbusplus::bus::bus& bus, const std::string& intf, const std::string& path); /** @brief Gets the dbus object info implementing the given interface @@ -127,10 +128,8 @@ DbusObjectInfo getIPObject(sdbusplus::bus::bus& bus, * @param[in] property - name of the property. * @return On success returns the value of the property. */ -Value getDbusProperty(sdbusplus::bus::bus& bus, - const std::string& service, - const std::string& objPath, - const std::string& interface, +Value getDbusProperty(sdbusplus::bus::bus& bus, const std::string& service, + const std::string& objPath, const std::string& interface, const std::string& property); /** @brief Gets all the properties associated with the given object @@ -154,8 +153,8 @@ PropertyMap getAllDbusProperties(sdbusplus::bus::bus& bus, * @return On success returns the map of name value pair. */ ObjectValueTree getManagedObjects(sdbusplus::bus::bus& bus, - const std::string& service, - const std::string& objPath); + const std::string& service, + const std::string& objPath); /** @brief Sets the property value of the given object. * @param[in] bus - DBUS Bus Object. @@ -165,12 +164,9 @@ ObjectValueTree getManagedObjects(sdbusplus::bus::bus& bus, * @param[in] property - name of the property. * @param[in] value - value which needs to be set. */ -void setDbusProperty(sdbusplus::bus::bus& bus, - const std::string& service, - const std::string& objPath, - const std::string& interface, - const std::string& property, - const Value& value); +void setDbusProperty(sdbusplus::bus::bus& bus, const std::string& service, + const std::string& objPath, const std::string& interface, + const std::string& property, const Value& value); /** @brief Gets all the dbus objects from the given service root * which matches the object identifier. @@ -204,8 +200,7 @@ void deleteAllDbusObjects(sdbusplus::bus::bus& bus, * @param[in] interfaces - Dbus interface list. * @return map of object path and service info. */ -ObjectTree getAllAncestors(sdbusplus::bus::bus& bus, - const std::string& path, +ObjectTree getAllAncestors(sdbusplus::bus::bus& bus, const std::string& path, InterfaceList&& interfaces); /** @struct VariantToDoubleVisitor @@ -216,14 +211,14 @@ struct VariantToDoubleVisitor { template std::enable_if_t::value, double> - operator()(const T &t) const + operator()(const T& t) const { return static_cast(t); } template std::enable_if_t::value, double> - operator()(const T &t) const + operator()(const T& t) const { throw std::invalid_argument("Cannot translate type to double"); } @@ -239,13 +234,11 @@ namespace method_no_args * @param[in] interface - Dbus interface. * @param[in] method - Dbus method. */ -void callDbusMethod(sdbusplus::bus::bus& bus, - const std::string& service, - const std::string& objPath, - const std::string& interface, +void callDbusMethod(sdbusplus::bus::bus& bus, const std::string& service, + const std::string& objPath, const std::string& interface, const std::string& method); -} //namespace method_no_args +} // namespace method_no_args namespace network { @@ -257,10 +250,13 @@ constexpr auto IPV4_PREFIX = "169.254"; constexpr auto IPV6_PREFIX = "fe80"; constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP"; constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress"; -constexpr auto SYSTEMCONFIG_INTERFACE = "xyz.openbmc_project.Network.SystemConfiguration"; -constexpr auto ETHERNET_INTERFACE = "xyz.openbmc_project.Network.EthernetInterface"; +constexpr auto SYSTEMCONFIG_INTERFACE = + "xyz.openbmc_project.Network.SystemConfiguration"; +constexpr auto ETHERNET_INTERFACE = + "xyz.openbmc_project.Network.EthernetInterface"; constexpr auto IP_CREATE_INTERFACE = "xyz.openbmc_project.Network.IP.Create"; -constexpr auto VLAN_CREATE_INTERFACE = "xyz.openbmc_project.Network.VLAN.Create"; +constexpr auto VLAN_CREATE_INTERFACE = + "xyz.openbmc_project.Network.VLAN.Create"; constexpr auto VLAN_INTERFACE = "xyz.openbmc_project.Network.VLAN"; /* @brief converts the given subnet into prefix notation. @@ -270,7 +266,6 @@ constexpr auto VLAN_INTERFACE = "xyz.openbmc_project.Network.VLAN"; */ uint8_t toPrefix(int addressFamily, const std::string& subnetMask); - /** @brief Sets the ip on the system. * @param[in] bus - DBUS Bus Object. * @param[in] service - Dbus service name. @@ -279,12 +274,9 @@ uint8_t toPrefix(int addressFamily, const std::string& subnetMask); * @param[in] ipaddress - IPaddress. * @param[in] prefix - Prefix length. */ -void createIP(sdbusplus::bus::bus& bus, - const std::string& service, - const std::string& objPath, - const std::string& protocolType, - const std::string& ipaddress, - uint8_t prefix); +void createIP(sdbusplus::bus::bus& bus, const std::string& service, + const std::string& objPath, const std::string& protocolType, + const std::string& ipaddress, uint8_t prefix); /** @brief Creates the VLAN on the given interface. * @param[in] bus - DBUS Bus Object. @@ -293,10 +285,8 @@ void createIP(sdbusplus::bus::bus& bus, * @param[in] interface - EthernetInterface. * @param[in] vlanID - Vlan ID. */ -void createVLAN(sdbusplus::bus::bus& bus, - const std::string& service, - const std::string& objPath, - const std::string& interface, +void createVLAN(sdbusplus::bus::bus& bus, const std::string& service, + const std::string& objPath, const std::string& interface, uint32_t vlanID); /** @brief Gets the vlan id from the given object path. @@ -304,7 +294,5 @@ void createVLAN(sdbusplus::bus::bus& bus, */ uint32_t getVLAN(const std::string& path); -} //namespace network +} // namespace network } // namespace ipmi - - -- cgit v1.2.1