summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-10-05 03:22:56 +0300
committerEd Tanous <ed@tanous.net>2022-12-09 03:10:51 +0300
commitd00907336f7497df6073a668fa8b398e6a12bf5b (patch)
tree6a40565b43ec7b217ae9308887db70838345403d
parent0ec8b83db7e8629c721c0e632de702bf1018f58f (diff)
downloadbmcweb-d00907336f7497df6073a668fa8b398e6a12bf5b.tar.xz
Remove ObjectManager search code in sensors
Per [1], daemons implementing sensors are supposed to implement an ObjectManager at /xyz/openbmc_project/sensors. Once this is made consistent, there is no need for this complex code to search for an ObjectManager instance, when we can simply look it up. This commit deletes the ObjectManager search code, which saves a Dbus call for any sensor read done within thermal or sensor schemas. This does have the negative of requiring that ObjectMapper implements its ObjectManager on "/". Considering there is only one implementation of ObjectMapper, this seems reasonable to hardcode. Tested: Redfish Service Validator passes. ''' curl --insecure --user root:0penBmc https://192.168.10.156/redfish/v1/Chassis/Tyan_S7106_Baseboard/Thermal ''' returns the sensors on an S7106 platform. [1] https://github.com/openbmc/phosphor-dbus-interfaces/blob/991b2b8bdbc950f2a85aebfc29d1b34ea3264686/yaml/xyz/openbmc_project/Sensor/Value.interface.yaml#L18 Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I69071848c685c33320d920d9faec16e5a1b563ca
-rw-r--r--redfish-core/lib/sensors.hpp186
1 files changed, 34 insertions, 152 deletions
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 5bbb642cc4..697bf0db0b 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -593,77 +593,6 @@ void getChassis(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
}
/**
- * @brief Finds all DBus object paths that implement ObjectManager.
- *
- * Creates a mapping from the associated connection name to the object path.
- *
- * Finds the object paths asynchronously. Invokes callback when information has
- * been obtained.
- *
- * The callback must have the following signature:
- * @code
- * callback(std::shared_ptr<std::map<std::string,std::string>> objectMgrPaths)
- * @endcode
- *
- * @param sensorsAsyncResp Pointer to object holding response data.
- * @param callback Callback to invoke when object paths obtained.
- */
-template <typename Callback>
-void getObjectManagerPaths(
- const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
- Callback&& callback)
-{
- BMCWEB_LOG_DEBUG << "getObjectManagerPaths enter";
- const std::array<std::string, 1> interfaces = {
- "org.freedesktop.DBus.ObjectManager"};
-
- // Response handler for GetSubTree DBus method
- auto respHandler =
- [callback{std::forward<Callback>(callback)}, sensorsAsyncResp](
- const boost::system::error_code ec,
- const dbus::utility::MapperGetSubTreeResponse& subtree) {
- BMCWEB_LOG_DEBUG << "getObjectManagerPaths respHandler enter";
- if (ec)
- {
- messages::internalError(sensorsAsyncResp->asyncResp->res);
- BMCWEB_LOG_ERROR << "getObjectManagerPaths respHandler: DBus error "
- << ec;
- return;
- }
-
- // Loop over returned object paths
- std::shared_ptr<std::map<std::string, std::string>> objectMgrPaths =
- std::make_shared<std::map<std::string, std::string>>();
- for (const std::pair<
- std::string,
- std::vector<std::pair<std::string, std::vector<std::string>>>>&
- object : subtree)
- {
- // Loop over connections for current object path
- const std::string& objectPath = object.first;
- for (const std::pair<std::string, std::vector<std::string>>&
- objData : object.second)
- {
- // Add mapping from connection to object path
- const std::string& connection = objData.first;
- (*objectMgrPaths)[connection] = objectPath;
- BMCWEB_LOG_DEBUG << "Added mapping " << connection << " -> "
- << objectPath;
- }
- }
- callback(objectMgrPaths);
- BMCWEB_LOG_DEBUG << "getObjectManagerPaths respHandler exit";
- };
-
- // Query mapper for all DBus object paths that implement ObjectManager
- crow::connections::systemBus->async_method_call(
- std::move(respHandler), "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, interfaces);
- BMCWEB_LOG_DEBUG << "getObjectManagerPaths exit";
-}
-
-/**
* @brief Returns the Redfish State value for the specified inventory item.
* @param inventoryItem D-Bus inventory item associated with a sensor.
* @return State value for inventory item.
@@ -1484,7 +1413,6 @@ inline void storeInventoryItemData(
* @param sensorsAsyncResp Pointer to object holding response data.
* @param inventoryItems D-Bus inventory items associated with sensors.
* @param invConnections Connections that provide data for the inventory items.
- * @param objectMgrPaths Mappings from connection name to DBus object path that
* implements ObjectManager.
* @param callback Callback to invoke when inventory data has been obtained.
* @param invConnectionsIndex Current index in invConnections. Only specified
@@ -1494,9 +1422,8 @@ template <typename Callback>
static void getInventoryItemsData(
std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
std::shared_ptr<std::vector<InventoryItem>> inventoryItems,
- std::shared_ptr<std::set<std::string>> invConnections,
- std::shared_ptr<std::map<std::string, std::string>> objectMgrPaths,
- Callback&& callback, size_t invConnectionsIndex = 0)
+ std::shared_ptr<std::set<std::string>> invConnections, Callback&& callback,
+ size_t invConnectionsIndex = 0)
{
BMCWEB_LOG_DEBUG << "getInventoryItemsData enter";
@@ -1516,11 +1443,11 @@ static void getInventoryItemsData(
const std::string& invConnection = *it;
// Response handler for GetManagedObjects
- auto respHandler =
- [sensorsAsyncResp, inventoryItems, invConnections, objectMgrPaths,
- callback{std::forward<Callback>(callback)}, invConnectionsIndex](
- const boost::system::error_code ec,
- const dbus::utility::ManagedObjectType& resp) {
+ auto respHandler = [sensorsAsyncResp, inventoryItems, invConnections,
+ callback{std::forward<Callback>(callback)},
+ invConnectionsIndex](
+ const boost::system::error_code ec,
+ const dbus::utility::ManagedObjectType& resp) {
BMCWEB_LOG_DEBUG << "getInventoryItemsData respHandler enter";
if (ec)
{
@@ -1548,23 +1475,16 @@ static void getInventoryItemsData(
// Recurse to get inventory item data from next connection
getInventoryItemsData(sensorsAsyncResp, inventoryItems,
- invConnections, objectMgrPaths,
- std::move(callback), invConnectionsIndex + 1);
+ invConnections, std::move(callback),
+ invConnectionsIndex + 1);
BMCWEB_LOG_DEBUG << "getInventoryItemsData respHandler exit";
};
- // Find DBus object path that implements ObjectManager for the current
- // connection. If no mapping found, default to "/".
- auto iter = objectMgrPaths->find(invConnection);
- const std::string& objectMgrPath =
- (iter != objectMgrPaths->end()) ? iter->second : "/";
- BMCWEB_LOG_DEBUG << "ObjectManager path for " << invConnection << " is "
- << objectMgrPath;
-
// Get all object paths and their interfaces for current connection
crow::connections::systemBus->async_method_call(
- std::move(respHandler), invConnection, objectMgrPath,
+ std::move(respHandler), invConnection,
+ "/xyz/openbmc_project/sensors",
"org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
}
@@ -1672,7 +1592,6 @@ static void getInventoryItemsConnections(
*
* @param sensorsAsyncResp Pointer to object holding response data.
* @param sensorNames All sensors within the current chassis.
- * @param objectMgrPaths Mappings from connection name to DBus object path that
* implements ObjectManager.
* @param callback Callback to invoke when inventory items have been obtained.
*/
@@ -1680,7 +1599,6 @@ template <typename Callback>
static void getInventoryItemAssociations(
const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
const std::shared_ptr<std::set<std::string>>& sensorNames,
- const std::shared_ptr<std::map<std::string, std::string>>& objectMgrPaths,
Callback&& callback)
{
BMCWEB_LOG_DEBUG << "getInventoryItemAssociations enter";
@@ -1797,17 +1715,9 @@ static void getInventoryItemAssociations(
BMCWEB_LOG_DEBUG << "getInventoryItemAssociations respHandler exit";
};
- // Find DBus object path that implements ObjectManager for ObjectMapper
- std::string connection = "xyz.openbmc_project.ObjectMapper";
- auto iter = objectMgrPaths->find(connection);
- const std::string& objectMgrPath =
- (iter != objectMgrPaths->end()) ? iter->second : "/";
- BMCWEB_LOG_DEBUG << "ObjectManager path for " << connection << " is "
- << objectMgrPath;
-
// Call GetManagedObjects on the ObjectMapper to get all associations
crow::connections::systemBus->async_method_call(
- std::move(respHandler), connection, objectMgrPath,
+ std::move(respHandler), "xyz.openbmc_project.ObjectMapper", "/",
"org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
BMCWEB_LOG_DEBUG << "getInventoryItemAssociations exit";
@@ -2214,25 +2124,22 @@ void getPowerSupplyAttributes(
*
* @param sensorsAsyncResp Pointer to object holding response data.
* @param sensorNames All sensors within the current chassis.
- * @param objectMgrPaths Mappings from connection name to DBus object path that
* implements ObjectManager.
* @param callback Callback to invoke when inventory items have been obtained.
*/
template <typename Callback>
-static void getInventoryItems(
- std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
- const std::shared_ptr<std::set<std::string>> sensorNames,
- std::shared_ptr<std::map<std::string, std::string>> objectMgrPaths,
- Callback&& callback)
+static void
+ getInventoryItems(std::shared_ptr<SensorsAsyncResp> sensorsAsyncResp,
+ const std::shared_ptr<std::set<std::string>> sensorNames,
+ Callback&& callback)
{
BMCWEB_LOG_DEBUG << "getInventoryItems enter";
auto getInventoryItemAssociationsCb =
- [sensorsAsyncResp, objectMgrPaths,
- callback{std::forward<Callback>(callback)}](
+ [sensorsAsyncResp, callback{std::forward<Callback>(callback)}](
std::shared_ptr<std::vector<InventoryItem>> inventoryItems) {
BMCWEB_LOG_DEBUG << "getInventoryItemAssociationsCb enter";
auto getInventoryItemsConnectionsCb =
- [sensorsAsyncResp, inventoryItems, objectMgrPaths,
+ [sensorsAsyncResp, inventoryItems,
callback{std::forward<const Callback>(callback)}](
std::shared_ptr<std::set<std::string>> invConnections) {
BMCWEB_LOG_DEBUG << "getInventoryItemsConnectionsCb enter";
@@ -2257,7 +2164,7 @@ static void getInventoryItems(
// Get inventory item data from connections
getInventoryItemsData(sensorsAsyncResp, inventoryItems,
- invConnections, objectMgrPaths,
+ invConnections,
std::move(getInventoryItemsDataCb));
BMCWEB_LOG_DEBUG << "getInventoryItemsConnectionsCb exit";
};
@@ -2269,7 +2176,7 @@ static void getInventoryItems(
};
// Get associations from sensors to inventory items
- getInventoryItemAssociations(sensorsAsyncResp, sensorNames, objectMgrPaths,
+ getInventoryItemAssociations(sensorsAsyncResp, sensorNames,
std::move(getInventoryItemAssociationsCb));
BMCWEB_LOG_DEBUG << "getInventoryItems exit";
}
@@ -2345,16 +2252,12 @@ inline nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray,
*
* The connections set contains all the connections that provide sensor values.
*
- * The objectMgrPaths map contains mappings from a connection name to the
- * corresponding DBus object path that implements ObjectManager.
- *
* The InventoryItem vector contains D-Bus inventory items associated with the
* sensors. Inventory item data is needed for some Redfish sensor properties.
*
* @param SensorsAsyncResp Pointer to object holding response data.
* @param sensorNames All requested sensors within the current chassis.
* @param connections Connections that provide sensor values.
- * @param objectMgrPaths Mappings from connection name to DBus object path that
* implements ObjectManager.
* @param inventoryItems Inventory items associated with the sensors.
*/
@@ -2362,7 +2265,6 @@ inline void getSensorData(
const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
const std::shared_ptr<std::set<std::string>>& sensorNames,
const std::set<std::string>& connections,
- const std::shared_ptr<std::map<std::string, std::string>>& objectMgrPaths,
const std::shared_ptr<std::vector<InventoryItem>>& inventoryItems)
{
BMCWEB_LOG_DEBUG << "getSensorData enter";
@@ -2579,16 +2481,8 @@ inline void getSensorData(
BMCWEB_LOG_DEBUG << "getManagedObjectsCb exit";
};
- // Find DBus object path that implements ObjectManager for the current
- // connection. If no mapping found, default to "/".
- auto iter = objectMgrPaths->find(connection);
- const std::string& objectMgrPath =
- (iter != objectMgrPaths->end()) ? iter->second : "/";
- BMCWEB_LOG_DEBUG << "ObjectManager path for " << connection << " is "
- << objectMgrPath;
-
crow::connections::systemBus->async_method_call(
- getManagedObjectsCb, connection, objectMgrPath,
+ getManagedObjectsCb, connection, "/xyz/openbmc_project/sensors",
"org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
}
BMCWEB_LOG_DEBUG << "getSensorData exit";
@@ -2601,33 +2495,21 @@ inline void
auto getConnectionCb = [sensorsAsyncResp, sensorNames](
const std::set<std::string>& connections) {
BMCWEB_LOG_DEBUG << "getConnectionCb enter";
- auto getObjectManagerPathsCb =
- [sensorsAsyncResp, sensorNames, connections](
- const std::shared_ptr<std::map<std::string, std::string>>&
- objectMgrPaths) {
- BMCWEB_LOG_DEBUG << "getObjectManagerPathsCb enter";
- auto getInventoryItemsCb =
- [sensorsAsyncResp, sensorNames, connections, objectMgrPaths](
- const std::shared_ptr<std::vector<InventoryItem>>&
- inventoryItems) {
- BMCWEB_LOG_DEBUG << "getInventoryItemsCb enter";
- // Get sensor data and store results in JSON
- getSensorData(sensorsAsyncResp, sensorNames, connections,
- objectMgrPaths, inventoryItems);
- BMCWEB_LOG_DEBUG << "getInventoryItemsCb exit";
- };
-
- // Get inventory items associated with sensors
- getInventoryItems(sensorsAsyncResp, sensorNames, objectMgrPaths,
- std::move(getInventoryItemsCb));
-
- BMCWEB_LOG_DEBUG << "getObjectManagerPathsCb exit";
+ auto getInventoryItemsCb =
+ [sensorsAsyncResp, sensorNames,
+ connections](const std::shared_ptr<std::vector<InventoryItem>>&
+ inventoryItems) {
+ BMCWEB_LOG_DEBUG << "getInventoryItemsCb enter";
+ // Get sensor data and store results in JSON
+ getSensorData(sensorsAsyncResp, sensorNames, connections,
+ inventoryItems);
+ BMCWEB_LOG_DEBUG << "getInventoryItemsCb exit";
};
- // Get mapping from connection names to the DBus object
- // paths that implement the ObjectManager interface
- getObjectManagerPaths(sensorsAsyncResp,
- std::move(getObjectManagerPathsCb));
+ // Get inventory items associated with sensors
+ getInventoryItems(sensorsAsyncResp, sensorNames,
+ std::move(getInventoryItemsCb));
+
BMCWEB_LOG_DEBUG << "getConnectionCb exit";
};