Try to fix the lambda formatting issue
clang-tidy has a setting, LambdaBodyIndentation, which it says:
"For callback-heavy code, it may improve readability to have the
signature indented two levels and to use OuterScope."
bmcweb is very callback heavy code. Try to enable it and see if that
improves things. There are many cases where the length of a lambda call
will change, and reindent the entire lambda function. This is really
bad for code reviews, as it's difficult to see the lines changed. This
commit should resolve it. This does have the downside of reindenting a
lot of functions, which is unfortunate, but probably worth it in the
long run.
All changes except for the .clang-format file were made by the robot.
Tested: Code compiles, whitespace changes only.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ib4aa2f1391fada981febd25b67dcdb9143827f43
diff --git a/include/dbus_monitor.hpp b/include/dbus_monitor.hpp
index 977f3a3..ce0550d 100644
--- a/include/dbus_monitor.hpp
+++ b/include/dbus_monitor.hpp
@@ -117,138 +117,136 @@
.onclose([&](crow::websocket::Connection& conn, const std::string&) {
sessions.erase(&conn);
})
- .onmessage([&](crow::websocket::Connection& conn,
- const std::string& data, bool) {
- const auto sessionPair = sessions.find(&conn);
- if (sessionPair == sessions.end())
+ .onmessage(
+ [&](crow::websocket::Connection& conn, const std::string& data,
+ bool) {
+ const auto sessionPair = sessions.find(&conn);
+ if (sessionPair == sessions.end())
+ {
+ conn.close("Internal error");
+ }
+ DbusWebsocketSession& thisSession = sessionPair->second;
+ BMCWEB_LOG_DEBUG << "Connection " << &conn << " received " << data;
+ nlohmann::json j = nlohmann::json::parse(data, nullptr, false);
+ if (j.is_discarded())
+ {
+ BMCWEB_LOG_ERROR << "Unable to parse json data for monitor";
+ conn.close("Unable to parse json request");
+ return;
+ }
+ nlohmann::json::iterator interfaces = j.find("interfaces");
+ if (interfaces != j.end())
+ {
+ thisSession.interfaces.reserve(interfaces->size());
+ for (auto& interface : *interfaces)
{
- conn.close("Internal error");
+ const std::string* str =
+ interface.get_ptr<const std::string*>();
+ if (str != nullptr)
+ {
+ thisSession.interfaces.insert(*str);
+ }
}
- DbusWebsocketSession& thisSession = sessionPair->second;
- BMCWEB_LOG_DEBUG << "Connection " << &conn << " received " << data;
- nlohmann::json j = nlohmann::json::parse(data, nullptr, false);
- if (j.is_discarded())
+ }
+
+ nlohmann::json::iterator paths = j.find("paths");
+ if (paths == j.end())
+ {
+ BMCWEB_LOG_ERROR << "Unable to find paths in json data";
+ conn.close("Unable to find paths in json data");
+ return;
+ }
+
+ size_t interfaceCount = thisSession.interfaces.size();
+ if (interfaceCount == 0)
+ {
+ interfaceCount = 1;
+ }
+ // Reserve our matches upfront. For each path there is 1 for
+ // interfacesAdded, and InterfaceCount number for
+ // PropertiesChanged
+ thisSession.matches.reserve(thisSession.matches.size() +
+ paths->size() * (1U + interfaceCount));
+ std::string objectManagerMatchString;
+ std::string propertiesMatchString;
+ std::string objectManagerInterfacesMatchString;
+ // These regexes derived on the rules here:
+ // https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names
+ std::regex validPath("^/([A-Za-z0-9_]+/?)*$");
+ std::regex validInterface(
+ "^[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)+$");
+
+ for (const auto& thisPath : *paths)
+ {
+ const std::string* thisPathString =
+ thisPath.get_ptr<const std::string*>();
+ if (thisPathString == nullptr)
{
- BMCWEB_LOG_ERROR << "Unable to parse json data for monitor";
- conn.close("Unable to parse json request");
+ BMCWEB_LOG_ERROR << "subscribe path isn't a string?";
+ conn.close();
return;
}
- nlohmann::json::iterator interfaces = j.find("interfaces");
- if (interfaces != j.end())
+ if (!std::regex_match(*thisPathString, validPath))
{
- thisSession.interfaces.reserve(interfaces->size());
- for (auto& interface : *interfaces)
- {
- const std::string* str =
- interface.get_ptr<const std::string*>();
- if (str != nullptr)
- {
- thisSession.interfaces.insert(*str);
- }
- }
- }
-
- nlohmann::json::iterator paths = j.find("paths");
- if (paths == j.end())
- {
- BMCWEB_LOG_ERROR << "Unable to find paths in json data";
- conn.close("Unable to find paths in json data");
+ BMCWEB_LOG_ERROR << "Invalid path name " << *thisPathString;
+ conn.close();
return;
}
-
- size_t interfaceCount = thisSession.interfaces.size();
- if (interfaceCount == 0)
+ propertiesMatchString =
+ ("type='signal',"
+ "interface='org.freedesktop.DBus.Properties',"
+ "path_namespace='" +
+ *thisPathString +
+ "',"
+ "member='PropertiesChanged'");
+ // If interfaces weren't specified, add a single match for all
+ // interfaces
+ if (thisSession.interfaces.empty())
{
- interfaceCount = 1;
- }
- // Reserve our matches upfront. For each path there is 1 for
- // interfacesAdded, and InterfaceCount number for
- // PropertiesChanged
- thisSession.matches.reserve(thisSession.matches.size() +
- paths->size() * (1U + interfaceCount));
- std::string objectManagerMatchString;
- std::string propertiesMatchString;
- std::string objectManagerInterfacesMatchString;
- // These regexes derived on the rules here:
- // https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names
- std::regex validPath("^/([A-Za-z0-9_]+/?)*$");
- std::regex validInterface(
- "^[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)+$");
+ BMCWEB_LOG_DEBUG << "Creating match " << propertiesMatchString;
- for (const auto& thisPath : *paths)
- {
- const std::string* thisPathString =
- thisPath.get_ptr<const std::string*>();
- if (thisPathString == nullptr)
- {
- BMCWEB_LOG_ERROR << "subscribe path isn't a string?";
- conn.close();
- return;
- }
- if (!std::regex_match(*thisPathString, validPath))
- {
- BMCWEB_LOG_ERROR << "Invalid path name " << *thisPathString;
- conn.close();
- return;
- }
- propertiesMatchString =
- ("type='signal',"
- "interface='org.freedesktop.DBus.Properties',"
- "path_namespace='" +
- *thisPathString +
- "',"
- "member='PropertiesChanged'");
- // If interfaces weren't specified, add a single match for all
- // interfaces
- if (thisSession.interfaces.empty())
- {
- BMCWEB_LOG_DEBUG << "Creating match "
- << propertiesMatchString;
-
- thisSession.matches.emplace_back(
- std::make_unique<sdbusplus::bus::match::match>(
- *crow::connections::systemBus,
- propertiesMatchString, onPropertyUpdate, &conn));
- }
- else
- {
- // If interfaces were specified, add a match for each
- // interface
- for (const std::string& interface : thisSession.interfaces)
- {
- if (!std::regex_match(interface, validInterface))
- {
- BMCWEB_LOG_ERROR << "Invalid interface name "
- << interface;
- conn.close();
- return;
- }
- std::string ifaceMatchString = propertiesMatchString;
- ifaceMatchString += ",arg0='";
- ifaceMatchString += interface;
- ifaceMatchString += "'";
- BMCWEB_LOG_DEBUG << "Creating match "
- << ifaceMatchString;
- thisSession.matches.emplace_back(
- std::make_unique<sdbusplus::bus::match::match>(
- *crow::connections::systemBus, ifaceMatchString,
- onPropertyUpdate, &conn));
- }
- }
- objectManagerMatchString =
- ("type='signal',"
- "interface='org.freedesktop.DBus.ObjectManager',"
- "path_namespace='" +
- *thisPathString +
- "',"
- "member='InterfacesAdded'");
- BMCWEB_LOG_DEBUG << "Creating match "
- << objectManagerMatchString;
thisSession.matches.emplace_back(
std::make_unique<sdbusplus::bus::match::match>(
- *crow::connections::systemBus, objectManagerMatchString,
+ *crow::connections::systemBus, propertiesMatchString,
onPropertyUpdate, &conn));
}
+ else
+ {
+ // If interfaces were specified, add a match for each
+ // interface
+ for (const std::string& interface : thisSession.interfaces)
+ {
+ if (!std::regex_match(interface, validInterface))
+ {
+ BMCWEB_LOG_ERROR << "Invalid interface name "
+ << interface;
+ conn.close();
+ return;
+ }
+ std::string ifaceMatchString = propertiesMatchString;
+ ifaceMatchString += ",arg0='";
+ ifaceMatchString += interface;
+ ifaceMatchString += "'";
+ BMCWEB_LOG_DEBUG << "Creating match " << ifaceMatchString;
+ thisSession.matches.emplace_back(
+ std::make_unique<sdbusplus::bus::match::match>(
+ *crow::connections::systemBus, ifaceMatchString,
+ onPropertyUpdate, &conn));
+ }
+ }
+ objectManagerMatchString =
+ ("type='signal',"
+ "interface='org.freedesktop.DBus.ObjectManager',"
+ "path_namespace='" +
+ *thisPathString +
+ "',"
+ "member='InterfacesAdded'");
+ BMCWEB_LOG_DEBUG << "Creating match " << objectManagerMatchString;
+ thisSession.matches.emplace_back(
+ std::make_unique<sdbusplus::bus::match::match>(
+ *crow::connections::systemBus, objectManagerMatchString,
+ onPropertyUpdate, &conn));
+ }
});
}
} // namespace dbus_monitor