Populate info in background thread
This change incorporates
https://gerrit.openbmc.org/c/openbmc/openbmc-tools/+/50784 and
https://gerrit.openbmc.org/c/openbmc/openbmc-tools/+/50088.
The function `ListAllSensors` populates a list of DBus sensor objects.
Currently it runs in the main thread before the UI gets created.
To enhance user experience, this routine is moved to a separate thread,
so the information is populated by that thread, so the main thread does
not get blocked while the list is being filled.
Originally, change 50784's ListAllSensors function includes the
following steps:
1) List DBus connections currently on the Bus
2) Get Creds for each of the DBus connections
3) Examine objects in ObjectMapper to ..
* See if they are Sensor objects
* If so mark a "Sensor" as "visible in ObjectMapper"
4) List all Associations recorded in the ObjectMapper
* So they can be shown in the sensor info panel
5) Find association definitions
6) Find association endpoints
7) Check all objects from HwMon daemons
* Objects from the DBus-Sensors daemon will be added later
8) Check `ipmitool sdr`
Step 8) is currently removed in this change since running `ipmitool sdr`
can potentially take a long time.
Change-Id: If6f27f130060b52e22c405942a861ba40e45ced2
Signed-off-by: Sui Chen <suichen6@gmail.com>
diff --git a/sensorhelper.hpp b/sensorhelper.hpp
index 3aa7c0f..1228339 100644
--- a/sensorhelper.hpp
+++ b/sensorhelper.hpp
@@ -18,12 +18,15 @@
// This is the form a sensor assumes on DBus.
// Aggregates their view from all other daemons.
#include <bitset>
+#include <map>
#include <optional>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
+
+std::pair<std::string, std::string> ExtractFileName(std::string x);
// Where is this sensor seen?
constexpr int VISIBILITY_OBJECT_MAPPER = 0;
constexpr int VISIBILITY_HWMON = 1;
@@ -226,6 +229,11 @@
return ret;
}
+ explicit SensorSnapshot()
+ {
+ connection_snapshot_ = nullptr;
+ }
+
explicit SensorSnapshot(DBusConnectionSnapshot* cs)
{
connection_snapshot_ = cs;
@@ -285,7 +293,7 @@
}
// This sensor is visible from Object Mapper
- void SerSensorVisibleFromObjectMapper(const std::string& service,
+ void SetSensorVisibleFromObjectMapper(const std::string& service,
const std::string& object)
{
Sensor* s = FindOrCreateSensorByServiceAndObject(service, object);
@@ -329,10 +337,63 @@
return nullptr;
}
+ void AddAssociationEndpoints(const std::string& path,
+ const std::set<std::string>& entries)
+ {
+ associations_[path] = entries;
+ }
+
+ // Input: object path (regardless of what service name)
+ // out_edges: what associations does `path` declare?
+ // in_edges: what associations have `path` as endpoints?
+ void FindAssociationEndpoints(
+ const std::string& path,
+ std::map<std::string, std::set<std::string>>* out_edges,
+ std::map<std::string, std::set<std::string>>* in_edges)
+ {
+ std::map<std::string, std::set<std::string>> out, in;
+ for (const auto& [k, v] : associations_)
+ {
+ if (k.find(path) == 0)
+ {
+ out[k.substr(path.size())] = v;
+ }
+ for (const std::string& entry : v)
+ {
+ if (entry.find(path) == 0)
+ {
+ std::pair<std::string, std::string> p = ExtractFileName(k);
+ in[p.second].insert(k);
+ }
+ }
+ }
+
+ *out_edges = out;
+ *in_edges = in;
+ }
+
+ void AddAssociationDefinition(const std::string& path,
+ const std::string& forward,
+ const std::string& reverse,
+ const std::string& endpoint)
+ {
+ std::vector<std::string> d = {path, forward, reverse, endpoint};
+ association_definitions_.push_back(d);
+ }
+
private:
std::vector<Sensor*> sensors_;
std::unordered_map<std::string, int> conn2pid_;
DBusConnectionSnapshot* connection_snapshot_;
+
+ // Associations seen from Inventory objects
+ // Key: the path of the object that has the Association interface
+ // Value: all the endpoints
+ std::unordered_map<std::string, std::set<std::string>> associations_;
+
+ // Association Definitions
+ // Ideally, this should match associations_ above
+ std::vector<std::vector<std::string>> association_definitions_;
};
bool IsSensorObjectPath(const std::string& s);