@@ -29,23 +29,49 @@ namespace {
29
29
30
30
namespace sua {
31
31
32
+ void on_completed (
33
+ GDBusConnection * connection,
34
+ const gchar * sender_name,
35
+ const gchar * object_path,
36
+ const gchar * interface_name,
37
+ const gchar * signal_name,
38
+ GVariant * parameters,
39
+ gpointer user_data)
40
+ {
41
+ Logger::trace (" de.pengutronix.rauc.Installer::Completed callback" );
42
+
43
+ int32_t status = 0 ;
44
+ g_variant_get (parameters, " (i)" , &status);
45
+ Logger::trace (" RAUC install status = {}" , status);
46
+
47
+ DBusRaucInstaller * installer = (DBusRaucInstaller *)user_data;
48
+ if (status == 0 ) {
49
+ installer->setSuccess (true );
50
+ } else {
51
+ installer->setSuccess (false );
52
+ }
53
+ installer->setFinished ();
54
+ }
55
+
32
56
DBusRaucInstaller::DBusRaucInstaller ()
33
57
{
34
- Logger::trace (" DBusRaucInstaller::DBusRaucInstaller()" );
35
58
setupDBusRaucConnection ();
36
59
}
37
60
38
61
DBusRaucInstaller::~DBusRaucInstaller ()
39
62
{
40
- Logger::trace (" DBusRaucInstaller::~DBusRaucInstaller()" );
41
63
if (nullptr != connection) {
42
64
g_object_unref (connection);
43
65
}
66
+
67
+ if (nullptr != loop) {
68
+ g_main_loop_unref (loop);
69
+ }
44
70
}
45
71
46
72
TechCode DBusRaucInstaller::installBundle (const std::string& input)
47
73
{
48
- Logger::info (" Installing rauc bundle {}" , input);
74
+ Logger::trace (" Installing rauc bundle {}" , input);
49
75
return installDBusRaucBundle (input);
50
76
}
51
77
@@ -69,8 +95,22 @@ namespace sua {
69
95
GError* connectionError = nullptr ;
70
96
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL , &connectionError);
71
97
98
+ loop = g_main_loop_new (NULL , FALSE );
99
+
100
+ auto id = g_dbus_connection_signal_subscribe (
101
+ connection,
102
+ " de.pengutronix.rauc" ,
103
+ " de.pengutronix.rauc.Installer" ,
104
+ " Completed" ,
105
+ " /" ,
106
+ NULL ,
107
+ G_DBUS_SIGNAL_FLAGS_NONE,
108
+ on_completed,
109
+ this ,
110
+ NULL
111
+ );
72
112
if (nullptr != connection) {
73
- Logger::info (" Valid connection to dbus" );
113
+ Logger::trace (" Valid connection to dbus" );
74
114
} else {
75
115
Logger::error (" Unable to connect to dbus, code = {}, message = {}" ,
76
116
connectionError->code ,
@@ -80,6 +120,9 @@ namespace sua {
80
120
81
121
TechCode DBusRaucInstaller::installDBusRaucBundle (const std::string& bundleName)
82
122
{
123
+ is_installing = true ;
124
+ is_succeeded = false ;
125
+
83
126
GError* connectionError = nullptr ;
84
127
GVariant* result = g_dbus_connection_call_sync (connection,
85
128
" de.pengutronix.rauc" ,
@@ -99,6 +142,10 @@ namespace sua {
99
142
Logger::error (" Install call to Rauc via DBus failed, code = {}, message = {}" ,
100
143
connectionError->code ,
101
144
connectionError->message );
145
+
146
+ is_installing = false ;
147
+ is_succeeded = false ;
148
+
102
149
return TechCode::InstallationFailed;
103
150
}
104
151
@@ -107,7 +154,7 @@ namespace sua {
107
154
108
155
int32_t DBusRaucInstaller::getDBusRaucInstallProgress () const
109
156
{
110
- Logger::info (" Install progress" );
157
+ Logger::trace (" Install progress" );
111
158
GError* connectionError = nullptr ;
112
159
GVariant* progressInfo = g_dbus_connection_call_sync (
113
160
connection,
@@ -129,10 +176,10 @@ namespace sua {
129
176
gchar* message;
130
177
g_variant_get (progressInfo, " (v)" , &internalVal);
131
178
g_variant_get (internalVal, " (isi)" , &progressPercentage, &message, &nesting);
132
- Logger::info (" Installing" );
133
- Logger::info (" message = {}" , message);
134
- Logger::info (" progress percentage = {}" , progressPercentage);
135
- Logger::info ( " nesting = {}" , nesting);
179
+ Logger::trace (" Installing" );
180
+ Logger::trace (" message = {}" , message);
181
+ Logger::trace (" progress percentage = {}" , progressPercentage);
182
+ Logger::trace ( " nesting = {}" , nesting);
136
183
g_variant_unref (progressInfo);
137
184
} else {
138
185
Logger::error (" Connection to DBus lost? code = {}, message = {}" ,
@@ -217,7 +264,7 @@ namespace sua {
217
264
218
265
std::string DBusRaucInstaller::getDBusRaucBundleVersion (const std::string& input) const
219
266
{
220
- Logger::info (" getDBusRaucBundleVersion, input={}" , input);
267
+ Logger::trace (" getDBusRaucBundleVersion, input={}" , input);
221
268
std::string bundleVersion = " bundle_version_not_available" ;
222
269
GError* connectionError = nullptr ;
223
270
GVariant* result = g_dbus_connection_call_sync (connection,
@@ -233,21 +280,74 @@ namespace sua {
233
280
&connectionError);
234
281
235
282
if (nullptr != result) {
236
- Logger::info (" Retrieved the version data, processing..." );
283
+ Logger::trace (" Retrieved the version data, processing..." );
237
284
gchar* compatible;
238
285
gchar* version;
239
286
g_variant_get (result, " (ss)" , &compatible, &version);
240
287
bundleVersion = std::string (version);
241
- Logger::info (" Version of downloaded bundle: {}" , bundleVersion);
288
+ Logger::trace (" Version of downloaded bundle: {}" , bundleVersion);
242
289
g_free (compatible);
243
290
g_free (version);
244
291
} else {
245
- Logger::info (" Retrieval of bundle version was not succesfull, error {}" ,
292
+ Logger::trace (" Retrieval of bundle version was not succesfull, error {}" ,
246
293
connectionError->message );
247
294
}
248
295
249
- Logger::info (" Retrieved version of the incoming bundle is: " + bundleVersion);
296
+ Logger::trace (" Retrieved version of the incoming bundle is: " + bundleVersion);
250
297
return bundleVersion;
251
298
}
252
299
300
+ std::string DBusRaucInstaller::getLastError ()
301
+ {
302
+ GError* connectionError = nullptr ;
303
+ GVariant* lastErrorInfo = g_dbus_connection_call_sync (
304
+ connection,
305
+ " de.pengutronix.rauc" ,
306
+ " /" ,
307
+ " org.freedesktop.DBus.Properties" ,
308
+ " Get" ,
309
+ g_variant_new (" (ss)" , " de.pengutronix.rauc.Installer" , " LastError" ),
310
+ NULL ,
311
+ G_DBUS_CALL_FLAGS_NONE,
312
+ -1 ,
313
+ NULL ,
314
+ &connectionError);
315
+
316
+ std::string lastError;
317
+ if (nullptr != lastErrorInfo) {
318
+ GVariant* internalVal;
319
+ gchar* message;
320
+ g_variant_get (lastErrorInfo, " (v)" , &internalVal);
321
+ g_variant_get (internalVal, " s" , &message);
322
+ g_variant_unref (lastErrorInfo);
323
+ lastError = message;
324
+ } else {
325
+ Logger::error (" Connection to DBus lost? code = {}, message = {}" ,
326
+ connectionError->code ,
327
+ connectionError->message );
328
+ }
329
+ return lastError;
330
+ }
331
+
332
+ bool DBusRaucInstaller::installing ()
333
+ {
334
+ g_main_context_iteration (g_main_loop_get_context (loop), FALSE );
335
+ return is_installing;
336
+ }
337
+
338
+ bool DBusRaucInstaller::succeeded ()
339
+ {
340
+ return is_succeeded;
341
+ }
342
+
343
+ void DBusRaucInstaller::setSuccess (const bool value)
344
+ {
345
+ is_succeeded = value;
346
+ }
347
+
348
+ void DBusRaucInstaller::setFinished ()
349
+ {
350
+ is_installing = false ;
351
+ }
352
+
253
353
} // namespace sua
0 commit comments