Debian Codegraph @

lib/packagekit-glib2/pk-task-sync.c

raw
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2008-2009 Richard Hughes <[email protected]>
4 *
5 * Licensed under the GNU Lesser General Public License Version 2.1
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "config.h"
23
24 #include <stdio.h>
25 #include <string.h>
26 #include <gio/gio.h>
27 #include <glib.h>
28 #include <packagekit-glib2/pk-results.h>
29 #include <packagekit-glib2/pk-task.h>
30 #include <packagekit-glib2/pk-progress.h>
31
32 #include "pk-task-sync.h"
33
34 /* tiny helper to help us do the async operation */
35 typedef struct {
36 GError **error;
37 GMainContext *context;
38 GMainLoop *loop;
39 PkResults *results;
40 } PkTaskHelper;
41
42 /*
43 * pk_task_generic_finish_sync:
44 **/
45 static void
46 pk_task_generic_finish_sync (PkTask *task, GAsyncResult *res, PkTaskHelper *helper)
47 {
48 PkResults *results;
49 /* get the result */
50 results = pk_task_generic_finish (task, res, helper->error);
51 if (results != NULL) {
52 g_object_unref (results);
53 helper->results = g_object_ref (results);
54 }
55 g_main_loop_quit (helper->loop);
56 }
57
58 /**
59 * pk_task_remove_packages_sync:
60 * @task: a valid #PkTask instance
61 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
62 * @allow_deps: if other dependent packages are allowed to be removed from the computer
63 * @autoremove: if other packages installed at the same time should be tried to remove
64 * @cancellable: a #GCancellable or %NULL
65 * @progress_callback: (scope call): the function to run when the progress changes
66 * @progress_user_data: data to pass to @progress_callback
67 * @error: the #GError to store any failure, or %NULL
68 *
69 * Remove a package (optionally with dependancies) from the system.
70 * If @allow_deps is set to %FALSE, and other packages would have to be removed,
71 * then the transaction would fail.
72 *
73 * Warning: this function is synchronous, and may block. Do not use it in GUI
74 * applications.
75 *
76 * Return value: (transfer full): a #PkResults object, or %NULL for error
77 *
78 * Since: 0.5.3
79 **/
80 PkResults *
81 pk_task_remove_packages_sync (PkTask *task, gchar **package_ids, gboolean allow_deps, gboolean autoremove, GCancellable *cancellable,
82 PkProgressCallback progress_callback, gpointer progress_user_data, GError **error)
83 {
84 PkTaskHelper helper;
85 PkResults *results;
86
87 g_return_val_if_fail (PK_IS_TASK (task), NULL);
88 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
89
90 /* create temp object */
91 memset (&helper, 0, sizeof (PkTaskHelper));
92 helper.context = g_main_context_new ();
93 helper.loop = g_main_loop_new (helper.context, FALSE);
94 helper.error = error;
95
96 g_main_context_push_thread_default (helper.context);
97
98 /* run async method */
99 pk_task_remove_packages_async (task, package_ids, allow_deps, autoremove, cancellable, progress_callback, progress_user_data,
100 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
101
102 g_main_loop_run (helper.loop);
103
104 results = helper.results;
105
106 g_main_context_pop_thread_default (helper.context);
107
108 /* free temp object */
109 g_main_loop_unref (helper.loop);
110 g_main_context_unref (helper.context);
111
112 return results;
113 }
114
115 /**
116 * pk_task_install_packages_sync:
117 * @task: a valid #PkTask instance
118 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
119 * @cancellable: a #GCancellable or %NULL
120 * @progress_callback: (scope call): the function to run when the progress changes
121 * @progress_user_data: data to pass to @progress_callback
122 * @error: the #GError to store any failure, or %NULL
123 *
124 * Install a package of the newest and most correct version.
125 *
126 * Warning: this function is synchronous, and may block. Do not use it in GUI
127 * applications.
128 *
129 * Return value: (transfer full): a #PkResults object, or %NULL for error
130 *
131 * Since: 0.5.3
132 **/
133 PkResults *
134 pk_task_install_packages_sync (PkTask *task, gchar **package_ids, GCancellable *cancellable,
135 PkProgressCallback progress_callback, gpointer progress_user_data, GError **error)
136 {
137 PkTaskHelper helper;
138 PkResults *results;
139
140 g_return_val_if_fail (PK_IS_TASK (task), NULL);
141 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
142
143 /* create temp object */
144 memset (&helper, 0, sizeof (PkTaskHelper));
145 helper.context = g_main_context_new ();
146 helper.loop = g_main_loop_new (helper.context, FALSE);
147 helper.error = error;
148
149 g_main_context_push_thread_default (helper.context);
150
151 /* run async method */
152 pk_task_install_packages_async (task, package_ids, cancellable, progress_callback, progress_user_data,
153 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
154
155 g_main_loop_run (helper.loop);
156
157 results = helper.results;
158
159 g_main_context_pop_thread_default (helper.context);
160
161 /* free temp object */
162 g_main_loop_unref (helper.loop);
163 g_main_context_unref (helper.context);
164
165 return results;
166 }
167
168 /**
169 * pk_task_update_packages_sync:
170 * @task: a valid #PkTask instance
171 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
172 * @cancellable: a #GCancellable or %NULL
173 * @progress_callback: (scope call): the function to run when the progress changes
174 * @progress_user_data: data to pass to @progress_callback
175 * @error: the #GError to store any failure, or %NULL
176 *
177 * Update specific packages to the newest available versions.
178 *
179 * Warning: this function is synchronous, and may block. Do not use it in GUI
180 * applications.
181 *
182 * Return value: (transfer full): a #PkResults object, or %NULL for error
183 *
184 * Since: 0.5.3
185 **/
186 PkResults *
187 pk_task_update_packages_sync (PkTask *task, gchar **package_ids, GCancellable *cancellable,
188 PkProgressCallback progress_callback, gpointer progress_user_data, GError **error)
189 {
190 PkTaskHelper helper;
191 PkResults *results;
192
193 g_return_val_if_fail (PK_IS_TASK (task), NULL);
194 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
195
196 /* create temp object */
197 memset (&helper, 0, sizeof (PkTaskHelper));
198 helper.context = g_main_context_new ();
199 helper.loop = g_main_loop_new (helper.context, FALSE);
200 helper.error = error;
201
202 g_main_context_push_thread_default (helper.context);
203
204 /* run async method */
205 pk_task_update_packages_async (task, package_ids, cancellable, progress_callback, progress_user_data,
206 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
207
208 g_main_loop_run (helper.loop);
209
210 results = helper.results;
211
212 g_main_context_pop_thread_default (helper.context);
213
214 /* free temp object */
215 g_main_loop_unref (helper.loop);
216 g_main_context_unref (helper.context);
217
218 return results;
219 }
220
221 /**
222 * pk_task_install_files_sync:
223 * @task: a valid #PkTask instance
224 * @files: (array zero-terminated=1): a file such as "/home/hughsie/Desktop/hal-devel-0.10.0.rpm"
225 * @cancellable: a #GCancellable or %NULL
226 * @progress_callback: (scope call): the function to run when the progress changes
227 * @progress_user_data: data to pass to @progress_callback
228 * @error: the #GError to store any failure, or %NULL
229 *
230 * Install a file locally, and get the deps from the repositories.
231 * This is useful for double clicking on a .rpm or .deb file.
232 *
233 * Warning: this function is synchronous, and may block. Do not use it in GUI
234 * applications.
235 *
236 * Return value: (transfer full): a #PkResults object, or %NULL for error
237 *
238 * Since: 0.5.3
239 **/
240 PkResults *
241 pk_task_install_files_sync (PkTask *task, gchar **files, GCancellable *cancellable,
242 PkProgressCallback progress_callback, gpointer progress_user_data, GError **error)
243 {
244 PkTaskHelper helper;
245 PkResults *results;
246
247 g_return_val_if_fail (PK_IS_TASK (task), NULL);
248 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
249
250 /* create temp object */
251 memset (&helper, 0, sizeof (PkTaskHelper));
252 helper.context = g_main_context_new ();
253 helper.loop = g_main_loop_new (helper.context, FALSE);
254 helper.error = error;
255
256 g_main_context_push_thread_default (helper.context);
257
258 /* run async method */
259 pk_task_install_files_async (task, files, cancellable, progress_callback, progress_user_data,
260 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
261
262 g_main_loop_run (helper.loop);
263
264 results = helper.results;
265
266 g_main_context_pop_thread_default (helper.context);
267
268 /* free temp object */
269 g_main_loop_unref (helper.loop);
270 g_main_context_unref (helper.context);
271
272 return results;
273 }
274
275 /**
276 * pk_task_resolve_sync:
277 * @task: a valid #PkTask instance
278 * @filters: a bitfield of filters that can be used to limit the results
279 * @packages: (array zero-terminated=1): package names to find
280 * @cancellable: a #GCancellable or %NULL
281 * @progress_callback: (scope call): the function to run when the progress changes
282 * @progress_user_data: data to pass to @progress_callback
283 * @error: the #GError to store any failure, or %NULL
284 *
285 * Resolves a package name to a package-id.
286 *
287 * Since: 0.6.5
288 *
289 * Return value: (transfer full): a #PkResults object, or %NULL for error
290 **/
291 PkResults *
292 pk_task_resolve_sync (PkTask *task, PkBitfield filters, gchar **packages, GCancellable *cancellable,
293 PkProgressCallback progress_callback, gpointer progress_user_data,
294 GError **error)
295 {
296 PkTaskHelper helper;
297 PkResults *results;
298
299 g_return_val_if_fail (PK_IS_TASK (task), NULL);
300 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
301
302 /* create temp object */
303 memset (&helper, 0, sizeof (PkTaskHelper));
304 helper.context = g_main_context_new ();
305 helper.loop = g_main_loop_new (helper.context, FALSE);
306 helper.error = error;
307
308 g_main_context_push_thread_default (helper.context);
309
310 /* run async method */
311 pk_task_resolve_async (task, filters, packages, cancellable, progress_callback, progress_user_data,
312 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
313
314 g_main_loop_run (helper.loop);
315
316 results = helper.results;
317
318 g_main_context_pop_thread_default (helper.context);
319
320 /* free temp object */
321 g_main_loop_unref (helper.loop);
322 g_main_context_unref (helper.context);
323
324 return results;
325 }
326
327 /**
328 * pk_task_search_names_sync:
329 * @task: a valid #PkTask instance
330 * @filters: a bitfield of filters that can be used to limit the results
331 * @values: (array zero-terminated=1): search values
332 * @cancellable: a #GCancellable or %NULL
333 * @progress_callback: (scope call): the function to run when the progress changes
334 * @progress_user_data: data to pass to @progress_callback
335 * @error: the #GError to store any failure, or %NULL
336 *
337 * Searches for a package name.
338 *
339 * Since: 0.6.5
340 *
341 * Return value: (transfer full): a #PkResults object, or %NULL for error
342 **/
343 PkResults *
344 pk_task_search_names_sync (PkTask *task, PkBitfield filters, gchar **values, GCancellable *cancellable,
345 PkProgressCallback progress_callback, gpointer progress_user_data,
346 GError **error)
347 {
348 PkTaskHelper helper;
349 PkResults *results;
350
351 g_return_val_if_fail (PK_IS_TASK (task), NULL);
352 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
353
354 /* create temp object */
355 memset (&helper, 0, sizeof (PkTaskHelper));
356 helper.context = g_main_context_new ();
357 helper.loop = g_main_loop_new (helper.context, FALSE);
358 helper.error = error;
359
360 g_main_context_push_thread_default (helper.context);
361
362 /* run async method */
363 pk_task_search_names_async (task, filters, values, cancellable, progress_callback, progress_user_data,
364 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
365
366 g_main_loop_run (helper.loop);
367
368 results = helper.results;
369
370 g_main_context_pop_thread_default (helper.context);
371
372 /* free temp object */
373 g_main_loop_unref (helper.loop);
374 g_main_context_unref (helper.context);
375
376 return results;
377 }
378
379 /**
380 * pk_task_search_details_sync:
381 * @task: a valid #PkTask instance
382 * @filters: a bitfield of filters that can be used to limit the results
383 * @values: (array zero-terminated=1): search values
384 * @cancellable: a #GCancellable or %NULL
385 * @progress_callback: (scope call): the function to run when the progress changes
386 * @progress_user_data: data to pass to @progress_callback
387 * @error: the #GError to store any failure, or %NULL
388 *
389 * Searches for some package details.
390 *
391 * Since: 0.6.5
392 *
393 * Return value: (transfer full): a #PkResults object, or %NULL for error
394 **/
395 PkResults *
396 pk_task_search_details_sync (PkTask *task, PkBitfield filters, gchar **values, GCancellable *cancellable,
397 PkProgressCallback progress_callback, gpointer progress_user_data,
398 GError **error)
399 {
400 PkTaskHelper helper;
401 PkResults *results;
402
403 g_return_val_if_fail (PK_IS_TASK (task), NULL);
404 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
405
406 /* create temp object */
407 memset (&helper, 0, sizeof (PkTaskHelper));
408 helper.context = g_main_context_new ();
409 helper.loop = g_main_loop_new (helper.context, FALSE);
410 helper.error = error;
411
412 g_main_context_push_thread_default (helper.context);
413
414 /* run async method */
415 pk_task_search_details_async (task, filters, values, cancellable, progress_callback, progress_user_data,
416 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
417
418 g_main_loop_run (helper.loop);
419
420 results = helper.results;
421
422 g_main_context_pop_thread_default (helper.context);
423
424 /* free temp object */
425 g_main_loop_unref (helper.loop);
426 g_main_context_unref (helper.context);
427
428 return results;
429 }
430
431 /**
432 * pk_task_search_groups_sync:
433 * @task: a valid #PkTask instance
434 * @filters: a bitfield of filters that can be used to limit the results
435 * @values: (array zero-terminated=1): search values
436 * @cancellable: a #GCancellable or %NULL
437 * @progress_callback: (scope call): the function to run when the progress changes
438 * @progress_user_data: data to pass to @progress_callback
439 * @error: the #GError to store any failure, or %NULL
440 *
441 * Searches the group lists.
442 *
443 * Return value: (transfer full): a #PkResults object, or %NULL for error
444 *
445 * Since: 0.6.5
446 **/
447 PkResults *
448 pk_task_search_groups_sync (PkTask *task, PkBitfield filters, gchar **values, GCancellable *cancellable,
449 PkProgressCallback progress_callback, gpointer progress_user_data,
450 GError **error)
451 {
452 PkTaskHelper helper;
453 PkResults *results;
454
455 g_return_val_if_fail (PK_IS_TASK (task), NULL);
456 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
457
458 /* create temp object */
459 memset (&helper, 0, sizeof (PkTaskHelper));
460 helper.context = g_main_context_new ();
461 helper.loop = g_main_loop_new (helper.context, FALSE);
462 helper.error = error;
463
464 g_main_context_push_thread_default (helper.context);
465
466 /* run async method */
467 pk_task_search_groups_async (task, filters, values, cancellable, progress_callback, progress_user_data,
468 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
469
470 g_main_loop_run (helper.loop);
471
472 results = helper.results;
473
474 g_main_context_pop_thread_default (helper.context);
475
476 /* free temp object */
477 g_main_loop_unref (helper.loop);
478 g_main_context_unref (helper.context);
479
480 return results;
481 }
482
483 /**
484 * pk_task_search_files_sync:
485 * @task: a valid #PkTask instance
486 * @filters: a bitfield of filters that can be used to limit the results
487 * @values: (array zero-terminated=1): search values
488 * @cancellable: a #GCancellable or %NULL
489 * @progress_callback: (scope call): the function to run when the progress changes
490 * @progress_user_data: data to pass to @progress_callback
491 * @error: the #GError to store any failure, or %NULL
492 *
493 * Searches for specific files.
494 *
495 * Return value: (transfer full): a #PkResults object, or %NULL for error
496 *
497 * Since: 0.6.5
498 **/
499 PkResults *
500 pk_task_search_files_sync (PkTask *task, PkBitfield filters, gchar **values, GCancellable *cancellable,
501 PkProgressCallback progress_callback, gpointer progress_user_data,
502 GError **error)
503 {
504 PkTaskHelper helper;
505 PkResults *results;
506
507 g_return_val_if_fail (PK_IS_TASK (task), NULL);
508 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
509
510 /* create temp object */
511 memset (&helper, 0, sizeof (PkTaskHelper));
512 helper.context = g_main_context_new ();
513 helper.loop = g_main_loop_new (helper.context, FALSE);
514 helper.error = error;
515
516 g_main_context_push_thread_default (helper.context);
517
518 /* run async method */
519 pk_task_search_files_async (task, filters, values, cancellable, progress_callback, progress_user_data,
520 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
521
522 g_main_loop_run (helper.loop);
523
524 results = helper.results;
525
526 g_main_context_pop_thread_default (helper.context);
527
528 /* free temp object */
529 g_main_loop_unref (helper.loop);
530 g_main_context_unref (helper.context);
531
532 return results;
533 }
534
535 /**
536 * pk_task_get_details_sync:
537 * @task: a valid #PkTask instance
538 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
539 * @cancellable: a #GCancellable or %NULL
540 * @progress_callback: (scope call): the function to run when the progress changes
541 * @progress_user_data: data to pass to @progress_callback
542 * @error: the #GError to store any failure, or %NULL
543 *
544 * Gets details about packages.
545 *
546 * Return value: (transfer full): a #PkResults object, or %NULL for error
547 *
548 * Since: 0.6.5
549 **/
550 PkResults *
551 pk_task_get_details_sync (PkTask *task, gchar **package_ids, GCancellable *cancellable,
552 PkProgressCallback progress_callback, gpointer progress_user_data,
553 GError **error)
554 {
555 PkTaskHelper helper;
556 PkResults *results;
557
558 g_return_val_if_fail (PK_IS_TASK (task), NULL);
559 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
560
561 /* create temp object */
562 memset (&helper, 0, sizeof (PkTaskHelper));
563 helper.context = g_main_context_new ();
564 helper.loop = g_main_loop_new (helper.context, FALSE);
565 helper.error = error;
566
567 g_main_context_push_thread_default (helper.context);
568
569 /* run async method */
570 pk_task_get_details_async (task, package_ids, cancellable, progress_callback, progress_user_data,
571 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
572
573 g_main_loop_run (helper.loop);
574
575 results = helper.results;
576
577 g_main_context_pop_thread_default (helper.context);
578
579 /* free temp object */
580 g_main_loop_unref (helper.loop);
581 g_main_context_unref (helper.context);
582
583 return results;
584 }
585
586 /**
587 * pk_task_get_update_detail_sync:
588 * @task: a valid #PkTask instance
589 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
590 * @cancellable: a #GCancellable or %NULL
591 * @progress_callback: (scope call): the function to run when the progress changes
592 * @progress_user_data: data to pass to @progress_callback
593 * @error: the #GError to store any failure, or %NULL
594 *
595 * Gets details about updates.
596 *
597 * Return value: (transfer full): a #PkResults object, or %NULL for error
598 *
599 * Since: 0.6.5
600 **/
601 PkResults *
602 pk_task_get_update_detail_sync (PkTask *task, gchar **package_ids, GCancellable *cancellable,
603 PkProgressCallback progress_callback, gpointer progress_user_data,
604 GError **error)
605 {
606 PkTaskHelper helper;
607 PkResults *results;
608
609 g_return_val_if_fail (PK_IS_TASK (task), NULL);
610 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
611
612 /* create temp object */
613 memset (&helper, 0, sizeof (PkTaskHelper));
614 helper.context = g_main_context_new ();
615 helper.loop = g_main_loop_new (helper.context, FALSE);
616 helper.error = error;
617
618 g_main_context_push_thread_default (helper.context);
619
620 /* run async method */
621 pk_task_get_update_detail_async (task, package_ids, cancellable, progress_callback, progress_user_data,
622 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
623
624 g_main_loop_run (helper.loop);
625
626 results = helper.results;
627
628 g_main_context_pop_thread_default (helper.context);
629
630 /* free temp object */
631 g_main_loop_unref (helper.loop);
632 g_main_context_unref (helper.context);
633
634 return results;
635 }
636
637 /**
638 * pk_task_download_packages_sync:
639 * @task: a valid #PkTask instance
640 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
641 * @directory: the destination directory
642 * @cancellable: a #GCancellable or %NULL
643 * @progress_callback: (scope call): the function to run when the progress changes
644 * @progress_user_data: data to pass to @progress_callback
645 * @error: the #GError to store any failure, or %NULL
646 *
647 * Downloads packages
648 *
649 * Return value: (transfer full): a #PkResults object, or %NULL for error
650 *
651 * Since: 0.6.5
652 **/
653 PkResults *
654 pk_task_download_packages_sync (PkTask *task, gchar **package_ids, const gchar *directory, GCancellable *cancellable,
655 PkProgressCallback progress_callback, gpointer progress_user_data,
656 GError **error)
657 {
658 PkTaskHelper helper;
659 PkResults *results;
660
661 g_return_val_if_fail (PK_IS_TASK (task), NULL);
662 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
663
664 /* create temp object */
665 memset (&helper, 0, sizeof (PkTaskHelper));
666 helper.context = g_main_context_new ();
667 helper.loop = g_main_loop_new (helper.context, FALSE);
668 helper.error = error;
669
670 g_main_context_push_thread_default (helper.context);
671
672 /* run async method */
673 pk_task_download_packages_async (task, package_ids, directory, cancellable, progress_callback, progress_user_data,
674 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
675
676 g_main_loop_run (helper.loop);
677
678 results = helper.results;
679
680 g_main_context_pop_thread_default (helper.context);
681
682 /* free temp object */
683 g_main_loop_unref (helper.loop);
684 g_main_context_unref (helper.context);
685
686 return results;
687 }
688
689 /**
690 * pk_task_get_updates_sync:
691 * @task: a valid #PkTask instance
692 * @filters: a bitfield of filters that can be used to limit the results
693 * @cancellable: a #GCancellable or %NULL
694 * @progress_callback: (scope call): the function to run when the progress changes
695 * @progress_user_data: data to pass to @progress_callback
696 * @error: the #GError to store any failure, or %NULL
697 *
698 * Gets the update lists.
699 *
700 * Return value: (transfer full): a #PkResults object, or %NULL for error
701 *
702 * Since: 0.6.5
703 **/
704 PkResults *
705 pk_task_get_updates_sync (PkTask *task, PkBitfield filters, GCancellable *cancellable,
706 PkProgressCallback progress_callback, gpointer progress_user_data,
707 GError **error)
708 {
709 PkTaskHelper helper;
710 PkResults *results;
711
712 g_return_val_if_fail (PK_IS_TASK (task), NULL);
713 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
714
715 /* create temp object */
716 memset (&helper, 0, sizeof (PkTaskHelper));
717 helper.context = g_main_context_new ();
718 helper.loop = g_main_loop_new (helper.context, FALSE);
719 helper.error = error;
720
721 g_main_context_push_thread_default (helper.context);
722
723 /* run async method */
724 pk_task_get_updates_async (task, filters, cancellable, progress_callback, progress_user_data,
725 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
726
727 g_main_loop_run (helper.loop);
728
729 results = helper.results;
730
731 g_main_context_pop_thread_default (helper.context);
732
733 /* free temp object */
734 g_main_loop_unref (helper.loop);
735 g_main_context_unref (helper.context);
736
737 return results;
738 }
739
740 /**
741 * pk_task_depends_on_sync:
742 * @task: a valid #PkTask instance
743 * @filters: a bitfield of filters that can be used to limit the results
744 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
745 * @recursive: if we should recurse to packages that depend on other packages
746 * @cancellable: a #GCancellable or %NULL
747 * @progress_callback: (scope call): the function to run when the progress changes
748 * @progress_user_data: data to pass to @progress_callback
749 * @error: the #GError to store any failure, or %NULL
750 *
751 * Get the list of dependent packages.
752 *
753 * Return value: (transfer full): a #PkResults object, or %NULL for error
754 *
755 * Since: 0.6.5
756 **/
757 PkResults *
758 pk_task_depends_on_sync (PkTask *task, PkBitfield filters, gchar **package_ids, gboolean recursive, GCancellable *cancellable,
759 PkProgressCallback progress_callback, gpointer progress_user_data,
760 GError **error)
761 {
762 PkTaskHelper helper;
763 PkResults *results;
764
765 g_return_val_if_fail (PK_IS_TASK (task), NULL);
766 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
767
768 /* create temp object */
769 memset (&helper, 0, sizeof (PkTaskHelper));
770 helper.context = g_main_context_new ();
771 helper.loop = g_main_loop_new (helper.context, FALSE);
772 helper.error = error;
773
774 g_main_context_push_thread_default (helper.context);
775
776 /* run async method */
777 pk_task_depends_on_async (task, filters, package_ids, recursive, cancellable, progress_callback, progress_user_data,
778 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
779
780 g_main_loop_run (helper.loop);
781
782 results = helper.results;
783
784 g_main_context_pop_thread_default (helper.context);
785
786 /* free temp object */
787 g_main_loop_unref (helper.loop);
788 g_main_context_unref (helper.context);
789
790 return results;
791 }
792
793 /**
794 * pk_task_get_packages_sync:
795 * @task: a valid #PkTask instance
796 * @filters: a bitfield of filters that can be used to limit the results
797 * @cancellable: a #GCancellable or %NULL
798 * @progress_callback: (scope call): the function to run when the progress changes
799 * @progress_user_data: data to pass to @progress_callback
800 * @error: the #GError to store any failure, or %NULL
801 *
802 * Gets the list of packages.
803 *
804 * Return value: (transfer full): a #PkResults object, or %NULL for error
805 *
806 * Since: 0.6.5
807 **/
808 PkResults *
809 pk_task_get_packages_sync (PkTask *task, PkBitfield filters, GCancellable *cancellable,
810 PkProgressCallback progress_callback, gpointer progress_user_data,
811 GError **error)
812 {
813 PkTaskHelper helper;
814 PkResults *results;
815
816 g_return_val_if_fail (PK_IS_TASK (task), NULL);
817 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
818
819 /* create temp object */
820 memset (&helper, 0, sizeof (PkTaskHelper));
821 helper.context = g_main_context_new ();
822 helper.loop = g_main_loop_new (helper.context, FALSE);
823 helper.error = error;
824
825 g_main_context_push_thread_default (helper.context);
826
827 /* run async method */
828 pk_task_get_packages_async (task, filters, cancellable, progress_callback, progress_user_data,
829 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
830
831 g_main_loop_run (helper.loop);
832
833 results = helper.results;
834
835 g_main_context_pop_thread_default (helper.context);
836
837 /* free temp object */
838 g_main_loop_unref (helper.loop);
839 g_main_context_unref (helper.context);
840
841 return results;
842 }
843
844 /**
845 * pk_task_required_by_sync:
846 * @task: a valid #PkTask instance
847 * @filters: a bitfield of filters that can be used to limit the results
848 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
849 * @recursive: if we should return packages that depend on the ones we do
850 * @cancellable: a #GCancellable or %NULL
851 * @progress_callback: (scope call): the function to run when the progress changes
852 * @progress_user_data: data to pass to @progress_callback
853 * @error: the #GError to store any failure, or %NULL
854 *
855 * Get the packages this package requires.
856 *
857 * Return value: (transfer full): a #PkResults object, or %NULL for error
858 *
859 * Since: 0.6.5
860 **/
861 PkResults *
862 pk_task_required_by_sync (PkTask *task, PkBitfield filters, gchar **package_ids, gboolean recursive, GCancellable *cancellable,
863 PkProgressCallback progress_callback, gpointer progress_user_data,
864 GError **error)
865 {
866 PkTaskHelper helper;
867 PkResults *results;
868
869 g_return_val_if_fail (PK_IS_TASK (task), NULL);
870 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
871
872 /* create temp object */
873 memset (&helper, 0, sizeof (PkTaskHelper));
874 helper.context = g_main_context_new ();
875 helper.loop = g_main_loop_new (helper.context, FALSE);
876 helper.error = error;
877
878 g_main_context_push_thread_default (helper.context);
879
880 /* run async method */
881 pk_task_required_by_async (task, filters, package_ids, recursive, cancellable, progress_callback, progress_user_data,
882 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
883
884 g_main_loop_run (helper.loop);
885
886 results = helper.results;
887
888 g_main_context_pop_thread_default (helper.context);
889
890 /* free temp object */
891 g_main_loop_unref (helper.loop);
892 g_main_context_unref (helper.context);
893
894 return results;
895 }
896
897 /**
898 * pk_task_what_provides_sync:
899 * @task: a valid #PkTask instance
900 * @filters: a bitfield of filters that can be used to limit the results
901 * @values: (array zero-terminated=1): values to search for
902 * @cancellable: a #GCancellable or %NULL
903 * @progress_callback: (scope call): the function to run when the progress changes
904 * @progress_user_data: data to pass to @progress_callback
905 * @error: the #GError to store any failure, or %NULL
906 *
907 * Find the package that provides some resource.
908 *
909 * Return value: (transfer full): a #PkResults object, or %NULL for error
910 *
911 * Since: 0.6.5
912 **/
913 PkResults *
914 pk_task_what_provides_sync (PkTask *task, PkBitfield filters,
915 gchar **values, GCancellable *cancellable,
916 PkProgressCallback progress_callback, gpointer progress_user_data,
917 GError **error)
918 {
919 PkTaskHelper helper;
920 PkResults *results;
921
922 g_return_val_if_fail (PK_IS_TASK (task), NULL);
923 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
924
925 /* create temp object */
926 memset (&helper, 0, sizeof (PkTaskHelper));
927 helper.context = g_main_context_new ();
928 helper.loop = g_main_loop_new (helper.context, FALSE);
929 helper.error = error;
930
931 g_main_context_push_thread_default (helper.context);
932
933 /* run async method */
934 pk_task_what_provides_async (task, filters, values, cancellable, progress_callback, progress_user_data,
935 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
936
937 g_main_loop_run (helper.loop);
938
939 results = helper.results;
940
941 g_main_context_pop_thread_default (helper.context);
942
943 /* free temp object */
944 g_main_loop_unref (helper.loop);
945 g_main_context_unref (helper.context);
946
947 return results;
948 }
949
950 /**
951 * pk_task_get_files_sync:
952 * @task: a valid #PkTask instance
953 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
954 * @cancellable: a #GCancellable or %NULL
955 * @progress_callback: (scope call): the function to run when the progress changes
956 * @progress_user_data: data to pass to @progress_callback
957 * @error: the #GError to store any failure, or %NULL
958 *
959 * Get the files in a package.
960 *
961 * Return value: (transfer full): a #PkResults object, or %NULL for error
962 *
963 * Since: 0.6.5
964 **/
965 PkResults *
966 pk_task_get_files_sync (PkTask *task, gchar **package_ids, GCancellable *cancellable,
967 PkProgressCallback progress_callback, gpointer progress_user_data,
968 GError **error)
969 {
970 PkTaskHelper helper;
971 PkResults *results;
972
973 g_return_val_if_fail (PK_IS_TASK (task), NULL);
974 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
975
976 /* create temp object */
977 memset (&helper, 0, sizeof (PkTaskHelper));
978 helper.context = g_main_context_new ();
979 helper.loop = g_main_loop_new (helper.context, FALSE);
980 helper.error = error;
981
982 g_main_context_push_thread_default (helper.context);
983
984 /* run async method */
985 pk_task_get_files_async (task, package_ids, cancellable, progress_callback, progress_user_data,
986 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
987
988 g_main_loop_run (helper.loop);
989
990 results = helper.results;
991
992 g_main_context_pop_thread_default (helper.context);
993
994 /* free temp object */
995 g_main_loop_unref (helper.loop);
996 g_main_context_unref (helper.context);
997
998 return results;
999 }
1000
1001 /**
1002 * pk_task_get_categories_sync:
1003 * @task: a valid #PkTask instance
1004 * @cancellable: a #GCancellable or %NULL
1005 * @progress_callback: (scope call): the function to run when the progress changes
1006 * @progress_user_data: data to pass to @progress_callback
1007 * @error: the #GError to store any failure, or %NULL
1008 *
1009 * Get the categories available.
1010 *
1011 * Return value: (transfer full): a #PkResults object, or %NULL for error
1012 *
1013 * Since: 0.6.5
1014 **/
1015 PkResults *
1016 pk_task_get_categories_sync (PkTask *task, GCancellable *cancellable,
1017 PkProgressCallback progress_callback, gpointer progress_user_data,
1018 GError **error)
1019 {
1020 PkTaskHelper helper;
1021 PkResults *results;
1022
1023 g_return_val_if_fail (PK_IS_TASK (task), NULL);
1024 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1025
1026 /* create temp object */
1027 memset (&helper, 0, sizeof (PkTaskHelper));
1028 helper.context = g_main_context_new ();
1029 helper.loop = g_main_loop_new (helper.context, FALSE);
1030 helper.error = error;
1031
1032 g_main_context_push_thread_default (helper.context);
1033
1034 /* run async method */
1035 pk_task_get_categories_async (task, cancellable, progress_callback, progress_user_data,
1036 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
1037
1038 g_main_loop_run (helper.loop);
1039
1040 results = helper.results;
1041
1042 g_main_context_pop_thread_default (helper.context);
1043
1044 /* free temp object */
1045 g_main_loop_unref (helper.loop);
1046 g_main_context_unref (helper.context);
1047
1048 return results;
1049 }
1050
1051 /**
1052 * pk_task_refresh_cache_sync:
1053 * @task: a valid #PkTask instance
1054 * @force: if the metadata should be deleted and re-downloaded even if it is correct
1055 * @cancellable: a #GCancellable or %NULL
1056 * @progress_callback: (scope call): the function to run when the progress changes
1057 * @progress_user_data: data to pass to @progress_callback
1058 * @error: the #GError to store any failure, or %NULL
1059 *
1060 * Refresh the package cache.
1061 *
1062 * Return value: (transfer full): a #PkResults object, or %NULL for error
1063 *
1064 * Since: 0.6.5
1065 **/
1066 PkResults *
1067 pk_task_refresh_cache_sync (PkTask *task, gboolean force, GCancellable *cancellable,
1068 PkProgressCallback progress_callback, gpointer progress_user_data,
1069 GError **error)
1070 {
1071 PkTaskHelper helper;
1072 PkResults *results;
1073
1074 g_return_val_if_fail (PK_IS_TASK (task), NULL);
1075 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1076
1077 /* create temp object */
1078 memset (&helper, 0, sizeof (PkTaskHelper));
1079 helper.context = g_main_context_new ();
1080 helper.loop = g_main_loop_new (helper.context, FALSE);
1081 helper.error = error;
1082
1083 g_main_context_push_thread_default (helper.context);
1084
1085 /* run async method */
1086 pk_task_refresh_cache_async (task, force, cancellable, progress_callback, progress_user_data,
1087 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
1088
1089 g_main_loop_run (helper.loop);
1090
1091 results = helper.results;
1092
1093 g_main_context_pop_thread_default (helper.context);
1094
1095 /* free temp object */
1096 g_main_loop_unref (helper.loop);
1097 g_main_context_unref (helper.context);
1098
1099 return results;
1100 }
1101
1102 /**
1103 * pk_task_get_repo_list_sync:
1104 * @task: a valid #PkTask instance
1105 * @filters: a bitfield of filters that can be used to limit the results
1106 * @cancellable: a #GCancellable or %NULL
1107 * @progress_callback: (scope call): the function to run when the progress changes
1108 * @progress_user_data: data to pass to @progress_callback
1109 * @error: the #GError to store any failure, or %NULL
1110 *
1111 * Get the list of available repositories.
1112 *
1113 * Return value: (transfer full): a #PkResults object, or %NULL for error
1114 *
1115 * Since: 0.6.5
1116 **/
1117 PkResults *
1118 pk_task_get_repo_list_sync (PkTask *task, PkBitfield filters, GCancellable *cancellable,
1119 PkProgressCallback progress_callback, gpointer progress_user_data,
1120 GError **error)
1121 {
1122 PkTaskHelper helper;
1123 PkResults *results;
1124
1125 g_return_val_if_fail (PK_IS_TASK (task), NULL);
1126 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1127
1128 /* create temp object */
1129 memset (&helper, 0, sizeof (PkTaskHelper));
1130 helper.context = g_main_context_new ();
1131 helper.loop = g_main_loop_new (helper.context, FALSE);
1132 helper.error = error;
1133
1134 g_main_context_push_thread_default (helper.context);
1135
1136 /* run async method */
1137 pk_task_get_repo_list_async (task, filters, cancellable, progress_callback, progress_user_data,
1138 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
1139
1140 g_main_loop_run (helper.loop);
1141
1142 results = helper.results;
1143
1144 g_main_context_pop_thread_default (helper.context);
1145
1146 /* free temp object */
1147 g_main_loop_unref (helper.loop);
1148 g_main_context_unref (helper.context);
1149
1150 return results;
1151 }
1152
1153 /**
1154 * pk_task_repo_enable_sync:
1155 * @task: a valid #PkTask instance
1156 * @repo_id: The software repository ID
1157 * @enabled: %TRUE or %FALSE
1158 * @cancellable: a #GCancellable or %NULL
1159 * @progress_callback: (scope call): the function to run when the progress changes
1160 * @progress_user_data: data to pass to @progress_callback
1161 * @error: the #GError to store any failure, or %NULL
1162 *
1163 * Enable or disable a specific repo.
1164 *
1165 * Return value: (transfer full): a #PkResults object, or %NULL for error
1166 *
1167 * Since: 0.6.5
1168 **/
1169 PkResults *
1170 pk_task_repo_enable_sync (PkTask *task, const gchar *repo_id, gboolean enabled, GCancellable *cancellable,
1171 PkProgressCallback progress_callback, gpointer progress_user_data,
1172 GError **error)
1173 {
1174 PkTaskHelper helper;
1175 PkResults *results;
1176
1177 g_return_val_if_fail (PK_IS_TASK (task), NULL);
1178 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1179
1180 /* create temp object */
1181 memset (&helper, 0, sizeof (PkTaskHelper));
1182 helper.context = g_main_context_new ();
1183 helper.loop = g_main_loop_new (helper.context, FALSE);
1184 helper.error = error;
1185
1186 g_main_context_push_thread_default (helper.context);
1187
1188 /* run async method */
1189 pk_task_repo_enable_async (task, repo_id, enabled, cancellable, progress_callback, progress_user_data,
1190 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
1191
1192 g_main_loop_run (helper.loop);
1193
1194 results = helper.results;
1195
1196 g_main_context_pop_thread_default (helper.context);
1197
1198 /* free temp object */
1199 g_main_loop_unref (helper.loop);
1200 g_main_context_unref (helper.context);
1201
1202 return results;
1203 }
1204
1205 /**
1206 * pk_task_upgrade_system_sync:
1207 * @task: a valid #PkTask instance
1208 * @distro_id: a distro ID such as "fedora-14"
1209 * @upgrade_kind: a #PkUpgradeKindEnum such as %PK_UPGRADE_KIND_ENUM_COMPLETE
1210 * @cancellable: a #GCancellable or %NULL
1211 * @progress_callback: (scope call): the function to run when the progress changes
1212 * @progress_user_data: data to pass to @progress_callback
1213 * @error: the #GError to store any failure, or %NULL
1214 *
1215 * This transaction will update the distro to the next version, which may
1216 * involve just downloading the installer and setting up the boot device,
1217 * or may involve doing an on-line upgrade.
1218 *
1219 * The backend will decide what is best to do.
1220 *
1221 * Return value: (transfer full): a #PkResults object, or %NULL for error
1222 *
1223 * Since: 1.0.12
1224 **/
1225 PkResults *
1226 pk_task_upgrade_system_sync (PkTask *task,
1227 const gchar *distro_id,
1228 PkUpgradeKindEnum upgrade_kind,
1229 GCancellable *cancellable,
1230 PkProgressCallback progress_callback, gpointer progress_user_data, GError **error)
1231 {
1232 PkTaskHelper helper;
1233 PkResults *results;
1234
1235 g_return_val_if_fail (PK_IS_TASK (task), NULL);
1236 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1237
1238 /* create temp object */
1239 memset (&helper, 0, sizeof (PkTaskHelper));
1240 helper.context = g_main_context_new ();
1241 helper.loop = g_main_loop_new (helper.context, FALSE);
1242 helper.error = error;
1243
1244 g_main_context_push_thread_default (helper.context);
1245
1246 /* run async method */
1247 pk_task_upgrade_system_async (task, distro_id, upgrade_kind, cancellable, progress_callback, progress_user_data,
1248 (GAsyncReadyCallback) pk_task_generic_finish_sync, &helper);
1249
1250 g_main_loop_run (helper.loop);
1251
1252 results = helper.results;
1253
1254 g_main_context_pop_thread_default (helper.context);
1255
1256 /* free temp object */
1257 g_main_loop_unref (helper.loop);
1258 g_main_context_unref (helper.context);
1259
1260 return results;
1261 }
1262
1263 /**
1264 * pk_task_repair_system_sync:
1265 * @task: a valid #PkTask instance
1266 * @cancellable: a #GCancellable or %NULL
1267 * @progress_callback: (scope call): the function to run when the progress changes
1268 * @progress_user_data: data to pass to @progress_callback
1269 * @error: the #GError to store any failure, or %NULL
1270 *
1271 * Recover from broken dependencies of installed packages or incomplete
1272 * installations.
1273 *
1274 * Warning: this function is synchronous, and may block. Do not use it in GUI
1275 * applications.
1276 *
1277 * Return value: (transfer full): a #PkResults object, or %NULL for error
1278 *
1279 * Since: 0.7.2
1280 **/
1281 PkResults *
1282 pk_task_repair_system_sync (PkTask *task, GCancellable *cancellable,
1283 PkProgressCallback progress_callback, gpointer progress_user_data,
1284 GError **error)
1285 {
1286 PkTaskHelper helper;
1287 PkResults *results;
1288
1289 g_return_val_if_fail (PK_IS_TASK (task), NULL);
1290 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1291
1292 /* create temp object */
1293 memset (&helper, 0, sizeof (PkTaskHelper));
1294 helper.context = g_main_context_new ();
1295 helper.loop = g_main_loop_new (helper.context, FALSE);
1296 helper.error = error;
1297
1298 g_main_context_push_thread_default (helper.context);
1299
1300 /* run async method */
1301 pk_task_repair_system_async (task, cancellable, progress_callback, progress_user_data,
1302 (GAsyncReadyCallback) pk_task_generic_finish_sync,
1303 &helper);
1304
1305 g_main_loop_run (helper.loop);
1306
1307 results = helper.results;
1308
1309 g_main_context_pop_thread_default (helper.context);
1310
1311 /* free temp object */
1312 g_main_loop_unref (helper.loop);
1313 g_main_context_unref (helper.context);
1314
1315 return results;
1316 }