/src/fwupd/plugins/amd-afc/fu-amd-afc-setting.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2026 Advanced Micro Devices, Inc. |
3 | | * |
4 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
5 | | */ |
6 | | |
7 | | #include "config.h" |
8 | | |
9 | | #include "fu-amd-afc-option.h" |
10 | | #include "fu-amd-afc-setting.h" |
11 | | |
12 | | void |
13 | | fu_amd_afc_setting_export(FuAmdAfcSetting *self, |
14 | | FuFirmwareExportFlags flags, |
15 | | FwupdJsonObject *json_object) |
16 | 0 | { |
17 | 0 | const gchar *kind_str = fu_amd_afc_setting_kind_to_string(self->kind); |
18 | 0 | if (kind_str != NULL) |
19 | 0 | fwupd_json_object_add_string(json_object, "kind", kind_str); |
20 | 0 | if (self->display_name != NULL) |
21 | 0 | fwupd_json_object_add_string(json_object, "display_name", self->display_name); |
22 | 0 | if (self->language != NULL) |
23 | 0 | fwupd_json_object_add_string(json_object, "language", self->language); |
24 | 0 | if (self->paths->len > 0) { |
25 | 0 | g_autoptr(FwupdJsonArray) json_paths = fwupd_json_array_new(); |
26 | 0 | for (guint i = 0; i < self->paths->len; i++) { |
27 | 0 | const gchar *path = g_ptr_array_index(self->paths, i); |
28 | 0 | if (path != NULL) |
29 | 0 | fwupd_json_array_add_string(json_paths, path); |
30 | 0 | } |
31 | 0 | fwupd_json_object_add_array(json_object, "paths", json_paths); |
32 | 0 | } |
33 | 0 | if (self->options->len > 0) { |
34 | 0 | g_autoptr(FwupdJsonArray) json_options = fwupd_json_array_new(); |
35 | 0 | for (guint i = 0; i < self->options->len; i++) { |
36 | 0 | FuAmdAfcOption *option = g_ptr_array_index(self->options, i); |
37 | 0 | g_autoptr(FwupdJsonObject) json_option = fwupd_json_object_new(); |
38 | 0 | fu_amd_afc_option_export(option, flags, json_option); |
39 | 0 | fwupd_json_array_add_object(json_options, json_option); |
40 | 0 | } |
41 | 0 | fwupd_json_object_add_array(json_object, "options", json_options); |
42 | 0 | } |
43 | 0 | if (self->question_id != 0) |
44 | 0 | fwupd_json_object_add_integer(json_object, "question_id", self->question_id); |
45 | 0 | if (self->question_flags != 0) |
46 | 0 | fwupd_json_object_add_integer(json_object, "question_flags", self->question_flags); |
47 | 0 | fwupd_json_object_add_boolean(json_object, "has_current", self->has_current); |
48 | 0 | if (self->current != 0) |
49 | 0 | fwupd_json_object_add_integer(json_object, "current", (gint64)self->current); |
50 | 0 | if (self->minimum != 0) |
51 | 0 | fwupd_json_object_add_integer(json_object, "minimum", (gint64)self->minimum); |
52 | 0 | if (self->maximum != 0) |
53 | 0 | fwupd_json_object_add_integer(json_object, "maximum", (gint64)self->maximum); |
54 | 0 | if (self->step != 0) |
55 | 0 | fwupd_json_object_add_integer(json_object, "step", (gint64)self->step); |
56 | 0 | fwupd_json_object_add_boolean(json_object, "has_default", self->has_default); |
57 | 0 | if (self->default_value != 0) |
58 | 0 | fwupd_json_object_add_integer(json_object, |
59 | 0 | "default_value", |
60 | 0 | (gint64)self->default_value); |
61 | 0 | } |
62 | | |
63 | | void |
64 | | fu_amd_afc_setting_free(FuAmdAfcSetting *self) |
65 | 24.8k | { |
66 | 24.8k | if (self->paths != NULL) |
67 | 24.8k | g_ptr_array_unref(self->paths); |
68 | 24.8k | if (self->options != NULL) |
69 | 24.8k | g_ptr_array_unref(self->options); |
70 | 24.8k | g_free(self->display_name); |
71 | 24.8k | g_free(self->language); |
72 | 24.8k | g_free(self); |
73 | 24.8k | } |
74 | | |
75 | | const gchar * |
76 | | fu_amd_afc_setting_get_option_name(FuAmdAfcSetting *self, guint64 value) |
77 | 0 | { |
78 | 0 | for (guint i = 0; i < self->options->len; i++) { |
79 | 0 | FuAmdAfcOption *option = g_ptr_array_index(self->options, i); |
80 | 0 | if (option->value == value) |
81 | 0 | return option->name; |
82 | 0 | } |
83 | 0 | return NULL; |
84 | 0 | } |
85 | | |
86 | | gchar * |
87 | | fu_amd_afc_setting_build_name(FuAmdAfcSetting *self) |
88 | 0 | { |
89 | 0 | g_autoptr(GString) name = g_string_new(NULL); |
90 | 0 | g_autofree gchar *component = NULL; |
91 | 0 | for (guint i = 0; i < self->paths->len; i++) { |
92 | 0 | const gchar *path = g_ptr_array_index(self->paths, i); |
93 | 0 | g_set_str(&component, path); |
94 | 0 | g_strstrip(component); |
95 | 0 | if (component[0] == '\0') |
96 | 0 | continue; |
97 | 0 | if (name->len > 0) |
98 | 0 | g_string_append_c(name, '|'); |
99 | 0 | for (const gchar *p = component; *p != '\0'; p++) |
100 | 0 | g_string_append_c(name, *p == '/' ? '!' : *p); |
101 | 0 | } |
102 | 0 | return g_string_free_and_steal(g_steal_pointer(&name)); |
103 | 0 | } |