trivial: Remove FwupdResult from libfwupd
Richard Hughes
6 years ago
30 | 30 | <xi:include href="xml/fwupd-enums.xml"/> |
31 | 31 | <xi:include href="xml/fwupd-release.xml"/> |
32 | 32 | <xi:include href="xml/fwupd-remote.xml"/> |
33 | <xi:include href="xml/fwupd-result.xml"/> | |
34 | 33 | <xi:include href="xml/fwupd-version.xml"/> |
35 | 34 | </reference> |
36 | 35 |
3 | 3 | When we next bump soname the following changes are planned: |
4 | 4 | |
5 | 5 | * {sa{sv}} -> {a{sv}} -- we don't always want to send the device ID |
6 | * Make DeviceAdded emit a FwupdDevice, not a FwupdResult | |
7 | 6 | * Unexport fwupd_result_to_data() and fwupd_result_new_from_data() |
8 | 7 | |
9 | 8 | Migration from Version 0.9.x |
21 | 20 | * Switch FWUPD_RESULT_KEY_DEVICE_CHECKSUM_KIND to fwupd_checksum_guess_kind() |
22 | 21 | * Rename fwupd_result_update_*() to fwupd_release_*() |
23 | 22 | * Rename fwupd_result_*() to fwupd_device_*() |
23 | * Convert FwupdResult to FwupdDevice in all callbacks |
37 | 37 | #include "fwupd-device-private.h" |
38 | 38 | #include "fwupd-release-private.h" |
39 | 39 | #include "fwupd-remote-private.h" |
40 | #include "fwupd-result.h" | |
41 | 40 | |
42 | 41 | static void fwupd_client_finalize (GObject *object); |
43 | 42 | |
157 | 156 | GVariant *parameters, |
158 | 157 | FwupdClient *client) |
159 | 158 | { |
160 | g_autoptr(FwupdResult) res = NULL; | |
159 | g_autoptr(FwupdDevice) dev = NULL; | |
161 | 160 | if (g_strcmp0 (signal_name, "Changed") == 0) { |
162 | 161 | g_debug ("Emitting ::changed()"); |
163 | 162 | g_signal_emit (client, signals[SIGNAL_CHANGED], 0); |
164 | 163 | return; |
165 | 164 | } |
166 | 165 | if (g_strcmp0 (signal_name, "DeviceAdded") == 0) { |
167 | res = fwupd_result_new_from_data (parameters); | |
166 | dev = fwupd_device_new_from_data (parameters); | |
168 | 167 | g_debug ("Emitting ::device-added(%s)", |
169 | fwupd_device_get_id (fwupd_result_get_device (res))); | |
170 | g_signal_emit (client, signals[SIGNAL_DEVICE_ADDED], 0, res); | |
168 | fwupd_device_get_id (dev)); | |
169 | g_signal_emit (client, signals[SIGNAL_DEVICE_ADDED], 0, dev); | |
171 | 170 | return; |
172 | 171 | } |
173 | 172 | if (g_strcmp0 (signal_name, "DeviceRemoved") == 0) { |
174 | res = fwupd_result_new_from_data (parameters); | |
175 | g_signal_emit (client, signals[SIGNAL_DEVICE_REMOVED], 0, res); | |
173 | dev = fwupd_device_new_from_data (parameters); | |
174 | g_signal_emit (client, signals[SIGNAL_DEVICE_REMOVED], 0, dev); | |
176 | 175 | g_debug ("Emitting ::device-removed(%s)", |
177 | fwupd_device_get_id (fwupd_result_get_device (res))); | |
176 | fwupd_device_get_id (dev)); | |
178 | 177 | return; |
179 | 178 | } |
180 | 179 | if (g_strcmp0 (signal_name, "DeviceChanged") == 0) { |
181 | res = fwupd_result_new_from_data (parameters); | |
182 | g_signal_emit (client, signals[SIGNAL_DEVICE_CHANGED], 0, res); | |
180 | dev = fwupd_device_new_from_data (parameters); | |
181 | g_signal_emit (client, signals[SIGNAL_DEVICE_CHANGED], 0, dev); | |
183 | 182 | g_debug ("Emitting ::device-changed(%s)", |
184 | fwupd_device_get_id (fwupd_result_get_device (res))); | |
183 | fwupd_device_get_id (dev)); | |
185 | 184 | return; |
186 | 185 | } |
187 | 186 | g_debug ("Unknown signal name '%s' from %s", signal_name, sender_name); |
239 | 238 | if (val != NULL) |
240 | 239 | fwupd_client_set_daemon_version (client, g_variant_get_string (val, NULL)); |
241 | 240 | return TRUE; |
242 | } | |
243 | ||
244 | static GPtrArray * | |
245 | fwupd_client_parse_results_from_data (GVariant *devices) | |
246 | { | |
247 | FwupdResult *res; | |
248 | GPtrArray *results = NULL; | |
249 | gsize sz; | |
250 | guint i; | |
251 | g_autoptr(GVariant) untuple = NULL; | |
252 | ||
253 | results = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); | |
254 | untuple = g_variant_get_child_value (devices, 0); | |
255 | sz = g_variant_n_children (untuple); | |
256 | for (i = 0; i < sz; i++) { | |
257 | g_autoptr(GVariant) data = NULL; | |
258 | data = g_variant_get_child_value (untuple, i); | |
259 | res = fwupd_result_new_from_data (data); | |
260 | g_ptr_array_add (results, res); | |
261 | } | |
262 | ||
263 | return results; | |
264 | 241 | } |
265 | 242 | |
266 | 243 | static GPtrArray * |
449 | 426 | * |
450 | 427 | * Gets all the devices with known updates. |
451 | 428 | * |
452 | * Returns: (element-type FwupdResult) (transfer container): results | |
429 | * Returns: (element-type FwupdDevice) (transfer container): results | |
453 | 430 | * |
454 | 431 | * Since: 0.7.0 |
455 | 432 | **/ |
480 | 457 | fwupd_client_fixup_dbus_error (*error); |
481 | 458 | return NULL; |
482 | 459 | } |
483 | return fwupd_client_parse_results_from_data (val); | |
460 | return fwupd_client_parse_devices_from_variant (val); | |
484 | 461 | } |
485 | 462 | |
486 | 463 | /** |
832 | 809 | * |
833 | 810 | * Gets the results of a previous firmware update for a specific device. |
834 | 811 | * |
835 | * Returns: (transfer full): a #FwupdResult, or %NULL for failure | |
812 | * Returns: (transfer full): a #FwupdDevice, or %NULL for failure | |
836 | 813 | * |
837 | 814 | * Since: 0.7.0 |
838 | 815 | **/ |
839 | FwupdResult * | |
816 | FwupdDevice * | |
840 | 817 | fwupd_client_get_results (FwupdClient *client, const gchar *device_id, |
841 | 818 | GCancellable *cancellable, GError **error) |
842 | 819 | { |
868 | 845 | helper->error = NULL; |
869 | 846 | return NULL; |
870 | 847 | } |
871 | return fwupd_result_new_from_data (helper->val); | |
848 | return fwupd_device_new_from_data (helper->val); | |
872 | 849 | } |
873 | 850 | |
874 | 851 | static void |
1009 | 986 | * |
1010 | 987 | * Gets details about a specific firmware file. |
1011 | 988 | * |
1012 | * Returns: (transfer container) (element-type FwupdResult): an array of results | |
989 | * Returns: (transfer container) (element-type FwupdDevice): an array of results | |
1013 | 990 | * |
1014 | 991 | * Since: 1.0.0 |
1015 | 992 | **/ |
1079 | 1056 | } |
1080 | 1057 | |
1081 | 1058 | /* return results */ |
1082 | return fwupd_client_parse_results_from_data (helper->val); | |
1059 | return fwupd_client_parse_devices_from_variant (helper->val); | |
1083 | 1060 | } |
1084 | 1061 | |
1085 | 1062 | /** |
1480 | 1457 | /** |
1481 | 1458 | * FwupdClient::device-added: |
1482 | 1459 | * @client: the #FwupdClient instance that emitted the signal |
1483 | * @result: the #FwupdResult | |
1460 | * @result: the #FwupdDevice | |
1484 | 1461 | * |
1485 | 1462 | * The ::device-added signal is emitted when a device has been |
1486 | 1463 | * added. |
1492 | 1469 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
1493 | 1470 | G_STRUCT_OFFSET (FwupdClientClass, device_added), |
1494 | 1471 | NULL, NULL, g_cclosure_marshal_generic, |
1495 | G_TYPE_NONE, 1, FWUPD_TYPE_RESULT); | |
1472 | G_TYPE_NONE, 1, FWUPD_TYPE_DEVICE); | |
1496 | 1473 | |
1497 | 1474 | /** |
1498 | 1475 | * FwupdClient::device-removed: |
1499 | 1476 | * @client: the #FwupdClient instance that emitted the signal |
1500 | * @result: the #FwupdResult | |
1477 | * @result: the #FwupdDevice | |
1501 | 1478 | * |
1502 | 1479 | * The ::device-removed signal is emitted when a device has been |
1503 | 1480 | * removed. |
1509 | 1486 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
1510 | 1487 | G_STRUCT_OFFSET (FwupdClientClass, device_removed), |
1511 | 1488 | NULL, NULL, g_cclosure_marshal_generic, |
1512 | G_TYPE_NONE, 1, FWUPD_TYPE_RESULT); | |
1489 | G_TYPE_NONE, 1, FWUPD_TYPE_DEVICE); | |
1513 | 1490 | |
1514 | 1491 | /** |
1515 | 1492 | * FwupdClient::device-changed: |
1516 | 1493 | * @client: the #FwupdClient instance that emitted the signal |
1517 | * @result: the #FwupdResult | |
1494 | * @result: the #FwupdDevice | |
1518 | 1495 | * |
1519 | 1496 | * The ::device-changed signal is emitted when a device has been |
1520 | 1497 | * changed in some way, e.g. the version number is updated. |
1526 | 1503 | G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, |
1527 | 1504 | G_STRUCT_OFFSET (FwupdClientClass, device_changed), |
1528 | 1505 | NULL, NULL, g_cclosure_marshal_generic, |
1529 | G_TYPE_NONE, 1, FWUPD_TYPE_RESULT); | |
1506 | G_TYPE_NONE, 1, FWUPD_TYPE_DEVICE); | |
1530 | 1507 | |
1531 | 1508 | /** |
1532 | 1509 | * FwupdClient:status: |
25 | 25 | #include <gio/gio.h> |
26 | 26 | |
27 | 27 | #include "fwupd-enums.h" |
28 | #include "fwupd-device.h" | |
28 | 29 | #include "fwupd-remote.h" |
29 | #include "fwupd-result.h" | |
30 | 30 | |
31 | 31 | G_BEGIN_DECLS |
32 | 32 | |
40 | 40 | void (*status_changed) (FwupdClient *client, |
41 | 41 | FwupdStatus status); |
42 | 42 | void (*device_added) (FwupdClient *client, |
43 | FwupdResult *result); | |
43 | FwupdDevice *result); | |
44 | 44 | void (*device_removed) (FwupdClient *client, |
45 | FwupdResult *result); | |
45 | FwupdDevice *result); | |
46 | 46 | void (*device_changed) (FwupdClient *client, |
47 | FwupdResult *result); | |
47 | FwupdDevice *result); | |
48 | 48 | /*< private >*/ |
49 | 49 | void (*_fwupd_reserved1) (void); |
50 | 50 | void (*_fwupd_reserved2) (void); |
94 | 94 | const gchar *device_id, |
95 | 95 | GCancellable *cancellable, |
96 | 96 | GError **error); |
97 | FwupdResult *fwupd_client_get_results (FwupdClient *client, | |
97 | FwupdDevice *fwupd_client_get_results (FwupdClient *client, | |
98 | 98 | const gchar *device_id, |
99 | 99 | GCancellable *cancellable, |
100 | 100 | GError **error); |
1301 | 1301 | fwupd_pad_kv_unx (str, FWUPD_RESULT_KEY_DEVICE_MODIFIED, priv->modified); |
1302 | 1302 | fwupd_pad_kv_ups (str, FWUPD_RESULT_KEY_UPDATE_STATE, priv->update_state); |
1303 | 1303 | fwupd_pad_kv_str (str, FWUPD_RESULT_KEY_UPDATE_ERROR, priv->update_error); |
1304 | if (priv->release_default != NULL) { | |
1305 | g_autofree gchar *tmp = fwupd_release_to_string (priv->release_default); | |
1306 | g_string_append (str, tmp); | |
1307 | } | |
1304 | 1308 | |
1305 | 1309 | return g_string_free (str, FALSE); |
1306 | 1310 | } |
0 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- | |
1 | * | |
2 | * Copyright (C) 2017 Richard Hughes <richard@hughsie.com> | |
3 | * | |
4 | * Licensed under the GNU Lesser General Public License Version 2.1 | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2.1 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
21 | #ifndef __FWUPD_RESULT_PRIVATE_H | |
22 | #define __FWUPD_RESULT_PRIVATE_H | |
23 | ||
24 | #include "fwupd-result.h" | |
25 | ||
26 | void fwupd_result_set_release (FwupdResult *result, | |
27 | FwupdRelease *release); | |
28 | void fwupd_result_set_device (FwupdResult *result, | |
29 | FwupdDevice *device); | |
30 | ||
31 | G_END_DECLS | |
32 | ||
33 | #endif /* __FWUPD_RESULT_PRIVATE_H */ | |
34 |
0 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- | |
1 | * | |
2 | * Copyright (C) 2015-2016 Richard Hughes <richard@hughsie.com> | |
3 | * | |
4 | * Licensed under the GNU Lesser General Public License Version 2.1 | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2.1 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
21 | #include "config.h" | |
22 | ||
23 | #include <glib-object.h> | |
24 | #include <gio/gio.h> | |
25 | #include <string.h> | |
26 | ||
27 | #include "fwupd-common-private.h" | |
28 | #include "fwupd-deprecated.h" | |
29 | #include "fwupd-device-private.h" | |
30 | #include "fwupd-enums-private.h" | |
31 | #include "fwupd-error.h" | |
32 | #include "fwupd-release-private.h" | |
33 | #include "fwupd-result-private.h" | |
34 | ||
35 | static void fwupd_result_finalize (GObject *object); | |
36 | ||
37 | typedef struct { | |
38 | FwupdDevice *device; | |
39 | FwupdRelease *release; | |
40 | } FwupdResultPrivate; | |
41 | ||
42 | enum { | |
43 | SIGNAL_LAST | |
44 | }; | |
45 | ||
46 | enum { | |
47 | PROP_0, | |
48 | PROP_DEVICE_ID, | |
49 | PROP_LAST | |
50 | }; | |
51 | ||
52 | G_DEFINE_TYPE_WITH_PRIVATE (FwupdResult, fwupd_result, G_TYPE_OBJECT) | |
53 | #define GET_PRIVATE(o) (fwupd_result_get_instance_private (o)) | |
54 | ||
55 | /** | |
56 | * fwupd_result_get_release: | |
57 | * @result: A #FwupdResult | |
58 | * | |
59 | * Gets the default release for this result. | |
60 | * | |
61 | * Returns: (transfer none): the #FwupdRelease | |
62 | * | |
63 | * Since: 0.9.3 | |
64 | **/ | |
65 | FwupdRelease * | |
66 | fwupd_result_get_release (FwupdResult *result) | |
67 | { | |
68 | FwupdResultPrivate *priv = GET_PRIVATE (result); | |
69 | g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); | |
70 | return priv->release; | |
71 | } | |
72 | ||
73 | /** | |
74 | * fwupd_result_get_device: | |
75 | * @result: A #FwupdResult | |
76 | * | |
77 | * Gets the default device for this result. | |
78 | * | |
79 | * Returns: (transfer none): the #FwupdDevice | |
80 | * | |
81 | * Since: 0.9.3 | |
82 | **/ | |
83 | FwupdDevice * | |
84 | fwupd_result_get_device (FwupdResult *result) | |
85 | { | |
86 | FwupdResultPrivate *priv = GET_PRIVATE (result); | |
87 | g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); | |
88 | return priv->device; | |
89 | } | |
90 | ||
91 | void | |
92 | fwupd_result_set_release (FwupdResult *result, FwupdRelease *release) | |
93 | { | |
94 | FwupdResultPrivate *priv = GET_PRIVATE (result); | |
95 | g_return_if_fail (FWUPD_IS_RESULT (result)); | |
96 | g_set_object (&priv->release, release); | |
97 | } | |
98 | ||
99 | void | |
100 | fwupd_result_set_device (FwupdResult *result, FwupdDevice *device) | |
101 | { | |
102 | FwupdResultPrivate *priv = GET_PRIVATE (result); | |
103 | g_return_if_fail (FWUPD_IS_RESULT (result)); | |
104 | g_set_object (&priv->device, device); | |
105 | } | |
106 | ||
107 | /** | |
108 | * fwupd_result_to_string: | |
109 | * @result: A #FwupdResult | |
110 | * | |
111 | * Builds a text representation of the object. | |
112 | * | |
113 | * Returns: text, or %NULL for invalid | |
114 | * | |
115 | * Since: 0.7.0 | |
116 | **/ | |
117 | gchar * | |
118 | fwupd_result_to_string (FwupdResult *result) | |
119 | { | |
120 | FwupdResultPrivate *priv = GET_PRIVATE (result); | |
121 | GString *str; | |
122 | g_autofree gchar *device_str = NULL; | |
123 | g_autofree gchar *release_str = NULL; | |
124 | ||
125 | g_return_val_if_fail (FWUPD_IS_RESULT (result), NULL); | |
126 | ||
127 | str = g_string_new (""); | |
128 | ||
129 | /* device and release */ | |
130 | device_str = fwupd_device_to_string (priv->device); | |
131 | g_string_append (str, device_str); | |
132 | release_str = fwupd_release_to_string (priv->release); | |
133 | g_string_append (str, release_str); | |
134 | ||
135 | return g_string_free (str, FALSE); | |
136 | } | |
137 | ||
138 | static void | |
139 | fwupd_result_get_property (GObject *object, guint prop_id, | |
140 | GValue *value, GParamSpec *pspec) | |
141 | { | |
142 | FwupdResult *result = FWUPD_RESULT (object); | |
143 | FwupdResultPrivate *priv = GET_PRIVATE (result); | |
144 | ||
145 | switch (prop_id) { | |
146 | case PROP_DEVICE_ID: | |
147 | g_value_set_string (value, fwupd_device_get_id (priv->device)); | |
148 | break; | |
149 | default: | |
150 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
151 | break; | |
152 | } | |
153 | } | |
154 | ||
155 | static void | |
156 | fwupd_result_set_property (GObject *object, guint prop_id, | |
157 | const GValue *value, GParamSpec *pspec) | |
158 | { | |
159 | FwupdResult *result = FWUPD_RESULT (object); | |
160 | FwupdResultPrivate *priv = GET_PRIVATE (result); | |
161 | ||
162 | switch (prop_id) { | |
163 | case PROP_DEVICE_ID: | |
164 | fwupd_device_set_id (priv->device, g_value_get_string (value)); | |
165 | break; | |
166 | default: | |
167 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
168 | break; | |
169 | } | |
170 | } | |
171 | ||
172 | static void | |
173 | fwupd_result_class_init (FwupdResultClass *klass) | |
174 | { | |
175 | GParamSpec *pspec; | |
176 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
177 | object_class->finalize = fwupd_result_finalize; | |
178 | object_class->get_property = fwupd_result_get_property; | |
179 | object_class->set_property = fwupd_result_set_property; | |
180 | ||
181 | /** | |
182 | * FwupdResult:device-id: | |
183 | * | |
184 | * The device ID for this result. | |
185 | * | |
186 | * Since: 0.7.0 | |
187 | */ | |
188 | pspec = g_param_spec_string ("device-id", NULL, NULL, | |
189 | NULL, | |
190 | G_PARAM_READWRITE); | |
191 | g_object_class_install_property (object_class, PROP_DEVICE_ID, pspec); | |
192 | } | |
193 | ||
194 | static void | |
195 | fwupd_result_init (FwupdResult *result) | |
196 | { | |
197 | FwupdResultPrivate *priv = GET_PRIVATE (result); | |
198 | priv->release = fwupd_release_new (); | |
199 | priv->device = fwupd_device_new (); | |
200 | } | |
201 | ||
202 | static void | |
203 | fwupd_result_finalize (GObject *object) | |
204 | { | |
205 | FwupdResult *result = FWUPD_RESULT (object); | |
206 | FwupdResultPrivate *priv = GET_PRIVATE (result); | |
207 | ||
208 | g_object_unref (priv->device); | |
209 | g_object_unref (priv->release); | |
210 | ||
211 | G_OBJECT_CLASS (fwupd_result_parent_class)->finalize (object); | |
212 | } | |
213 | ||
214 | static void | |
215 | fwupd_result_from_variant_iter (FwupdResult *result, GVariantIter *iter) | |
216 | { | |
217 | FwupdResultPrivate *priv = GET_PRIVATE (result); | |
218 | GVariant *value; | |
219 | const gchar *key; | |
220 | while (g_variant_iter_next (iter, "{&sv}", &key, &value)) { | |
221 | fwupd_release_from_key_value (priv->release, key, value); | |
222 | fwupd_device_from_key_value (priv->device, key, value); | |
223 | g_variant_unref (value); | |
224 | } | |
225 | } | |
226 | ||
227 | /** | |
228 | * fwupd_result_new_from_data: | |
229 | * @data: a #GVariant | |
230 | * | |
231 | * Creates a new result using packed data. | |
232 | * | |
233 | * Returns: a new #FwupdResult, or %NULL if @data was invalid | |
234 | * | |
235 | * Since: 0.7.0 | |
236 | **/ | |
237 | FwupdResult * | |
238 | fwupd_result_new_from_data (GVariant *data) | |
239 | { | |
240 | FwupdResult *res = NULL; | |
241 | const gchar *id; | |
242 | const gchar *type_string; | |
243 | g_autoptr(GVariantIter) iter = NULL; | |
244 | ||
245 | /* format from GetDetails */ | |
246 | type_string = g_variant_get_type_string (data); | |
247 | if (g_strcmp0 (type_string, "(a{sv})") == 0) { | |
248 | res = fwupd_result_new (); | |
249 | g_variant_get (data, "(a{sv})", &iter); | |
250 | fwupd_result_from_variant_iter (res, iter); | |
251 | } else if (g_strcmp0 (type_string, "{sa{sv}}") == 0) { | |
252 | res = fwupd_result_new (); | |
253 | g_variant_get (data, "{&sa{sv}}", &id, &iter); | |
254 | fwupd_device_set_id (fwupd_result_get_device (res), id); | |
255 | fwupd_result_from_variant_iter (res, iter); | |
256 | } else { | |
257 | g_warning ("type %s not known", type_string); | |
258 | } | |
259 | return res; | |
260 | } | |
261 | ||
262 | /** | |
263 | * fwupd_result_new: | |
264 | * | |
265 | * Creates a new result. | |
266 | * | |
267 | * Returns: a new #FwupdResult | |
268 | * | |
269 | * Since: 0.7.0 | |
270 | **/ | |
271 | FwupdResult * | |
272 | fwupd_result_new (void) | |
273 | { | |
274 | FwupdResult *result; | |
275 | result = g_object_new (FWUPD_TYPE_RESULT, NULL); | |
276 | return FWUPD_RESULT (result); | |
277 | } |
0 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- | |
1 | * | |
2 | * Copyright (C) 2015-2016 Richard Hughes <richard@hughsie.com> | |
3 | * | |
4 | * Licensed under the GNU Lesser General Public License Version 2.1 | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2.1 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
21 | #ifndef __FWUPD_RESULT_H | |
22 | #define __FWUPD_RESULT_H | |
23 | ||
24 | #include <glib-object.h> | |
25 | ||
26 | #include "fwupd-device.h" | |
27 | #include "fwupd-enums.h" | |
28 | #include "fwupd-release.h" | |
29 | ||
30 | G_BEGIN_DECLS | |
31 | ||
32 | #define FWUPD_TYPE_RESULT (fwupd_result_get_type ()) | |
33 | G_DECLARE_DERIVABLE_TYPE (FwupdResult, fwupd_result, FWUPD, RESULT, GObject) | |
34 | ||
35 | struct _FwupdResultClass | |
36 | { | |
37 | GObjectClass parent_class; | |
38 | /*< private >*/ | |
39 | void (*_fwupd_reserved1) (void); | |
40 | void (*_fwupd_reserved2) (void); | |
41 | void (*_fwupd_reserved3) (void); | |
42 | void (*_fwupd_reserved4) (void); | |
43 | void (*_fwupd_reserved5) (void); | |
44 | void (*_fwupd_reserved6) (void); | |
45 | void (*_fwupd_reserved7) (void); | |
46 | }; | |
47 | ||
48 | FwupdResult *fwupd_result_new (void); | |
49 | FwupdResult *fwupd_result_new_from_data (GVariant *data); | |
50 | FwupdRelease *fwupd_result_get_release (FwupdResult *result); | |
51 | FwupdDevice *fwupd_result_get_device (FwupdResult *result); | |
52 | ||
53 | GVariant *fwupd_result_to_data (FwupdResult *result, | |
54 | const gchar *type_string); | |
55 | gchar *fwupd_result_to_string (FwupdResult *result); | |
56 | ||
57 | G_END_DECLS | |
58 | ||
59 | #endif /* __FWUPD_RESULT_H */ | |
60 |
27 | 27 | #include "fwupd-enums.h" |
28 | 28 | #include "fwupd-error.h" |
29 | 29 | #include "fwupd-remote-private.h" |
30 | #include "fwupd-result.h" | |
31 | 30 | |
32 | 31 | static gboolean |
33 | 32 | as_test_compare_lines (const gchar *txt1, const gchar *txt2, GError **error) |
175 | 174 | } |
176 | 175 | |
177 | 176 | static void |
178 | fwupd_result_func (void) | |
179 | { | |
180 | FwupdDevice *dev; | |
181 | FwupdRelease *rel; | |
177 | fwupd_device_func (void) | |
178 | { | |
182 | 179 | gboolean ret; |
183 | 180 | g_autofree gchar *str = NULL; |
184 | g_autoptr(FwupdResult) result = NULL; | |
181 | g_autoptr(FwupdDevice) dev = NULL; | |
182 | g_autoptr(FwupdRelease) rel = NULL; | |
185 | 183 | g_autoptr(GError) error = NULL; |
186 | 184 | |
187 | 185 | /* create dummy object */ |
188 | result = fwupd_result_new (); | |
189 | dev = fwupd_result_get_device (result); | |
186 | dev = fwupd_device_new (); | |
190 | 187 | fwupd_device_add_checksum (dev, "beefdead"); |
191 | 188 | fwupd_device_set_created (dev, 1); |
192 | 189 | fwupd_device_set_flags (dev, FWUPD_DEVICE_FLAG_UPDATABLE); |
198 | 195 | fwupd_device_add_icon (dev, "input-gaming"); |
199 | 196 | fwupd_device_add_icon (dev, "input-mouse"); |
200 | 197 | fwupd_device_add_flag (dev, FWUPD_DEVICE_FLAG_REQUIRE_AC); |
201 | rel = fwupd_result_get_release (result); | |
198 | rel = fwupd_release_new (); | |
202 | 199 | fwupd_release_set_trust_flags (rel, FWUPD_TRUST_FLAG_PAYLOAD); |
203 | ||
204 | rel = fwupd_result_get_release (result); | |
205 | 200 | fwupd_release_add_checksum (rel, "deadbeef"); |
206 | 201 | fwupd_release_set_description (rel, "<p>Hi there!</p>"); |
207 | 202 | fwupd_release_set_filename (rel, "firmware.bin"); |
209 | 204 | fwupd_release_set_size (rel, 1024); |
210 | 205 | fwupd_release_set_uri (rel, "http://foo.com"); |
211 | 206 | fwupd_release_set_version (rel, "1.2.3"); |
212 | str = fwupd_result_to_string (result); | |
207 | fwupd_device_add_release (dev, rel); | |
208 | str = fwupd_device_to_string (dev); | |
213 | 209 | g_print ("\n%s", str); |
214 | 210 | |
215 | 211 | /* check GUIDs */ |
301 | 297 | fwupd_client_updates_func (void) |
302 | 298 | { |
303 | 299 | FwupdDevice *dev; |
304 | FwupdResult *res; | |
305 | 300 | g_autoptr(FwupdClient) client = NULL; |
306 | 301 | g_autoptr(GPtrArray) array = NULL; |
307 | 302 | g_autoptr(GError) error = NULL; |
319 | 314 | g_assert_cmpint (array->len, >, 0); |
320 | 315 | |
321 | 316 | /* check device */ |
322 | res = g_ptr_array_index (array, 0); | |
323 | g_assert (FWUPD_IS_RESULT (res)); | |
324 | dev = fwupd_result_get_device (res); | |
317 | dev = g_ptr_array_index (array, 0); | |
318 | g_assert (FWUPD_IS_DEVICE (dev)); | |
325 | 319 | g_assert_cmpstr (fwupd_device_get_guid_default (dev), !=, NULL); |
326 | 320 | g_assert_cmpstr (fwupd_device_get_id (dev), !=, NULL); |
327 | 321 | } |
348 | 342 | |
349 | 343 | /* tests go here */ |
350 | 344 | g_test_add_func ("/fwupd/enums", fwupd_enums_func); |
351 | g_test_add_func ("/fwupd/result", fwupd_result_func); | |
345 | g_test_add_func ("/fwupd/device", fwupd_device_func); | |
352 | 346 | g_test_add_func ("/fwupd/remote{download}", fwupd_remote_download_func); |
353 | 347 | g_test_add_func ("/fwupd/remote{base-uri}", fwupd_remote_baseuri_func); |
354 | 348 | g_test_add_func ("/fwupd/remote{local}", fwupd_remote_local_func); |
35 | 35 | #include <libfwupd/fwupd-error.h> |
36 | 36 | #include <libfwupd/fwupd-release.h> |
37 | 37 | #include <libfwupd/fwupd-remote.h> |
38 | #include <libfwupd/fwupd-result.h> | |
39 | 38 | #include <libfwupd/fwupd-version.h> |
40 | 39 | |
41 | 40 | #ifndef FWUPD_DISABLE_DEPRECATED |
21 | 21 | 'fwupd-error.h', |
22 | 22 | 'fwupd-remote.h', |
23 | 23 | 'fwupd-release.h', |
24 | 'fwupd-result.h', | |
25 | 24 | fwupd_version_h, |
26 | 25 | ], |
27 | 26 | subdir : 'fwupd-1/libfwupd', |
39 | 38 | 'fwupd-error.c', |
40 | 39 | 'fwupd-release.c', |
41 | 40 | 'fwupd-remote.c', |
42 | 'fwupd-result.c', | |
43 | 41 | ], |
44 | 42 | soversion : lt_current, |
45 | 43 | version : lt_version, |
83 | 81 | 'fwupd-release.h', |
84 | 82 | 'fwupd-remote.c', |
85 | 83 | 'fwupd-remote.h', |
86 | 'fwupd-result.c', | |
87 | 'fwupd-result.h', | |
88 | 84 | ], |
89 | 85 | nsversion : '2.0', |
90 | 86 | namespace : 'Fwupd', |
31 | 31 | #include "fwupd-error.h" |
32 | 32 | #include "fwupd-release-private.h" |
33 | 33 | #include "fwupd-remote-private.h" |
34 | #include "fwupd-result-private.h" | |
35 | 34 | #include "fwupd-resources.h" |
36 | 35 | |
37 | 36 | #include "fu-common.h" |
26 | 26 | #include <appstream-glib.h> |
27 | 27 | #include <glib-object.h> |
28 | 28 | |
29 | #include "fwupd-result.h" | |
29 | #include "fwupd-device.h" | |
30 | 30 | #include "fwupd-enums.h" |
31 | 31 | |
32 | 32 | #include "fu-plugin.h" |
31 | 31 | #include "fwupd-device-private.h" |
32 | 32 | #include "fwupd-release-private.h" |
33 | 33 | #include "fwupd-remote-private.h" |
34 | #include "fwupd-result-private.h" | |
35 | 34 | #include "fwupd-resources.h" |
36 | 35 | |
37 | 36 | #include "fu-common.h" |
352 | 352 | if (array == NULL) |
353 | 353 | return FALSE; |
354 | 354 | for (guint i = 0; i < array->len; i++) { |
355 | FwupdResult *res = g_ptr_array_index (array, i); | |
355 | FwupdDevice *dev = g_ptr_array_index (array, i); | |
356 | 356 | g_autofree gchar *tmp = NULL; |
357 | tmp = fwupd_result_to_string (res); | |
357 | tmp = fwupd_device_to_string (dev); | |
358 | 358 | g_print ("%s", tmp); |
359 | 359 | } |
360 | 360 | return TRUE; |
456 | 456 | |
457 | 457 | /* apply each update */ |
458 | 458 | for (guint i = 0; i < results->len; i++) { |
459 | FwupdResult *res = g_ptr_array_index (results, i); | |
460 | FwupdDevice *dev = fwupd_result_get_device (res); | |
461 | FwupdRelease *rel = fwupd_result_get_release (res); | |
459 | FwupdDevice *dev = g_ptr_array_index (results, i); | |
460 | FwupdRelease *rel = fwupd_device_get_release_default (dev); | |
462 | 461 | |
463 | 462 | /* check not already done */ |
464 | 463 | if (fwupd_device_get_update_state (dev) != FWUPD_UPDATE_STATE_PENDING) |
829 | 828 | fu_util_get_results (FuUtilPrivate *priv, gchar **values, GError **error) |
830 | 829 | { |
831 | 830 | g_autofree gchar *tmp = NULL; |
832 | g_autoptr(FwupdResult) res = NULL; | |
831 | g_autoptr(FwupdDevice) dev = NULL; | |
833 | 832 | |
834 | 833 | if (g_strv_length (values) != 1) { |
835 | 834 | g_set_error_literal (error, |
838 | 837 | "Invalid arguments: expected 'DeviceID'"); |
839 | 838 | return FALSE; |
840 | 839 | } |
841 | res = fwupd_client_get_results (priv->client, values[0], NULL, error); | |
842 | if (res == NULL) | |
843 | return FALSE; | |
844 | tmp = fwupd_result_to_string (res); | |
840 | dev = fwupd_client_get_results (priv->client, values[0], NULL, error); | |
841 | if (dev == NULL) | |
842 | return FALSE; | |
843 | tmp = fwupd_device_to_string (dev); | |
845 | 844 | g_print ("%s", tmp); |
846 | 845 | return TRUE; |
847 | 846 | } |
1220 | 1219 | |
1221 | 1220 | static void |
1222 | 1221 | fu_util_device_added_cb (FwupdClient *client, |
1223 | FwupdResult *device, | |
1222 | FwupdDevice *device, | |
1224 | 1223 | gpointer user_data) |
1225 | 1224 | { |
1226 | g_autofree gchar *tmp = fwupd_result_to_string (device); | |
1225 | g_autofree gchar *tmp = fwupd_device_to_string (device); | |
1227 | 1226 | /* TRANSLATORS: this is when a device is hotplugged */ |
1228 | 1227 | g_print ("%s\n%s", _("Device added:"), tmp); |
1229 | 1228 | } |
1230 | 1229 | |
1231 | 1230 | static void |
1232 | 1231 | fu_util_device_removed_cb (FwupdClient *client, |
1233 | FwupdResult *device, | |
1232 | FwupdDevice *device, | |
1234 | 1233 | gpointer user_data) |
1235 | 1234 | { |
1236 | g_autofree gchar *tmp = fwupd_result_to_string (device); | |
1235 | g_autofree gchar *tmp = fwupd_device_to_string (device); | |
1237 | 1236 | /* TRANSLATORS: this is when a device is hotplugged */ |
1238 | 1237 | g_print ("%s\n%s", _("Device removed:"), tmp); |
1239 | 1238 | } |
1240 | 1239 | |
1241 | 1240 | static void |
1242 | 1241 | fu_util_device_changed_cb (FwupdClient *client, |
1243 | FwupdResult *device, | |
1242 | FwupdDevice *device, | |
1244 | 1243 | gpointer user_data) |
1245 | 1244 | { |
1246 | g_autofree gchar *tmp = fwupd_result_to_string (device); | |
1245 | g_autofree gchar *tmp = fwupd_device_to_string (device); | |
1247 | 1246 | /* TRANSLATORS: this is when a device has been updated */ |
1248 | 1247 | g_print ("%s\n%s", _("Device changed:"), tmp); |
1249 | 1248 | } |