Codebase list fwupd / 80893e2
trivial: Remove FwupdResult from libfwupd Richard Hughes 6 years ago
15 changed file(s) with 60 addition(s) and 468 deletion(s). Raw diff Collapse all Expand all
3030 <xi:include href="xml/fwupd-enums.xml"/>
3131 <xi:include href="xml/fwupd-release.xml"/>
3232 <xi:include href="xml/fwupd-remote.xml"/>
33 <xi:include href="xml/fwupd-result.xml"/>
3433 <xi:include href="xml/fwupd-version.xml"/>
3534 </reference>
3635
33 When we next bump soname the following changes are planned:
44
55 * {sa{sv}} -> {a{sv}} -- we don't always want to send the device ID
6 * Make DeviceAdded emit a FwupdDevice, not a FwupdResult
76 * Unexport fwupd_result_to_data() and fwupd_result_new_from_data()
87
98 Migration from Version 0.9.x
2120 * Switch FWUPD_RESULT_KEY_DEVICE_CHECKSUM_KIND to fwupd_checksum_guess_kind()
2221 * Rename fwupd_result_update_*() to fwupd_release_*()
2322 * Rename fwupd_result_*() to fwupd_device_*()
23 * Convert FwupdResult to FwupdDevice in all callbacks
3737 #include "fwupd-device-private.h"
3838 #include "fwupd-release-private.h"
3939 #include "fwupd-remote-private.h"
40 #include "fwupd-result.h"
4140
4241 static void fwupd_client_finalize (GObject *object);
4342
157156 GVariant *parameters,
158157 FwupdClient *client)
159158 {
160 g_autoptr(FwupdResult) res = NULL;
159 g_autoptr(FwupdDevice) dev = NULL;
161160 if (g_strcmp0 (signal_name, "Changed") == 0) {
162161 g_debug ("Emitting ::changed()");
163162 g_signal_emit (client, signals[SIGNAL_CHANGED], 0);
164163 return;
165164 }
166165 if (g_strcmp0 (signal_name, "DeviceAdded") == 0) {
167 res = fwupd_result_new_from_data (parameters);
166 dev = fwupd_device_new_from_data (parameters);
168167 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);
171170 return;
172171 }
173172 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);
176175 g_debug ("Emitting ::device-removed(%s)",
177 fwupd_device_get_id (fwupd_result_get_device (res)));
176 fwupd_device_get_id (dev));
178177 return;
179178 }
180179 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);
183182 g_debug ("Emitting ::device-changed(%s)",
184 fwupd_device_get_id (fwupd_result_get_device (res)));
183 fwupd_device_get_id (dev));
185184 return;
186185 }
187186 g_debug ("Unknown signal name '%s' from %s", signal_name, sender_name);
239238 if (val != NULL)
240239 fwupd_client_set_daemon_version (client, g_variant_get_string (val, NULL));
241240 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;
264241 }
265242
266243 static GPtrArray *
449426 *
450427 * Gets all the devices with known updates.
451428 *
452 * Returns: (element-type FwupdResult) (transfer container): results
429 * Returns: (element-type FwupdDevice) (transfer container): results
453430 *
454431 * Since: 0.7.0
455432 **/
480457 fwupd_client_fixup_dbus_error (*error);
481458 return NULL;
482459 }
483 return fwupd_client_parse_results_from_data (val);
460 return fwupd_client_parse_devices_from_variant (val);
484461 }
485462
486463 /**
832809 *
833810 * Gets the results of a previous firmware update for a specific device.
834811 *
835 * Returns: (transfer full): a #FwupdResult, or %NULL for failure
812 * Returns: (transfer full): a #FwupdDevice, or %NULL for failure
836813 *
837814 * Since: 0.7.0
838815 **/
839 FwupdResult *
816 FwupdDevice *
840817 fwupd_client_get_results (FwupdClient *client, const gchar *device_id,
841818 GCancellable *cancellable, GError **error)
842819 {
868845 helper->error = NULL;
869846 return NULL;
870847 }
871 return fwupd_result_new_from_data (helper->val);
848 return fwupd_device_new_from_data (helper->val);
872849 }
873850
874851 static void
1009986 *
1010987 * Gets details about a specific firmware file.
1011988 *
1012 * Returns: (transfer container) (element-type FwupdResult): an array of results
989 * Returns: (transfer container) (element-type FwupdDevice): an array of results
1013990 *
1014991 * Since: 1.0.0
1015992 **/
10791056 }
10801057
10811058 /* return results */
1082 return fwupd_client_parse_results_from_data (helper->val);
1059 return fwupd_client_parse_devices_from_variant (helper->val);
10831060 }
10841061
10851062 /**
14801457 /**
14811458 * FwupdClient::device-added:
14821459 * @client: the #FwupdClient instance that emitted the signal
1483 * @result: the #FwupdResult
1460 * @result: the #FwupdDevice
14841461 *
14851462 * The ::device-added signal is emitted when a device has been
14861463 * added.
14921469 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
14931470 G_STRUCT_OFFSET (FwupdClientClass, device_added),
14941471 NULL, NULL, g_cclosure_marshal_generic,
1495 G_TYPE_NONE, 1, FWUPD_TYPE_RESULT);
1472 G_TYPE_NONE, 1, FWUPD_TYPE_DEVICE);
14961473
14971474 /**
14981475 * FwupdClient::device-removed:
14991476 * @client: the #FwupdClient instance that emitted the signal
1500 * @result: the #FwupdResult
1477 * @result: the #FwupdDevice
15011478 *
15021479 * The ::device-removed signal is emitted when a device has been
15031480 * removed.
15091486 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
15101487 G_STRUCT_OFFSET (FwupdClientClass, device_removed),
15111488 NULL, NULL, g_cclosure_marshal_generic,
1512 G_TYPE_NONE, 1, FWUPD_TYPE_RESULT);
1489 G_TYPE_NONE, 1, FWUPD_TYPE_DEVICE);
15131490
15141491 /**
15151492 * FwupdClient::device-changed:
15161493 * @client: the #FwupdClient instance that emitted the signal
1517 * @result: the #FwupdResult
1494 * @result: the #FwupdDevice
15181495 *
15191496 * The ::device-changed signal is emitted when a device has been
15201497 * changed in some way, e.g. the version number is updated.
15261503 G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
15271504 G_STRUCT_OFFSET (FwupdClientClass, device_changed),
15281505 NULL, NULL, g_cclosure_marshal_generic,
1529 G_TYPE_NONE, 1, FWUPD_TYPE_RESULT);
1506 G_TYPE_NONE, 1, FWUPD_TYPE_DEVICE);
15301507
15311508 /**
15321509 * FwupdClient:status:
2525 #include <gio/gio.h>
2626
2727 #include "fwupd-enums.h"
28 #include "fwupd-device.h"
2829 #include "fwupd-remote.h"
29 #include "fwupd-result.h"
3030
3131 G_BEGIN_DECLS
3232
4040 void (*status_changed) (FwupdClient *client,
4141 FwupdStatus status);
4242 void (*device_added) (FwupdClient *client,
43 FwupdResult *result);
43 FwupdDevice *result);
4444 void (*device_removed) (FwupdClient *client,
45 FwupdResult *result);
45 FwupdDevice *result);
4646 void (*device_changed) (FwupdClient *client,
47 FwupdResult *result);
47 FwupdDevice *result);
4848 /*< private >*/
4949 void (*_fwupd_reserved1) (void);
5050 void (*_fwupd_reserved2) (void);
9494 const gchar *device_id,
9595 GCancellable *cancellable,
9696 GError **error);
97 FwupdResult *fwupd_client_get_results (FwupdClient *client,
97 FwupdDevice *fwupd_client_get_results (FwupdClient *client,
9898 const gchar *device_id,
9999 GCancellable *cancellable,
100100 GError **error);
13011301 fwupd_pad_kv_unx (str, FWUPD_RESULT_KEY_DEVICE_MODIFIED, priv->modified);
13021302 fwupd_pad_kv_ups (str, FWUPD_RESULT_KEY_UPDATE_STATE, priv->update_state);
13031303 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 }
13041308
13051309 return g_string_free (str, FALSE);
13061310 }
+0
-35
libfwupd/fwupd-result-private.h less more
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
-278
libfwupd/fwupd-result.c less more
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
-61
libfwupd/fwupd-result.h less more
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
2727 #include "fwupd-enums.h"
2828 #include "fwupd-error.h"
2929 #include "fwupd-remote-private.h"
30 #include "fwupd-result.h"
3130
3231 static gboolean
3332 as_test_compare_lines (const gchar *txt1, const gchar *txt2, GError **error)
175174 }
176175
177176 static void
178 fwupd_result_func (void)
179 {
180 FwupdDevice *dev;
181 FwupdRelease *rel;
177 fwupd_device_func (void)
178 {
182179 gboolean ret;
183180 g_autofree gchar *str = NULL;
184 g_autoptr(FwupdResult) result = NULL;
181 g_autoptr(FwupdDevice) dev = NULL;
182 g_autoptr(FwupdRelease) rel = NULL;
185183 g_autoptr(GError) error = NULL;
186184
187185 /* create dummy object */
188 result = fwupd_result_new ();
189 dev = fwupd_result_get_device (result);
186 dev = fwupd_device_new ();
190187 fwupd_device_add_checksum (dev, "beefdead");
191188 fwupd_device_set_created (dev, 1);
192189 fwupd_device_set_flags (dev, FWUPD_DEVICE_FLAG_UPDATABLE);
198195 fwupd_device_add_icon (dev, "input-gaming");
199196 fwupd_device_add_icon (dev, "input-mouse");
200197 fwupd_device_add_flag (dev, FWUPD_DEVICE_FLAG_REQUIRE_AC);
201 rel = fwupd_result_get_release (result);
198 rel = fwupd_release_new ();
202199 fwupd_release_set_trust_flags (rel, FWUPD_TRUST_FLAG_PAYLOAD);
203
204 rel = fwupd_result_get_release (result);
205200 fwupd_release_add_checksum (rel, "deadbeef");
206201 fwupd_release_set_description (rel, "<p>Hi there!</p>");
207202 fwupd_release_set_filename (rel, "firmware.bin");
209204 fwupd_release_set_size (rel, 1024);
210205 fwupd_release_set_uri (rel, "http://foo.com");
211206 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);
213209 g_print ("\n%s", str);
214210
215211 /* check GUIDs */
301297 fwupd_client_updates_func (void)
302298 {
303299 FwupdDevice *dev;
304 FwupdResult *res;
305300 g_autoptr(FwupdClient) client = NULL;
306301 g_autoptr(GPtrArray) array = NULL;
307302 g_autoptr(GError) error = NULL;
319314 g_assert_cmpint (array->len, >, 0);
320315
321316 /* 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));
325319 g_assert_cmpstr (fwupd_device_get_guid_default (dev), !=, NULL);
326320 g_assert_cmpstr (fwupd_device_get_id (dev), !=, NULL);
327321 }
348342
349343 /* tests go here */
350344 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);
352346 g_test_add_func ("/fwupd/remote{download}", fwupd_remote_download_func);
353347 g_test_add_func ("/fwupd/remote{base-uri}", fwupd_remote_baseuri_func);
354348 g_test_add_func ("/fwupd/remote{local}", fwupd_remote_local_func);
3535 #include <libfwupd/fwupd-error.h>
3636 #include <libfwupd/fwupd-release.h>
3737 #include <libfwupd/fwupd-remote.h>
38 #include <libfwupd/fwupd-result.h>
3938 #include <libfwupd/fwupd-version.h>
4039
4140 #ifndef FWUPD_DISABLE_DEPRECATED
2121 'fwupd-error.h',
2222 'fwupd-remote.h',
2323 'fwupd-release.h',
24 'fwupd-result.h',
2524 fwupd_version_h,
2625 ],
2726 subdir : 'fwupd-1/libfwupd',
3938 'fwupd-error.c',
4039 'fwupd-release.c',
4140 'fwupd-remote.c',
42 'fwupd-result.c',
4341 ],
4442 soversion : lt_current,
4543 version : lt_version,
8381 'fwupd-release.h',
8482 'fwupd-remote.c',
8583 'fwupd-remote.h',
86 'fwupd-result.c',
87 'fwupd-result.h',
8884 ],
8985 nsversion : '2.0',
9086 namespace : 'Fwupd',
3131 #include "fwupd-error.h"
3232 #include "fwupd-release-private.h"
3333 #include "fwupd-remote-private.h"
34 #include "fwupd-result-private.h"
3534 #include "fwupd-resources.h"
3635
3736 #include "fu-common.h"
2626 #include <appstream-glib.h>
2727 #include <glib-object.h>
2828
29 #include "fwupd-result.h"
29 #include "fwupd-device.h"
3030 #include "fwupd-enums.h"
3131
3232 #include "fu-plugin.h"
3131 #include "fwupd-device-private.h"
3232 #include "fwupd-release-private.h"
3333 #include "fwupd-remote-private.h"
34 #include "fwupd-result-private.h"
3534 #include "fwupd-resources.h"
3635
3736 #include "fu-common.h"
352352 if (array == NULL)
353353 return FALSE;
354354 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);
356356 g_autofree gchar *tmp = NULL;
357 tmp = fwupd_result_to_string (res);
357 tmp = fwupd_device_to_string (dev);
358358 g_print ("%s", tmp);
359359 }
360360 return TRUE;
456456
457457 /* apply each update */
458458 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);
462461
463462 /* check not already done */
464463 if (fwupd_device_get_update_state (dev) != FWUPD_UPDATE_STATE_PENDING)
829828 fu_util_get_results (FuUtilPrivate *priv, gchar **values, GError **error)
830829 {
831830 g_autofree gchar *tmp = NULL;
832 g_autoptr(FwupdResult) res = NULL;
831 g_autoptr(FwupdDevice) dev = NULL;
833832
834833 if (g_strv_length (values) != 1) {
835834 g_set_error_literal (error,
838837 "Invalid arguments: expected 'DeviceID'");
839838 return FALSE;
840839 }
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);
845844 g_print ("%s", tmp);
846845 return TRUE;
847846 }
12201219
12211220 static void
12221221 fu_util_device_added_cb (FwupdClient *client,
1223 FwupdResult *device,
1222 FwupdDevice *device,
12241223 gpointer user_data)
12251224 {
1226 g_autofree gchar *tmp = fwupd_result_to_string (device);
1225 g_autofree gchar *tmp = fwupd_device_to_string (device);
12271226 /* TRANSLATORS: this is when a device is hotplugged */
12281227 g_print ("%s\n%s", _("Device added:"), tmp);
12291228 }
12301229
12311230 static void
12321231 fu_util_device_removed_cb (FwupdClient *client,
1233 FwupdResult *device,
1232 FwupdDevice *device,
12341233 gpointer user_data)
12351234 {
1236 g_autofree gchar *tmp = fwupd_result_to_string (device);
1235 g_autofree gchar *tmp = fwupd_device_to_string (device);
12371236 /* TRANSLATORS: this is when a device is hotplugged */
12381237 g_print ("%s\n%s", _("Device removed:"), tmp);
12391238 }
12401239
12411240 static void
12421241 fu_util_device_changed_cb (FwupdClient *client,
1243 FwupdResult *device,
1242 FwupdDevice *device,
12441243 gpointer user_data)
12451244 {
1246 g_autofree gchar *tmp = fwupd_result_to_string (device);
1245 g_autofree gchar *tmp = fwupd_device_to_string (device);
12471246 /* TRANSLATORS: this is when a device has been updated */
12481247 g_print ("%s\n%s", _("Device changed:"), tmp);
12491248 }