use async getProperty once io_context is running
Prevent the sync dbus call from reading the dbus messages meant for
async call and potentially cause the async request to miss the message.
The sync call before io_context started running is fine since it will
process all the queued up dbus message once it start running.
Tested:
The property is able to be refreshed with no issue.
Change-Id: I4a0e42275d42e5348c8ed0e30345b0a94c72d564
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/src/power_control.cpp b/src/power_control.cpp
index e6a0548..faefe9b 100644
--- a/src/power_control.cpp
+++ b/src/power_control.cpp
@@ -27,6 +27,7 @@
#include <nlohmann/json.hpp>
#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/object_server.hpp>
+#include <sdbusplus/asio/property.hpp>
#include <filesystem>
#include <fstream>
@@ -2703,14 +2704,22 @@
dBusRetryTimers.erase(configData.name);
return;
}
+ sdbusplus::asio::getProperty<bool>(
+ *conn, configData.dbusName, configData.path, configData.interface,
+ configData.lineName,
+ [&configData](boost::system::error_code ec, bool value) {
+ if (ec)
+ {
+ lg2::error("Exception while reading {PROPERTY}: {WHAT}",
+ "PROPERTY", configData.lineName, "WHAT",
+ ec.message());
+ reschedulePropertyRead(configData);
+ return;
+ }
- int property = getProperty(configData);
-
- if (property >= 0)
- {
- setInitialValue(configData, (property > 0));
- dBusRetryTimers.erase(configData.name);
- }
+ setInitialValue(configData, value);
+ dBusRetryTimers.erase(configData.name);
+ });
});
}
} // namespace power_control