Coverage Report

Created: 2026-06-10 07:04

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