/src/fwupd/libfwupd/fwupd-request.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2021 Richard Hughes <richard@hughsie.com> |
3 | | * |
4 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
5 | | */ |
6 | | |
7 | | #include "config.h" |
8 | | |
9 | | #include "fwupd-codec.h" |
10 | | #include "fwupd-enums-private.h" |
11 | | #include "fwupd-request-private.h" |
12 | | #include "fwupd-variant.h" |
13 | | |
14 | | /** |
15 | | * FwupdRequest: |
16 | | * |
17 | | * A user request from the device. |
18 | | * |
19 | | * See also: [class@FwupdDevice] |
20 | | */ |
21 | | |
22 | | typedef struct { |
23 | | gchar *id; |
24 | | FwupdRequestKind kind; |
25 | | FwupdRequestFlags flags; |
26 | | guint64 created; |
27 | | gchar *device_id; |
28 | | gchar *message; |
29 | | gchar *image; |
30 | | } FwupdRequestPrivate; |
31 | | |
32 | | enum { SIGNAL_INVALIDATE, SIGNAL_LAST }; |
33 | | |
34 | | enum { |
35 | | PROP_0, |
36 | | PROP_ID, |
37 | | PROP_KIND, |
38 | | PROP_FLAGS, |
39 | | PROP_MESSAGE, |
40 | | PROP_IMAGE, |
41 | | PROP_DEVICE_ID, |
42 | | PROP_LAST |
43 | | }; |
44 | | |
45 | | static guint signals[SIGNAL_LAST] = {0}; |
46 | | |
47 | | static void |
48 | | fwupd_request_codec_iface_init(FwupdCodecInterface *iface); |
49 | | |
50 | 2 | G_DEFINE_TYPE_EXTENDED(FwupdRequest, |
51 | 2 | fwupd_request, |
52 | 2 | G_TYPE_OBJECT, |
53 | 2 | 0, |
54 | 2 | G_ADD_PRIVATE(FwupdRequest) |
55 | 2 | G_IMPLEMENT_INTERFACE(FWUPD_TYPE_CODEC, fwupd_request_codec_iface_init)); |
56 | 2 | |
57 | 2 | #define GET_PRIVATE(o) (fwupd_request_get_instance_private(o)) |
58 | | |
59 | | /** |
60 | | * fwupd_request_emit_invalidate: |
61 | | * @self: a #FwupdRequest |
62 | | * |
63 | | * Emits an `invalidate` signal to signify that the request is no longer valid, and any visible |
64 | | * UI components should be hidden. |
65 | | * |
66 | | * Since: 1.9.17 |
67 | | **/ |
68 | | void |
69 | | fwupd_request_emit_invalidate(FwupdRequest *self) |
70 | 0 | { |
71 | 0 | g_return_if_fail(FWUPD_IS_REQUEST(self)); |
72 | 0 | g_debug("emitting FwupdRequest::invalidate()"); |
73 | 0 | g_signal_emit(self, signals[SIGNAL_INVALIDATE], 0); |
74 | 0 | } |
75 | | |
76 | | /** |
77 | | * fwupd_request_get_id: |
78 | | * @self: a #FwupdRequest |
79 | | * |
80 | | * Gets the ID. |
81 | | * |
82 | | * Returns: the ID, or %NULL if unset |
83 | | * |
84 | | * Since: 1.6.2 |
85 | | **/ |
86 | | const gchar * |
87 | | fwupd_request_get_id(FwupdRequest *self) |
88 | 0 | { |
89 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
90 | 0 | g_return_val_if_fail(FWUPD_IS_REQUEST(self), NULL); |
91 | 0 | return priv->id; |
92 | 0 | } |
93 | | |
94 | | /** |
95 | | * fwupd_request_set_id: |
96 | | * @self: a #FwupdRequest |
97 | | * @id: (nullable): the request ID, e.g. `USB:foo` |
98 | | * |
99 | | * Sets the ID. |
100 | | * |
101 | | * Since: 1.6.2 |
102 | | **/ |
103 | | void |
104 | | fwupd_request_set_id(FwupdRequest *self, const gchar *id) |
105 | 0 | { |
106 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
107 | 0 | g_return_if_fail(FWUPD_IS_REQUEST(self)); |
108 | 0 | g_set_str(&priv->id, id); |
109 | 0 | } |
110 | | |
111 | | /** |
112 | | * fwupd_request_get_device_id: |
113 | | * @self: a #FwupdRequest |
114 | | * |
115 | | * Gets the device_id that created the request. |
116 | | * |
117 | | * Returns: the device_id, or %NULL if unset |
118 | | * |
119 | | * Since: 1.6.2 |
120 | | **/ |
121 | | const gchar * |
122 | | fwupd_request_get_device_id(FwupdRequest *self) |
123 | 0 | { |
124 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
125 | 0 | g_return_val_if_fail(FWUPD_IS_REQUEST(self), NULL); |
126 | 0 | return priv->device_id; |
127 | 0 | } |
128 | | |
129 | | /** |
130 | | * fwupd_request_set_device_id: |
131 | | * @self: a #FwupdRequest |
132 | | * @device_id: (nullable): the device_id, e.g. `colorhug` |
133 | | * |
134 | | * Sets the device_id that created the request. |
135 | | * |
136 | | * Since: 1.6.2 |
137 | | **/ |
138 | | void |
139 | | fwupd_request_set_device_id(FwupdRequest *self, const gchar *device_id) |
140 | 0 | { |
141 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
142 | 0 | g_return_if_fail(FWUPD_IS_REQUEST(self)); |
143 | 0 | g_set_str(&priv->device_id, device_id); |
144 | 0 | } |
145 | | |
146 | | /** |
147 | | * fwupd_request_get_created: |
148 | | * @self: a #FwupdRequest |
149 | | * |
150 | | * Gets when the request was created. |
151 | | * |
152 | | * Returns: the UNIX time, or 0 if unset |
153 | | * |
154 | | * Since: 1.6.2 |
155 | | **/ |
156 | | guint64 |
157 | | fwupd_request_get_created(FwupdRequest *self) |
158 | 0 | { |
159 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
160 | 0 | g_return_val_if_fail(FWUPD_IS_REQUEST(self), 0); |
161 | 0 | return priv->created; |
162 | 0 | } |
163 | | |
164 | | /** |
165 | | * fwupd_request_set_created: |
166 | | * @self: a #FwupdRequest |
167 | | * @created: the UNIX time |
168 | | * |
169 | | * Sets when the request was created. |
170 | | * |
171 | | * Since: 1.6.2 |
172 | | **/ |
173 | | void |
174 | | fwupd_request_set_created(FwupdRequest *self, guint64 created) |
175 | 0 | { |
176 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
177 | 0 | g_return_if_fail(FWUPD_IS_REQUEST(self)); |
178 | 0 | priv->created = created; |
179 | 0 | } |
180 | | |
181 | | static void |
182 | | fwupd_request_add_variant(FwupdCodec *codec, GVariantBuilder *builder, FwupdCodecFlags flags) |
183 | 0 | { |
184 | 0 | FwupdRequest *self = FWUPD_REQUEST(codec); |
185 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
186 | |
|
187 | 0 | if (priv->id != NULL) { |
188 | 0 | g_variant_builder_add(builder, |
189 | 0 | "{sv}", |
190 | 0 | FWUPD_RESULT_KEY_APPSTREAM_ID, |
191 | 0 | g_variant_new_string(priv->id)); |
192 | 0 | } |
193 | 0 | if (priv->created > 0) { |
194 | 0 | g_variant_builder_add(builder, |
195 | 0 | "{sv}", |
196 | 0 | FWUPD_RESULT_KEY_CREATED, |
197 | 0 | g_variant_new_uint64(priv->created)); |
198 | 0 | } |
199 | 0 | if (priv->device_id != NULL) { |
200 | 0 | g_variant_builder_add(builder, |
201 | 0 | "{sv}", |
202 | 0 | FWUPD_RESULT_KEY_DEVICE_ID, |
203 | 0 | g_variant_new_string(priv->device_id)); |
204 | 0 | } |
205 | 0 | if (priv->message != NULL) { |
206 | 0 | g_variant_builder_add(builder, |
207 | 0 | "{sv}", |
208 | 0 | FWUPD_RESULT_KEY_UPDATE_MESSAGE, |
209 | 0 | g_variant_new_string(priv->message)); |
210 | 0 | } |
211 | 0 | if (priv->image != NULL) { |
212 | 0 | g_variant_builder_add(builder, |
213 | 0 | "{sv}", |
214 | 0 | FWUPD_RESULT_KEY_UPDATE_IMAGE, |
215 | 0 | g_variant_new_string(priv->image)); |
216 | 0 | } |
217 | 0 | if (priv->kind != FWUPD_REQUEST_KIND_UNKNOWN) { |
218 | 0 | g_variant_builder_add(builder, |
219 | 0 | "{sv}", |
220 | 0 | FWUPD_RESULT_KEY_REQUEST_KIND, |
221 | 0 | g_variant_new_uint32(priv->kind)); |
222 | 0 | } |
223 | 0 | if (priv->flags != FWUPD_REQUEST_FLAG_NONE) { |
224 | 0 | g_variant_builder_add(builder, |
225 | 0 | "{sv}", |
226 | 0 | FWUPD_RESULT_KEY_FLAGS, |
227 | 0 | g_variant_new_uint64(priv->flags)); |
228 | 0 | } |
229 | 0 | } |
230 | | |
231 | | static void |
232 | | fwupd_request_from_key_value(FwupdRequest *self, const gchar *key, GVariant *value) |
233 | 0 | { |
234 | 0 | if (g_strcmp0(key, FWUPD_RESULT_KEY_APPSTREAM_ID) == 0) { |
235 | 0 | fwupd_request_set_id(self, fwupd_variant_get_string(value)); |
236 | 0 | return; |
237 | 0 | } |
238 | 0 | if (g_strcmp0(key, FWUPD_RESULT_KEY_CREATED) == 0) { |
239 | 0 | fwupd_request_set_created(self, fwupd_variant_get_uint64(value)); |
240 | 0 | return; |
241 | 0 | } |
242 | 0 | if (g_strcmp0(key, FWUPD_RESULT_KEY_DEVICE_ID) == 0) { |
243 | 0 | fwupd_request_set_device_id(self, fwupd_variant_get_string(value)); |
244 | 0 | return; |
245 | 0 | } |
246 | 0 | if (g_strcmp0(key, FWUPD_RESULT_KEY_UPDATE_MESSAGE) == 0) { |
247 | 0 | fwupd_request_set_message(self, fwupd_variant_get_string(value)); |
248 | 0 | return; |
249 | 0 | } |
250 | 0 | if (g_strcmp0(key, FWUPD_RESULT_KEY_UPDATE_IMAGE) == 0) { |
251 | 0 | fwupd_request_set_image(self, fwupd_variant_get_string(value)); |
252 | 0 | return; |
253 | 0 | } |
254 | 0 | if (g_strcmp0(key, FWUPD_RESULT_KEY_REQUEST_KIND) == 0) { |
255 | 0 | fwupd_request_set_kind(self, fwupd_variant_get_uint32(value)); |
256 | 0 | return; |
257 | 0 | } |
258 | 0 | if (g_strcmp0(key, FWUPD_RESULT_KEY_FLAGS) == 0) { |
259 | 0 | fwupd_request_set_flags(self, fwupd_variant_get_uint64(value)); |
260 | 0 | return; |
261 | 0 | } |
262 | 0 | } |
263 | | |
264 | | /** |
265 | | * fwupd_request_get_message: |
266 | | * @self: a #FwupdRequest |
267 | | * |
268 | | * Gets the update message, generating a generic one using the request ID if possible. |
269 | | * |
270 | | * Returns: the update message, or %NULL if unset |
271 | | * |
272 | | * Since: 1.6.2 |
273 | | **/ |
274 | | const gchar * |
275 | | fwupd_request_get_message(FwupdRequest *self) |
276 | 0 | { |
277 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
278 | 0 | g_return_val_if_fail(FWUPD_IS_REQUEST(self), NULL); |
279 | | |
280 | | /* something custom */ |
281 | 0 | if (priv->message != NULL) |
282 | 0 | return priv->message; |
283 | | |
284 | | /* untranslated canned messages */ |
285 | 0 | if (fwupd_request_has_flag(self, FWUPD_REQUEST_FLAG_ALLOW_GENERIC_MESSAGE)) { |
286 | 0 | if (g_strcmp0(priv->id, FWUPD_REQUEST_ID_REMOVE_REPLUG) == 0) |
287 | 0 | return "Please unplug and then re-insert the device USB cable."; |
288 | 0 | if (g_strcmp0(priv->id, FWUPD_REQUEST_ID_INSERT_USB_CABLE) == 0) |
289 | 0 | return "Please re-insert the device USB cable."; |
290 | 0 | if (g_strcmp0(priv->id, FWUPD_REQUEST_ID_REMOVE_USB_CABLE) == 0) |
291 | 0 | return "Please unplug the device USB cable."; |
292 | 0 | if (g_strcmp0(priv->id, FWUPD_REQUEST_ID_REPLUG_POWER) == 0) |
293 | 0 | return "Please unplug and then re-insert the device power cable."; |
294 | 0 | if (g_strcmp0(priv->id, FWUPD_REQUEST_ID_PRESS_UNLOCK) == 0) |
295 | 0 | return "Press unlock on the device."; |
296 | 0 | if (g_strcmp0(priv->id, FWUPD_REQUEST_ID_DO_NOT_POWER_OFF) == 0) |
297 | 0 | return "Do not turn off your computer or remove the AC adaptor."; |
298 | 0 | if (g_strcmp0(priv->id, FWUPD_REQUEST_ID_RESTART_DAEMON) == 0) |
299 | 0 | return "Please restart the fwupd service."; |
300 | 0 | } |
301 | | |
302 | | /* unknown */ |
303 | 0 | return NULL; |
304 | 0 | } |
305 | | |
306 | | /** |
307 | | * fwupd_request_set_message: |
308 | | * @self: a #FwupdRequest |
309 | | * @message: (nullable): the update message string |
310 | | * |
311 | | * Sets the update message. |
312 | | * |
313 | | * Since: 1.6.2 |
314 | | **/ |
315 | | void |
316 | | fwupd_request_set_message(FwupdRequest *self, const gchar *message) |
317 | 0 | { |
318 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
319 | 0 | g_return_if_fail(FWUPD_IS_REQUEST(self)); |
320 | 0 | if (g_set_str(&priv->message, message)) |
321 | 0 | g_object_notify(G_OBJECT(self), "message"); |
322 | 0 | } |
323 | | |
324 | | /** |
325 | | * fwupd_request_get_image: |
326 | | * @self: a #FwupdRequest |
327 | | * |
328 | | * Gets the update image. |
329 | | * |
330 | | * Returns: the update image URL, or %NULL if unset |
331 | | * |
332 | | * Since: 1.6.2 |
333 | | **/ |
334 | | const gchar * |
335 | | fwupd_request_get_image(FwupdRequest *self) |
336 | 0 | { |
337 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
338 | 0 | g_return_val_if_fail(FWUPD_IS_REQUEST(self), NULL); |
339 | 0 | return priv->image; |
340 | 0 | } |
341 | | |
342 | | /** |
343 | | * fwupd_request_set_image: |
344 | | * @self: a #FwupdRequest |
345 | | * @image: (nullable): the update image URL |
346 | | * |
347 | | * Sets the update image. |
348 | | * |
349 | | * Since: 1.6.2 |
350 | | **/ |
351 | | void |
352 | | fwupd_request_set_image(FwupdRequest *self, const gchar *image) |
353 | 0 | { |
354 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
355 | 0 | g_return_if_fail(FWUPD_IS_REQUEST(self)); |
356 | 0 | if (g_set_str(&priv->image, image)) |
357 | 0 | g_object_notify(G_OBJECT(self), "image"); |
358 | 0 | } |
359 | | |
360 | | /** |
361 | | * fwupd_request_get_kind: |
362 | | * @self: a #FwupdRequest |
363 | | * |
364 | | * Returns what the request is currently doing. |
365 | | * |
366 | | * Returns: the kind value, e.g. %FWUPD_STATUS_REQUEST_WRITE |
367 | | * |
368 | | * Since: 1.6.2 |
369 | | **/ |
370 | | FwupdRequestKind |
371 | | fwupd_request_get_kind(FwupdRequest *self) |
372 | 0 | { |
373 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
374 | 0 | g_return_val_if_fail(FWUPD_IS_REQUEST(self), 0); |
375 | 0 | return priv->kind; |
376 | 0 | } |
377 | | |
378 | | /** |
379 | | * fwupd_request_set_kind: |
380 | | * @self: a #FwupdRequest |
381 | | * @kind: the kind value, e.g. %FWUPD_STATUS_REQUEST_WRITE |
382 | | * |
383 | | * Sets what the request is currently doing. |
384 | | * |
385 | | * Since: 1.6.2 |
386 | | **/ |
387 | | void |
388 | | fwupd_request_set_kind(FwupdRequest *self, FwupdRequestKind kind) |
389 | 0 | { |
390 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
391 | 0 | g_return_if_fail(FWUPD_IS_REQUEST(self)); |
392 | 0 | if (priv->kind == kind) |
393 | 0 | return; |
394 | 0 | priv->kind = kind; |
395 | 0 | g_object_notify(G_OBJECT(self), "kind"); |
396 | 0 | } |
397 | | |
398 | | /** |
399 | | * fwupd_request_get_flags: |
400 | | * @self: a #FwupdRequest |
401 | | * |
402 | | * Gets the request flags. |
403 | | * |
404 | | * Returns: request flags, or 0 if unset |
405 | | * |
406 | | * Since: 1.8.6 |
407 | | **/ |
408 | | FwupdRequestFlags |
409 | | fwupd_request_get_flags(FwupdRequest *self) |
410 | 0 | { |
411 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
412 | 0 | g_return_val_if_fail(FWUPD_IS_REQUEST(self), 0); |
413 | 0 | return priv->flags; |
414 | 0 | } |
415 | | |
416 | | /** |
417 | | * fwupd_request_set_flags: |
418 | | * @self: a #FwupdRequest |
419 | | * @flags: request flags, e.g. %FWUPD_REQUEST_FLAG_NONE |
420 | | * |
421 | | * Sets the request flags. |
422 | | * |
423 | | * Since: 1.8.6 |
424 | | **/ |
425 | | void |
426 | | fwupd_request_set_flags(FwupdRequest *self, FwupdRequestFlags flags) |
427 | 0 | { |
428 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
429 | 0 | g_return_if_fail(FWUPD_IS_REQUEST(self)); |
430 | | |
431 | | /* not changed */ |
432 | 0 | if (priv->flags == flags) |
433 | 0 | return; |
434 | | |
435 | 0 | priv->flags = flags; |
436 | 0 | g_object_notify(G_OBJECT(self), "flags"); |
437 | 0 | } |
438 | | |
439 | | /** |
440 | | * fwupd_request_add_flag: |
441 | | * @self: a #FwupdRequest |
442 | | * @flag: the #FwupdRequestFlags |
443 | | * |
444 | | * Adds a specific flag to the request. |
445 | | * |
446 | | * Since: 1.8.6 |
447 | | **/ |
448 | | void |
449 | | fwupd_request_add_flag(FwupdRequest *self, FwupdRequestFlags flag) |
450 | 0 | { |
451 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
452 | 0 | g_return_if_fail(FWUPD_IS_REQUEST(self)); |
453 | 0 | priv->flags |= flag; |
454 | 0 | } |
455 | | |
456 | | /** |
457 | | * fwupd_request_remove_flag: |
458 | | * @self: a #FwupdRequest |
459 | | * @flag: the #FwupdRequestFlags |
460 | | * |
461 | | * Removes a specific flag from the request. |
462 | | * |
463 | | * Since: 1.8.6 |
464 | | **/ |
465 | | void |
466 | | fwupd_request_remove_flag(FwupdRequest *self, FwupdRequestFlags flag) |
467 | 0 | { |
468 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
469 | 0 | g_return_if_fail(FWUPD_IS_REQUEST(self)); |
470 | 0 | priv->flags &= ~flag; |
471 | 0 | } |
472 | | |
473 | | /** |
474 | | * fwupd_request_has_flag: |
475 | | * @self: a #FwupdRequest |
476 | | * @flag: the #FwupdRequestFlags |
477 | | * |
478 | | * Finds if the request has a specific flag. |
479 | | * |
480 | | * Returns: %TRUE if the flag is set |
481 | | * |
482 | | * Since: 1.8.6 |
483 | | **/ |
484 | | gboolean |
485 | | fwupd_request_has_flag(FwupdRequest *self, FwupdRequestFlags flag) |
486 | 0 | { |
487 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
488 | 0 | g_return_val_if_fail(FWUPD_IS_REQUEST(self), FALSE); |
489 | 0 | return (priv->flags & flag) > 0; |
490 | 0 | } |
491 | | |
492 | | static void |
493 | | fwupd_request_add_string(FwupdCodec *codec, guint idt, GString *str) |
494 | 0 | { |
495 | 0 | FwupdRequest *self = FWUPD_REQUEST(codec); |
496 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
497 | 0 | fwupd_codec_string_append(str, idt, FWUPD_RESULT_KEY_APPSTREAM_ID, priv->id); |
498 | 0 | if (priv->kind != FWUPD_REQUEST_KIND_UNKNOWN) { |
499 | 0 | fwupd_codec_string_append(str, |
500 | 0 | idt, |
501 | 0 | FWUPD_RESULT_KEY_REQUEST_KIND, |
502 | 0 | fwupd_request_kind_to_string(priv->kind)); |
503 | 0 | } |
504 | 0 | fwupd_codec_string_append(str, |
505 | 0 | idt, |
506 | 0 | FWUPD_RESULT_KEY_FLAGS, |
507 | 0 | fwupd_request_flag_to_string(priv->flags)); |
508 | 0 | fwupd_codec_string_append(str, idt, FWUPD_RESULT_KEY_DEVICE_ID, priv->device_id); |
509 | 0 | fwupd_codec_string_append_time(str, idt, FWUPD_RESULT_KEY_CREATED, priv->created); |
510 | 0 | fwupd_codec_string_append(str, idt, FWUPD_RESULT_KEY_UPDATE_MESSAGE, priv->message); |
511 | 0 | fwupd_codec_string_append(str, idt, FWUPD_RESULT_KEY_UPDATE_IMAGE, priv->image); |
512 | 0 | } |
513 | | |
514 | | static void |
515 | | fwupd_request_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) |
516 | 0 | { |
517 | 0 | FwupdRequest *self = FWUPD_REQUEST(object); |
518 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
519 | 0 | switch (prop_id) { |
520 | 0 | case PROP_ID: |
521 | 0 | g_value_set_string(value, priv->id); |
522 | 0 | break; |
523 | 0 | case PROP_MESSAGE: |
524 | 0 | g_value_set_string(value, priv->message); |
525 | 0 | break; |
526 | 0 | case PROP_IMAGE: |
527 | 0 | g_value_set_string(value, priv->image); |
528 | 0 | break; |
529 | 0 | case PROP_DEVICE_ID: |
530 | 0 | g_value_set_string(value, priv->device_id); |
531 | 0 | break; |
532 | 0 | case PROP_KIND: |
533 | 0 | g_value_set_uint(value, priv->kind); |
534 | 0 | break; |
535 | 0 | case PROP_FLAGS: |
536 | 0 | g_value_set_uint64(value, priv->flags); |
537 | 0 | break; |
538 | 0 | default: |
539 | 0 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); |
540 | 0 | break; |
541 | 0 | } |
542 | 0 | } |
543 | | |
544 | | static void |
545 | | fwupd_request_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) |
546 | 0 | { |
547 | 0 | FwupdRequest *self = FWUPD_REQUEST(object); |
548 | 0 | switch (prop_id) { |
549 | 0 | case PROP_ID: |
550 | 0 | fwupd_request_set_id(self, g_value_get_string(value)); |
551 | 0 | break; |
552 | 0 | case PROP_MESSAGE: |
553 | 0 | fwupd_request_set_message(self, g_value_get_string(value)); |
554 | 0 | break; |
555 | 0 | case PROP_IMAGE: |
556 | 0 | fwupd_request_set_image(self, g_value_get_string(value)); |
557 | 0 | break; |
558 | 0 | case PROP_DEVICE_ID: |
559 | 0 | fwupd_request_set_device_id(self, g_value_get_string(value)); |
560 | 0 | break; |
561 | 0 | case PROP_KIND: |
562 | 0 | fwupd_request_set_kind(self, g_value_get_uint(value)); |
563 | 0 | break; |
564 | 0 | case PROP_FLAGS: |
565 | 0 | fwupd_request_set_flags(self, g_value_get_uint64(value)); |
566 | 0 | break; |
567 | 0 | default: |
568 | 0 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); |
569 | 0 | break; |
570 | 0 | } |
571 | 0 | } |
572 | | |
573 | | static void |
574 | | fwupd_request_finalize(GObject *object) |
575 | 0 | { |
576 | 0 | FwupdRequest *self = FWUPD_REQUEST(object); |
577 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
578 | |
|
579 | 0 | g_free(priv->id); |
580 | 0 | g_free(priv->device_id); |
581 | 0 | g_free(priv->message); |
582 | 0 | g_free(priv->image); |
583 | |
|
584 | 0 | G_OBJECT_CLASS(fwupd_request_parent_class)->finalize(object); |
585 | 0 | } |
586 | | |
587 | | static void |
588 | | fwupd_request_init(FwupdRequest *self) |
589 | 0 | { |
590 | 0 | FwupdRequestPrivate *priv = GET_PRIVATE(self); |
591 | 0 | priv->created = g_get_real_time() / G_USEC_PER_SEC; |
592 | 0 | } |
593 | | |
594 | | static void |
595 | | fwupd_request_class_init(FwupdRequestClass *klass) |
596 | 0 | { |
597 | 0 | GObjectClass *object_class = G_OBJECT_CLASS(klass); |
598 | 0 | GParamSpec *pspec; |
599 | |
|
600 | 0 | object_class->finalize = fwupd_request_finalize; |
601 | 0 | object_class->get_property = fwupd_request_get_property; |
602 | 0 | object_class->set_property = fwupd_request_set_property; |
603 | | |
604 | | /** |
605 | | * FwupdRequest::invalidate: |
606 | | * @self: the #FwupdRequest instance that emitted the signal |
607 | | * |
608 | | * The ::invalidate signal is emitted when the request is no longer valid, and any visible |
609 | | * UI components should be hidden. |
610 | | * |
611 | | * Since: 1.9.17 |
612 | | **/ |
613 | 0 | signals[SIGNAL_INVALIDATE] = g_signal_new("invalidate", |
614 | 0 | G_TYPE_FROM_CLASS(object_class), |
615 | 0 | G_SIGNAL_RUN_LAST, |
616 | 0 | G_STRUCT_OFFSET(FwupdRequestClass, invalidate), |
617 | 0 | NULL, |
618 | 0 | NULL, |
619 | 0 | g_cclosure_marshal_VOID__VOID, |
620 | 0 | G_TYPE_NONE, |
621 | 0 | 0); |
622 | | |
623 | | /** |
624 | | * FwupdRequest:id: |
625 | | * |
626 | | * The request identifier. |
627 | | * |
628 | | * Since: 1.6.2 |
629 | | */ |
630 | 0 | pspec = |
631 | 0 | g_param_spec_string("id", NULL, NULL, NULL, G_PARAM_READWRITE | G_PARAM_STATIC_NAME); |
632 | 0 | g_object_class_install_property(object_class, PROP_ID, pspec); |
633 | | |
634 | | /** |
635 | | * FwupdRequest:kind: |
636 | | * |
637 | | * The kind of the request. |
638 | | * |
639 | | * Since: 1.6.2 |
640 | | */ |
641 | 0 | pspec = g_param_spec_uint("kind", |
642 | 0 | NULL, |
643 | 0 | NULL, |
644 | 0 | FWUPD_REQUEST_KIND_UNKNOWN, |
645 | 0 | FWUPD_REQUEST_KIND_LAST, |
646 | 0 | FWUPD_REQUEST_KIND_UNKNOWN, |
647 | 0 | G_PARAM_READWRITE | G_PARAM_STATIC_NAME); |
648 | 0 | g_object_class_install_property(object_class, PROP_KIND, pspec); |
649 | | |
650 | | /** |
651 | | * FwupdRequest:flags: |
652 | | * |
653 | | * The flags for the request. |
654 | | * |
655 | | * Since: 1.8.6 |
656 | | */ |
657 | 0 | pspec = g_param_spec_uint64("flags", |
658 | 0 | NULL, |
659 | 0 | NULL, |
660 | 0 | FWUPD_REQUEST_FLAG_NONE, |
661 | 0 | FWUPD_REQUEST_FLAG_UNKNOWN, |
662 | 0 | FWUPD_REQUEST_FLAG_UNKNOWN, |
663 | 0 | G_PARAM_READWRITE | G_PARAM_STATIC_NAME); |
664 | 0 | g_object_class_install_property(object_class, PROP_FLAGS, pspec); |
665 | | |
666 | | /** |
667 | | * FwupdRequest:message: |
668 | | * |
669 | | * The message text in the request. |
670 | | * |
671 | | * Since: 1.6.2 |
672 | | */ |
673 | 0 | pspec = g_param_spec_string("message", |
674 | 0 | NULL, |
675 | 0 | NULL, |
676 | 0 | NULL, |
677 | 0 | G_PARAM_READWRITE | G_PARAM_STATIC_NAME); |
678 | 0 | g_object_class_install_property(object_class, PROP_MESSAGE, pspec); |
679 | | |
680 | | /** |
681 | | * FwupdRequest:image: |
682 | | * |
683 | | * The image link for the request. |
684 | | * |
685 | | * Since: 1.6.2 |
686 | | */ |
687 | 0 | pspec = |
688 | 0 | g_param_spec_string("image", NULL, NULL, NULL, G_PARAM_READWRITE | G_PARAM_STATIC_NAME); |
689 | 0 | g_object_class_install_property(object_class, PROP_IMAGE, pspec); |
690 | | |
691 | | /** |
692 | | * FwupdRequest:device-id: |
693 | | * |
694 | | * The device ID for the request. |
695 | | * |
696 | | * Since: 1.8.2 |
697 | | */ |
698 | 0 | pspec = g_param_spec_string("device-id", |
699 | 0 | NULL, |
700 | 0 | NULL, |
701 | 0 | NULL, |
702 | 0 | G_PARAM_READWRITE | G_PARAM_STATIC_NAME); |
703 | 0 | g_object_class_install_property(object_class, PROP_DEVICE_ID, pspec); |
704 | 0 | } |
705 | | |
706 | | static void |
707 | | fwupd_request_from_variant_iter(FwupdCodec *codec, GVariantIter *iter) |
708 | 0 | { |
709 | 0 | FwupdRequest *self = FWUPD_REQUEST(codec); |
710 | 0 | GVariant *value; |
711 | 0 | const gchar *key; |
712 | 0 | while (g_variant_iter_next(iter, "{&sv}", &key, &value)) { |
713 | 0 | fwupd_request_from_key_value(self, key, value); |
714 | 0 | g_variant_unref(value); |
715 | 0 | } |
716 | 0 | } |
717 | | |
718 | | static void |
719 | | fwupd_request_codec_iface_init(FwupdCodecInterface *iface) |
720 | 0 | { |
721 | 0 | iface->add_string = fwupd_request_add_string; |
722 | 0 | iface->add_variant = fwupd_request_add_variant; |
723 | 0 | iface->from_variant_iter = fwupd_request_from_variant_iter; |
724 | 0 | } |
725 | | |
726 | | /** |
727 | | * fwupd_request_new: |
728 | | * |
729 | | * Creates a new request. |
730 | | * |
731 | | * Returns: a new #FwupdRequest |
732 | | * |
733 | | * Since: 1.6.2 |
734 | | **/ |
735 | | FwupdRequest * |
736 | | fwupd_request_new(void) |
737 | 0 | { |
738 | 0 | FwupdRequest *self; |
739 | 0 | self = g_object_new(FWUPD_TYPE_REQUEST, NULL); |
740 | 0 | return FWUPD_REQUEST(self); |
741 | 0 | } |