-
Notifications
You must be signed in to change notification settings - Fork 416
/
fwupd-device.c
4140 lines (3892 loc) · 112 KB
/
fwupd-device.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2015 Richard Hughes <richard@hughsie.com>
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#include "config.h"
#include <gio/gio.h>
#include <string.h>
#include "fwupd-common-private.h"
#include "fwupd-device-private.h"
#include "fwupd-enums-private.h"
#include "fwupd-error.h"
#include "fwupd-release-private.h"
/**
* FwupdDevice:
*
* A physical device on the host with optionally updatable firmware.
*
* See also: [class@FwupdRelease]
*/
static void
fwupd_device_finalize(GObject *object);
typedef struct {
gchar *id;
gchar *parent_id;
gchar *composite_id;
guint64 created;
guint64 modified;
guint64 flags;
guint64 problems;
GPtrArray *guids;
GPtrArray *vendor_ids;
GPtrArray *protocols;
GPtrArray *instance_ids;
GPtrArray *icons;
GPtrArray *issues; /* of utf-8 */
gchar *name;
gchar *serial;
gchar *summary;
gchar *branch;
gchar *description;
gchar *vendor;
gchar *vendor_id; /* for compat only */
gchar *homepage;
gchar *plugin;
gchar *protocol;
gchar *version;
gchar *version_lowest;
gchar *version_bootloader;
FwupdVersionFormat version_format;
guint64 version_raw;
guint64 version_build_date;
guint64 version_lowest_raw;
guint64 version_bootloader_raw;
GPtrArray *checksums;
GPtrArray *children;
guint32 flashes_left;
guint32 battery_level;
guint32 battery_threshold;
guint32 install_duration;
FwupdUpdateState update_state;
gchar *update_error;
gchar *update_message;
gchar *update_image;
FwupdStatus status;
guint percentage;
GPtrArray *releases;
FwupdDevice *parent; /* noref */
} FwupdDevicePrivate;
enum {
PROP_0,
PROP_VERSION_FORMAT,
PROP_FLAGS,
PROP_PROTOCOL,
PROP_STATUS,
PROP_PERCENTAGE,
PROP_PARENT,
PROP_UPDATE_STATE,
PROP_UPDATE_MESSAGE,
PROP_UPDATE_ERROR,
PROP_UPDATE_IMAGE,
PROP_BATTERY_LEVEL,
PROP_BATTERY_THRESHOLD,
PROP_PROBLEMS,
PROP_LAST
};
G_DEFINE_TYPE_WITH_PRIVATE(FwupdDevice, fwupd_device, G_TYPE_OBJECT)
#define GET_PRIVATE(o) (fwupd_device_get_instance_private(o))
#define FWUPD_BATTERY_THRESHOLD_DEFAULT 10 /* % */
/**
* fwupd_device_get_checksums:
* @self: a #FwupdDevice
*
* Gets the device checksums.
*
* Returns: (element-type utf8) (transfer none): the checksums, which may be empty
*
* Since: 0.9.3
**/
GPtrArray *
fwupd_device_get_checksums(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
return priv->checksums;
}
/**
* fwupd_device_has_checksum:
* @self: a #FwupdDevice
* @checksum: (not nullable): the device checksum
*
* Finds out if the device has this specific checksum.
*
* Returns: %TRUE if the checksum name is found
*
* Since: 1.8.7
**/
gboolean
fwupd_device_has_checksum(FwupdDevice *self, const gchar *checksum)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), FALSE);
g_return_val_if_fail(checksum != NULL, FALSE);
for (guint i = 0; i < priv->checksums->len; i++) {
const gchar *checksum_tmp = g_ptr_array_index(priv->checksums, i);
if (g_strcmp0(checksum, checksum_tmp) == 0)
return TRUE;
}
return FALSE;
}
/**
* fwupd_device_add_checksum:
* @self: a #FwupdDevice
* @checksum: (not nullable): the device checksum
*
* Adds a device checksum.
*
* Since: 0.9.3
**/
void
fwupd_device_add_checksum(FwupdDevice *self, const gchar *checksum)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_if_fail(FWUPD_IS_DEVICE(self));
g_return_if_fail(checksum != NULL);
if (fwupd_device_has_checksum(self, checksum))
return;
g_ptr_array_add(priv->checksums, g_strdup(checksum));
}
/**
* fwupd_device_get_issues:
* @self: a #FwupdDevice
*
* Gets the list of issues currently affecting this device.
*
* Returns: (element-type utf8) (transfer none): the issues, which may be empty
*
* Since: 1.7.6
**/
GPtrArray *
fwupd_device_get_issues(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
return priv->issues;
}
/**
* fwupd_device_add_issue:
* @self: a #FwupdDevice
* @issue: (not nullable): the update issue, e.g. `CVE-2019-12345`
*
* Adds an current issue to this device.
*
* Since: 1.7.6
**/
void
fwupd_device_add_issue(FwupdDevice *self, const gchar *issue)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_if_fail(FWUPD_IS_DEVICE(self));
g_return_if_fail(issue != NULL);
for (guint i = 0; i < priv->issues->len; i++) {
const gchar *issue_tmp = g_ptr_array_index(priv->issues, i);
if (g_strcmp0(issue_tmp, issue) == 0)
return;
}
g_ptr_array_add(priv->issues, g_strdup(issue));
}
/**
* fwupd_device_get_children:
* @self: a #FwupdDevice
*
* Gets the device children. These can only be assigned using fwupd_device_set_parent().
*
* Returns: (element-type FwupdDevice) (transfer none): the children, which may be empty
*
* Since: 1.3.7
**/
GPtrArray *
fwupd_device_get_children(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
return priv->children;
}
/**
* fwupd_device_get_summary:
* @self: a #FwupdDevice
*
* Gets the device summary.
*
* Returns: the device summary, or %NULL if unset
*
* Since: 0.9.3
**/
const gchar *
fwupd_device_get_summary(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
return priv->summary;
}
/**
* fwupd_device_set_summary:
* @self: a #FwupdDevice
* @summary: (nullable): the device one line summary
*
* Sets the device summary.
*
* Since: 0.9.3
**/
void
fwupd_device_set_summary(FwupdDevice *self, const gchar *summary)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_if_fail(FWUPD_IS_DEVICE(self));
/* not changed */
if (g_strcmp0(priv->summary, summary) == 0)
return;
g_free(priv->summary);
priv->summary = g_strdup(summary);
}
/**
* fwupd_device_get_branch:
* @self: a #FwupdDevice
*
* Gets the current device branch.
*
* Returns: the device branch, or %NULL if unset
*
* Since: 1.5.0
**/
const gchar *
fwupd_device_get_branch(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
return priv->branch;
}
/**
* fwupd_device_set_branch:
* @self: a #FwupdDevice
* @branch: (nullable): the device one line branch
*
* Sets the current device branch.
*
* Since: 1.5.0
**/
void
fwupd_device_set_branch(FwupdDevice *self, const gchar *branch)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_if_fail(FWUPD_IS_DEVICE(self));
/* not changed */
if (g_strcmp0(priv->branch, branch) == 0)
return;
g_free(priv->branch);
priv->branch = g_strdup(branch);
}
/**
* fwupd_device_get_serial:
* @self: a #FwupdDevice
*
* Gets the serial number for the device.
*
* Returns: a string value, or %NULL if never set.
*
* Since: 1.1.2
**/
const gchar *
fwupd_device_get_serial(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
return priv->serial;
}
/**
* fwupd_device_set_serial:
* @self: a #FwupdDevice
* @serial: (nullable): the device serial number
*
* Sets the serial number for the device.
*
* Since: 1.1.2
**/
void
fwupd_device_set_serial(FwupdDevice *self, const gchar *serial)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_if_fail(FWUPD_IS_DEVICE(self));
/* not changed */
if (g_strcmp0(priv->serial, serial) == 0)
return;
g_free(priv->serial);
priv->serial = g_strdup(serial);
}
/**
* fwupd_device_get_id:
* @self: a #FwupdDevice
*
* Gets the ID.
*
* Returns: the ID, or %NULL if unset
*
* Since: 0.9.3
**/
const gchar *
fwupd_device_get_id(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
return priv->id;
}
/**
* fwupd_device_set_id:
* @self: a #FwupdDevice
* @id: (nullable): the device ID, e.g. `USB:foo`
*
* Sets the ID.
*
* Since: 0.9.3
**/
void
fwupd_device_set_id(FwupdDevice *self, const gchar *id)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_if_fail(FWUPD_IS_DEVICE(self));
/* not changed */
if (g_strcmp0(priv->id, id) == 0)
return;
g_free(priv->id);
priv->id = g_strdup(id);
}
/**
* fwupd_device_get_parent_id:
* @self: a #FwupdDevice
*
* Gets the parent ID.
*
* Returns: the parent ID, or %NULL if unset
*
* Since: 1.0.8
**/
const gchar *
fwupd_device_get_parent_id(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
return priv->parent_id;
}
/**
* fwupd_device_set_parent_id:
* @self: a #FwupdDevice
* @parent_id: (nullable): the device ID, e.g. `USB:foo`
*
* Sets the parent ID.
*
* Since: 1.0.8
**/
void
fwupd_device_set_parent_id(FwupdDevice *self, const gchar *parent_id)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_if_fail(FWUPD_IS_DEVICE(self));
/* not changed */
if (g_strcmp0(priv->parent_id, parent_id) == 0)
return;
g_free(priv->parent_id);
priv->parent_id = g_strdup(parent_id);
}
/**
* fwupd_device_get_composite_id:
* @self: a #FwupdDevice
*
* Gets the composite ID, falling back to the device ID if unset.
*
* The composite ID will be the same value for all parent, child and sibling
* devices.
*
* Returns: (nullable): the composite ID
*
* Since: 1.6.0
**/
const gchar *
fwupd_device_get_composite_id(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
if (priv->composite_id != NULL)
return priv->composite_id;
return priv->id;
}
/**
* fwupd_device_set_composite_id:
* @self: a #FwupdDevice
* @composite_id: (nullable): a device ID
*
* Sets the composite ID, which is usually a SHA1 hash of a grandparent or
* parent device.
*
* Since: 1.6.0
**/
void
fwupd_device_set_composite_id(FwupdDevice *self, const gchar *composite_id)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_if_fail(FWUPD_IS_DEVICE(self));
/* not changed */
if (g_strcmp0(priv->composite_id, composite_id) == 0)
return;
g_free(priv->composite_id);
priv->composite_id = g_strdup(composite_id);
}
/**
* fwupd_device_get_parent:
* @self: a #FwupdDevice
*
* Gets the parent.
*
* Returns: (transfer none): the parent device, or %NULL if unset
*
* Since: 1.0.8
**/
FwupdDevice *
fwupd_device_get_parent(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
return priv->parent;
}
/**
* fwupd_device_get_root:
* @self: a #FwupdDevice
*
* Gets the device root.
*
* Returns: (transfer none): the root device, or %NULL if unset
*
* Since: 1.7.4
**/
FwupdDevice *
fwupd_device_get_root(FwupdDevice *self)
{
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
while (1) {
FwupdDevicePrivate *priv = GET_PRIVATE(self);
if (priv->parent == NULL)
break;
self = priv->parent;
}
return self;
}
/**
* fwupd_device_set_parent:
* @self: a #FwupdDevice
* @parent: (nullable): another #FwupdDevice
*
* Sets the parent. Only used internally.
*
* Since: 1.0.8
**/
void
fwupd_device_set_parent(FwupdDevice *self, FwupdDevice *parent)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_if_fail(FWUPD_IS_DEVICE(self));
g_return_if_fail(self != parent);
if (priv->parent != NULL)
g_object_remove_weak_pointer(G_OBJECT(priv->parent), (gpointer *)&priv->parent);
if (parent != NULL)
g_object_add_weak_pointer(G_OBJECT(parent), (gpointer *)&priv->parent);
priv->parent = parent;
/* this is what goes over D-Bus */
fwupd_device_set_parent_id(self, parent != NULL ? fwupd_device_get_id(parent) : NULL);
}
static void
fwupd_device_child_finalized_cb(gpointer data, GObject *where_the_object_was)
{
FwupdDevice *self = FWUPD_DEVICE(data);
g_critical("FuDevice child %p was finalized while still having parent %s [%s]!",
where_the_object_was,
fwupd_device_get_name(self),
fwupd_device_get_id(self));
}
/**
* fwupd_device_add_child:
* @self: a #FwupdDevice
* @child: (not nullable): Another #FwupdDevice
*
* Adds a child device. An child device is logically linked to the primary
* device in some way.
*
* NOTE: You should never call this function from user code, it is for daemon
* use only. Only use fwupd_device_set_parent() to set up a logical tree.
*
* Since: 1.5.1
**/
void
fwupd_device_add_child(FwupdDevice *self, FwupdDevice *child)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_if_fail(FWUPD_IS_DEVICE(self));
g_return_if_fail(FWUPD_IS_DEVICE(child));
g_return_if_fail(self != child);
/* add if the child does not already exist */
for (guint i = 0; i < priv->children->len; i++) {
FwupdDevice *devtmp = g_ptr_array_index(priv->children, i);
if (devtmp == child)
return;
}
g_object_weak_ref(G_OBJECT(child), fwupd_device_child_finalized_cb, self);
g_ptr_array_add(priv->children, g_object_ref(child));
}
/**
* fwupd_device_remove_child:
* @self: a #FwupdDevice
* @child: Another #FwupdDevice
*
* Removes a child device.
*
* NOTE: You should never call this function from user code, it is for daemon
* use only.
*
* Since: 1.6.2
**/
void
fwupd_device_remove_child(FwupdDevice *self, FwupdDevice *child)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
/* remove if the child exists */
for (guint i = 0; i < priv->children->len; i++) {
FwupdDevice *child_tmp = g_ptr_array_index(priv->children, i);
if (child_tmp == child) {
g_object_weak_unref(G_OBJECT(child), fwupd_device_child_finalized_cb, self);
g_ptr_array_remove_index(priv->children, i);
return;
}
}
}
/**
* fwupd_device_get_guids:
* @self: a #FwupdDevice
*
* Gets the GUIDs.
*
* Returns: (element-type utf8) (transfer none): the GUIDs
*
* Since: 0.9.3
**/
GPtrArray *
fwupd_device_get_guids(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
return priv->guids;
}
/**
* fwupd_device_has_guid:
* @self: a #FwupdDevice
* @guid: (not nullable): the GUID, e.g. `2082b5e0-7a64-478a-b1b2-e3404fab6dad`
*
* Finds out if the device has this specific GUID.
*
* Returns: %TRUE if the GUID is found
*
* Since: 0.9.3
**/
gboolean
fwupd_device_has_guid(FwupdDevice *self, const gchar *guid)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), FALSE);
g_return_val_if_fail(guid != NULL, FALSE);
for (guint i = 0; i < priv->guids->len; i++) {
const gchar *guid_tmp = g_ptr_array_index(priv->guids, i);
if (g_strcmp0(guid, guid_tmp) == 0)
return TRUE;
}
return FALSE;
}
/**
* fwupd_device_add_guid:
* @self: a #FwupdDevice
* @guid: the GUID, e.g. `2082b5e0-7a64-478a-b1b2-e3404fab6dad`
*
* Adds the GUID if it does not already exist.
*
* Since: 0.9.3
**/
void
fwupd_device_add_guid(FwupdDevice *self, const gchar *guid)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_if_fail(FWUPD_IS_DEVICE(self));
g_return_if_fail(guid != NULL);
if (fwupd_device_has_guid(self, guid))
return;
g_ptr_array_add(priv->guids, g_strdup(guid));
}
/**
* fwupd_device_get_guid_default:
* @self: a #FwupdDevice
*
* Gets the default GUID.
*
* Returns: the GUID, or %NULL if unset
*
* Since: 0.9.3
**/
const gchar *
fwupd_device_get_guid_default(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
if (priv->guids->len == 0)
return NULL;
return g_ptr_array_index(priv->guids, 0);
}
/**
* fwupd_device_get_instance_ids:
* @self: a #FwupdDevice
*
* Gets the instance IDs.
*
* Returns: (element-type utf8) (transfer none): the instance IDs
*
* Since: 1.2.5
**/
GPtrArray *
fwupd_device_get_instance_ids(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
return priv->instance_ids;
}
/**
* fwupd_device_has_instance_id:
* @self: a #FwupdDevice
* @instance_id: (not nullable): the instance ID, e.g. `PCI\VEN_10EC&DEV_525A`
*
* Finds out if the device has this specific instance ID.
*
* Returns: %TRUE if the instance ID is found
*
* Since: 1.2.5
**/
gboolean
fwupd_device_has_instance_id(FwupdDevice *self, const gchar *instance_id)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), FALSE);
g_return_val_if_fail(instance_id != NULL, FALSE);
for (guint i = 0; i < priv->instance_ids->len; i++) {
const gchar *instance_id_tmp = g_ptr_array_index(priv->instance_ids, i);
if (g_strcmp0(instance_id, instance_id_tmp) == 0)
return TRUE;
}
return FALSE;
}
/**
* fwupd_device_add_instance_id:
* @self: a #FwupdDevice
* @instance_id: (not nullable): the instance ID, e.g. `PCI\VEN_10EC&DEV_525A`
*
* Adds the instance ID if it does not already exist.
*
* Since: 1.2.5
**/
void
fwupd_device_add_instance_id(FwupdDevice *self, const gchar *instance_id)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_if_fail(FWUPD_IS_DEVICE(self));
g_return_if_fail(instance_id != NULL);
if (fwupd_device_has_instance_id(self, instance_id))
return;
g_ptr_array_add(priv->instance_ids, g_strdup(instance_id));
}
/**
* fwupd_device_get_icons:
* @self: a #FwupdDevice
*
* Gets the icon names to use for the device.
*
* NOTE: Icons specified without a full path are stock icons and should
* be loaded from the users icon theme.
*
* Returns: (element-type utf8) (transfer none): an array of icon names
*
* Since: 0.9.8
**/
GPtrArray *
fwupd_device_get_icons(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
return priv->icons;
}
/**
* fwupd_device_has_icon:
* @self: a #FwupdDevice
* @icon: the icon name, e.g. `input-mouse` or `/usr/share/icons/foo.png`
*
* Finds out if the device has this specific icon.
*
* Returns: %TRUE if the icon name is found
*
* Since: 1.6.2
**/
gboolean
fwupd_device_has_icon(FwupdDevice *self, const gchar *icon)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
for (guint i = 0; i < priv->icons->len; i++) {
const gchar *icon_tmp = g_ptr_array_index(priv->icons, i);
if (g_strcmp0(icon, icon_tmp) == 0)
return TRUE;
}
return FALSE;
}
/**
* fwupd_device_add_icon:
* @self: a #FwupdDevice
* @icon: (not nullable): the icon name, e.g. `input-mouse` or `/usr/share/icons/foo.png`
*
* Adds the icon name if it does not already exist.
*
* Since: 0.9.8
**/
void
fwupd_device_add_icon(FwupdDevice *self, const gchar *icon)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_if_fail(FWUPD_IS_DEVICE(self));
g_return_if_fail(icon != NULL);
if (fwupd_device_has_icon(self, icon))
return;
g_ptr_array_add(priv->icons, g_strdup(icon));
}
/**
* fwupd_device_get_name:
* @self: a #FwupdDevice
*
* Gets the device name.
*
* Returns: the device name, or %NULL if unset
*
* Since: 0.9.3
**/
const gchar *
fwupd_device_get_name(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
return priv->name;
}
/**
* fwupd_device_set_name:
* @self: a #FwupdDevice
* @name: (nullable): the device name, e.g. `ColorHug2`
*
* Sets the device name.
*
* Since: 0.9.3
**/
void
fwupd_device_set_name(FwupdDevice *self, const gchar *name)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_if_fail(FWUPD_IS_DEVICE(self));
/* not changed */
if (g_strcmp0(priv->name, name) == 0)
return;
g_free(priv->name);
priv->name = g_strdup(name);
}
/**
* fwupd_device_get_vendor:
* @self: a #FwupdDevice
*
* Gets the device vendor.
*
* Returns: the device vendor, or %NULL if unset
*
* Since: 0.9.3
**/
const gchar *
fwupd_device_get_vendor(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
return priv->vendor;
}
/**
* fwupd_device_set_vendor:
* @self: a #FwupdDevice
* @vendor: (nullable): the vendor
*
* Sets the device vendor.
*
* Since: 0.9.3
**/
void
fwupd_device_set_vendor(FwupdDevice *self, const gchar *vendor)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_if_fail(FWUPD_IS_DEVICE(self));
/* not changed */
if (g_strcmp0(priv->vendor, vendor) == 0)
return;
g_free(priv->vendor);
priv->vendor = g_strdup(vendor);
}
/**
* fwupd_device_get_vendor_id:
* @self: a #FwupdDevice
*
* Gets the combined device vendor ID.
*
* Returns: the device vendor, e.g. 'USB:0x1234|PCI:0x5678', or %NULL if unset
*
* Since: 0.9.4
*
* Deprecated: 1.5.5: Use fwupd_device_get_vendor_ids() instead.
**/
const gchar *
fwupd_device_get_vendor_id(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
return priv->vendor_id;
}
/**
* fwupd_device_set_vendor_id:
* @self: a #FwupdDevice
* @vendor_id: (not nullable): the vendor ID, e.g. 'USB:0x1234' or 'USB:0x1234|PCI:0x5678'
*
* Sets the device vendor ID.
*
* Since: 0.9.4
*
* Deprecated: 1.5.5: Use fwupd_device_add_vendor_id() instead.
**/
void
fwupd_device_set_vendor_id(FwupdDevice *self, const gchar *vendor_id)
{
g_auto(GStrv) vendor_ids = NULL;
g_return_if_fail(FWUPD_IS_DEVICE(self));
g_return_if_fail(vendor_id != NULL);
/* add all */
vendor_ids = g_strsplit(vendor_id, "|", -1);
for (guint i = 0; vendor_ids[i] != NULL; i++)
fwupd_device_add_vendor_id(self, vendor_ids[i]);
}
/**
* fwupd_device_get_vendor_ids:
* @self: a #FwupdDevice
*
* Gets the device vendor ID.
*
* Returns: (element-type utf8) (transfer none): the device vendor ID
*
* Since: 1.5.5
**/
GPtrArray *
fwupd_device_get_vendor_ids(FwupdDevice *self)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), NULL);
return priv->vendor_ids;
}
/**
* fwupd_device_has_vendor_id:
* @self: a #FwupdDevice
* @vendor_id: (not nullable): the vendor ID, e.g. 'USB:0x1234'
*
* Finds out if the device has this specific vendor ID.
*
* Returns: %TRUE if the vendor ID is found
*
* Since: 1.5.5
**/
gboolean
fwupd_device_has_vendor_id(FwupdDevice *self, const gchar *vendor_id)
{
FwupdDevicePrivate *priv = GET_PRIVATE(self);
g_return_val_if_fail(FWUPD_IS_DEVICE(self), FALSE);
g_return_val_if_fail(vendor_id != NULL, FALSE);
for (guint i = 0; i < priv->vendor_ids->len; i++) {
const gchar *vendor_id_tmp = g_ptr_array_index(priv->vendor_ids, i);
if (g_strcmp0(vendor_id, vendor_id_tmp) == 0)
return TRUE;
}
return FALSE;
}
/**
* fwupd_device_add_vendor_id: