Skip to content

Commit 5e31f19

Browse files
Install progress reporting fixed
1 parent 490c78b commit 5e31f19

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/FSM/States/Installing.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ namespace sua {
3838
subscribe(Installer::EVENT_INSTALLING, [this, &ctx](const std::map<std::string, std::string>& payload) {
3939
const auto percentage = std::stoi(payload.at("percentage"));
4040
Logger::info("RAUC install progress: {}", percentage);
41-
send(ctx, IMqttProcessor::TOPIC_FEEDBACK, "installing");
41+
ctx.desiredState.installProgressPercentage = percentage;
42+
send(ctx, IMqttProcessor::TOPIC_FEEDBACK, "installing");
4243
});
4344

44-
const auto result = ctx.installerAgent->installBundle(ctx.updatesDirectory + "/temp_file");
45+
auto installer = std::make_shared<Installer>(ctx.installerAgent);
46+
const auto result = installer->start(ctx.updatesDirectory + "/temp_file");
4547

4648
if(result == TechCode::OK) {
4749
Logger::info("RAUC install completed");

src/Install/DummyRaucInstaller.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ namespace sua {
3131

3232
int32_t DummyRaucInstaller::getInstallProgress()
3333
{
34-
return 0;
34+
static int progress = 0;
35+
progress += 1;
36+
progress = std::min(100, progress);
37+
return progress;
3538
}
3639

3740
std::string DummyRaucInstaller::getBundleVersion()

src/Install/Installer.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
#include <gio/gio.h>
2222

23+
#include <chrono>
24+
#include <thread>
25+
26+
using namespace std::chrono_literals;
27+
2328
namespace sua {
2429

2530
const std::string Installer::EVENT_INSTALLING = "Installer/Installing";
@@ -41,17 +46,19 @@ namespace sua {
4146

4247
while(installing) {
4348
progressPercentage = _installerAgent->getInstallProgress();
44-
sleep(2);
49+
std::this_thread::sleep_for(2000ms);
4550
count++;
4651
if(progressPercentage >= 100 || count >= 120) {
4752
installing = false;
4853
}
4954

5055
if(progressPercentage >= progressNotificationLimiter) {
51-
std::map<std::string, std::string> payload;
52-
payload["percentage"] = std::to_string(progressPercentage);
53-
sua::Dispatcher::instance().dispatch(EVENT_INSTALLING, payload);
54-
progressNotificationLimiter += 10;
56+
if(progressPercentage != 100) {
57+
std::map<std::string, std::string> payload;
58+
payload["percentage"] = std::to_string(progressPercentage);
59+
sua::Dispatcher::instance().dispatch(EVENT_INSTALLING, payload);\
60+
}
61+
progressNotificationLimiter += 10;
5562
}
5663
}
5764

0 commit comments

Comments
 (0)