After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 779313 - Query for number of jobs asynchronously
Query for number of jobs asynchronously
Status: RESOLVED FIXED
Product: gnome-control-center
Classification: Core
Component: Printers
git master
Other Linux
: Normal normal
: ---
Assigned To: Marek Kašík
Control-Center Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-02-27 14:44 UTC by Felipe Borges
Modified: 2017-03-06 15:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
printers: Query for the number of jobs asynchronously (1.84 KB, patch)
2017-02-27 14:44 UTC, Felipe Borges
needs-work Details | Review
printers: Introduce pp_printer_get_jobs_async () (7.25 KB, patch)
2017-02-28 15:22 UTC, Felipe Borges
none Details | Review
printers: Port PpJobsDialog to pp_printer_get_jobs_async (3.83 KB, patch)
2017-02-28 15:22 UTC, Felipe Borges
none Details | Review
printers: Drop cups_get_jobs_async (3.99 KB, patch)
2017-02-28 15:22 UTC, Felipe Borges
none Details | Review
printers: Introduce pp_printer_get_jobs_async () (8.31 KB, patch)
2017-03-02 12:45 UTC, Felipe Borges
none Details | Review
printers: Port PpJobsDialog to pp_printer_get_jobs_async (3.83 KB, patch)
2017-03-02 12:45 UTC, Felipe Borges
none Details | Review
printers: Properly free pp_jobs_dialog (2.58 KB, patch)
2017-03-02 12:45 UTC, Felipe Borges
none Details | Review
printers: Drop cups_get_jobs_async (4.18 KB, patch)
2017-03-02 12:45 UTC, Felipe Borges
none Details | Review
printers: Introduce pp_printer_get_jobs_async () (8.17 KB, patch)
2017-03-02 12:49 UTC, Felipe Borges
none Details | Review
printers: Port PpJobsDialog to pp_printer_get_jobs_async (3.83 KB, patch)
2017-03-02 12:49 UTC, Felipe Borges
none Details | Review
printers: Properly free pp_jobs_dialog (2.58 KB, patch)
2017-03-02 12:49 UTC, Felipe Borges
committed Details | Review
printers: Drop cups_get_jobs_async (4.18 KB, patch)
2017-03-02 12:50 UTC, Felipe Borges
committed Details | Review
printers: Introduce pp_printer_get_jobs_async () (8.14 KB, patch)
2017-03-02 14:48 UTC, Felipe Borges
none Details | Review
printers: Port PpJobsDialog to pp_printer_get_jobs_async (3.83 KB, patch)
2017-03-02 14:48 UTC, Felipe Borges
none Details | Review
printers: Introduce pp_printer_get_jobs_async () (8.30 KB, patch)
2017-03-02 15:07 UTC, Felipe Borges
none Details | Review
printers: Port PpJobsDialog to pp_printer_get_jobs_async (3.95 KB, patch)
2017-03-02 15:07 UTC, Felipe Borges
none Details | Review
printers: Introduce pp_printer_get_jobs_async () (8.47 KB, patch)
2017-03-06 12:45 UTC, Felipe Borges
committed Details | Review
printers: Port PpJobsDialog to pp_printer_get_jobs_async (4.14 KB, patch)
2017-03-06 12:46 UTC, Felipe Borges
committed Details | Review

Description Felipe Borges 2017-02-27 14:44:16 UTC
Instead of cupsGetJobs ()
Comment 1 Felipe Borges 2017-02-27 14:44:38 UTC
Created attachment 346824 [details] [review]
printers: Query for the number of jobs asynchronously
Comment 2 Marek Kašík 2017-02-27 17:08:06 UTC
Review of attachment 346824 [details] [review]:

Looking at the cups_get_jobs_async() it seems that we should replace it by proper implementation in PpPrinter class. Something like pp_printer_get_jobs_async() and pp_printer_get_jobs_finish() with correct usage of GCancellable.
Try insert g_usleep(3000000) into the cups_get_jobs_func(), run printers panel and go quickly to overview. Something bad happens. This wouldn't happen if we would know that the PpPrinterEntry doesn't exist already.
Comment 3 Felipe Borges 2017-02-28 15:22:16 UTC
Created attachment 346908 [details] [review]
printers: Introduce pp_printer_get_jobs_async ()

It is a PpPrinter method to query asychronously for printing jobs
information.

It should replace cups_get_jobs_async ()
Comment 4 Felipe Borges 2017-02-28 15:22:22 UTC
Created attachment 346909 [details] [review]
printers: Port PpJobsDialog to pp_printer_get_jobs_async
Comment 5 Felipe Borges 2017-02-28 15:22:29 UTC
Created attachment 346910 [details] [review]
printers: Drop cups_get_jobs_async

pp_printer_get_jobs_async does the job with more modern GLib API
(GTask).
Comment 6 Marek Kašík 2017-03-01 16:43:28 UTC
Review of attachment 346908 [details] [review]:

Thank you for the patch. I have several comments on it.

::: panels/printers/pp-printer-entry.c
@@ +404,3 @@
   gint   num_jobs, num_of_jobs;
 
+  jobs = pp_printer_get_jobs_finish (printer, result, NULL);

Use an error here to check whether it was cancelled.
Free the list later.
Unref the source_object.

@@ +409,1 @@
   num_jobs = num_of_jobs < 0 ? 0 : (guint) num_of_jobs;

g_list_length returns guint so you can use directly that.

@@ +431,3 @@
+
+  g_object_unref (self->get_jobs_cancellable);
+  self->get_jobs_cancellable = NULL;

Use g_clear_object() here.

@@ +447,3 @@
+                             self->get_jobs_cancellable,
+                             get_jobs_cb,
+                             g_object_ref (self));

Don't ref the entry please, use error returned by the _finish() method to check whether the call was cancelled.

::: panels/printers/pp-printer.c
@@ +298,3 @@
+{
+  g_slice_free (GetJobsData, get_jobs_data);
+}

If you use g_new() for allocation then you can use g_free() instead of the new function.

@@ +313,3 @@
+  gint         num_jobs;
+
+  g_object_get (printer, "printer-name", &printer_name, NULL);

You are leaking the printer_name.

@@ +320,3 @@
+                          get_jobs_data->which_jobs);
+
+  while (num_jobs > 0)

This would work but use for() loop here please.

@@ +324,3 @@
+      num_jobs--;
+
+      list = g_list_append (list, &jobs[num_jobs]);

Lets create PpJob for every such job so the result is usable by other callers.

@@ +326,3 @@
+      list = g_list_append (list, &jobs[num_jobs]);
+    }
+  cupsFreeJobs (num_jobs, jobs);

This would make the result unusable but if you return GList of PpJob then it can stay here.
Comment 7 Marek Kašík 2017-03-01 16:45:27 UTC
Review of attachment 346909 [details] [review]:

Thank you for this patch. It needs some work yet.

::: panels/printers/pp-jobs-dialog.c
@@ +63,1 @@
   gint ref_count;

Since we already have proper async implementation of getting of jobs, please remove the ref_count variable and merge pp_jobs_dialog_free_idle() into pp_jobs_dialog_free() please.

@@ +176,3 @@
   stack = GTK_STACK (gtk_builder_get_object (GTK_BUILDER (dialog->builder), "stack"));
   clear_all_button = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (dialog->builder), "jobs-clear-all-button"));
 

Check whether the call was cancelled before using any pointer outside of PpPrinter here (via the error) that was original intent for the rewrite.

@@ +204,3 @@
 
+  g_object_unref (dialog->get_jobs_cancellable);
+  dialog->get_jobs_cancellable = NULL;

You can use g_clear_object() here.
Comment 8 Marek Kašík 2017-03-01 16:46:43 UTC
Review of attachment 346910 [details] [review]:

We can remove the CGJCallback now.

::: panels/printers/pp-utils.h
@@ +246,2 @@
                              gint        num_of_jobs,
                              gpointer    user_data);

Remove also the CGJCallback please.
Comment 9 Felipe Borges 2017-03-02 12:45:33 UTC
Created attachment 347055 [details] [review]
printers: Introduce pp_printer_get_jobs_async ()

It is a PpPrinter method to query asychronously for printing jobs
information.

It should replace cups_get_jobs_async ()
Comment 10 Felipe Borges 2017-03-02 12:45:39 UTC
Created attachment 347056 [details] [review]
printers: Port PpJobsDialog to pp_printer_get_jobs_async
Comment 11 Felipe Borges 2017-03-02 12:45:45 UTC
Created attachment 347057 [details] [review]
printers: Properly free pp_jobs_dialog

Since now we have proper async implementation for getting jobs, we
do not need to increment/decrement the objects ref_count manually.
Comment 12 Felipe Borges 2017-03-02 12:45:51 UTC
Created attachment 347058 [details] [review]
printers: Drop cups_get_jobs_async

pp_printer_get_jobs_async does the job with more modern GLib API
(GTask).
Comment 13 Felipe Borges 2017-03-02 12:49:44 UTC
Created attachment 347059 [details] [review]
printers: Introduce pp_printer_get_jobs_async ()

It is a PpPrinter method to query asychronously for printing jobs
information.

It should replace cups_get_jobs_async ()
Comment 14 Felipe Borges 2017-03-02 12:49:50 UTC
Created attachment 347060 [details] [review]
printers: Port PpJobsDialog to pp_printer_get_jobs_async
Comment 15 Felipe Borges 2017-03-02 12:49:56 UTC
Created attachment 347061 [details] [review]
printers: Properly free pp_jobs_dialog

Since now we have proper async implementation for getting jobs, we
do not need to increment/decrement the objects ref_count manually.
Comment 16 Felipe Borges 2017-03-02 12:50:01 UTC
Created attachment 347062 [details] [review]
printers: Drop cups_get_jobs_async

pp_printer_get_jobs_async does the job with more modern GLib API
(GTask).
Comment 17 Marek Kašík 2017-03-02 14:40:48 UTC
Review of attachment 347059 [details] [review]:

This need just 2 small changes yet.

::: panels/printers/pp-printer-entry.c
@@ +410,2 @@
+  g_object_unref (source_object);
+  g_list_free (jobs);

You haven't freed the jobs (use g_list_free_full() for that).

@@ +413,3 @@
+  if (error != NULL)
+    {
+      g_warning ("Could not get jobs: %s\n", error->message);

Don't show this when the operation was cancelled (I see a lot of these when I just open the panel).
Comment 18 Marek Kašík 2017-03-02 14:42:31 UTC
Review of attachment 347060 [details] [review]:

This one too.

::: panels/printers/pp-jobs-dialog.c
@@ +181,3 @@
+  if (error != NULL)
+    {
+      g_message ("Could not get jobs: %s\n", error->message);

Don't show this message when the operation was cancelled and maybe g_warning() would be better here.

@@ +203,1 @@
     }

You can g_list_free() the list here.
Comment 19 Marek Kašík 2017-03-02 14:43:05 UTC
Review of attachment 347061 [details] [review]:

This one looks good to me. Push it once we have all ready.
Comment 20 Marek Kašík 2017-03-02 14:43:33 UTC
Review of attachment 347062 [details] [review]:

Thank you for the change. Push it once we have all patches ready.
Comment 21 Felipe Borges 2017-03-02 14:48:00 UTC
Created attachment 347072 [details] [review]
printers: Introduce pp_printer_get_jobs_async ()

It is a PpPrinter method to query asychronously for printing jobs
information.

It should replace cups_get_jobs_async ()
Comment 22 Felipe Borges 2017-03-02 14:48:06 UTC
Created attachment 347073 [details] [review]
printers: Port PpJobsDialog to pp_printer_get_jobs_async
Comment 23 Felipe Borges 2017-03-02 15:07:20 UTC
Created attachment 347074 [details] [review]
printers: Introduce pp_printer_get_jobs_async ()

It is a PpPrinter method to query asychronously for printing jobs
information.

It should replace cups_get_jobs_async ()
Comment 24 Felipe Borges 2017-03-02 15:07:31 UTC
Created attachment 347075 [details] [review]
printers: Port PpJobsDialog to pp_printer_get_jobs_async
Comment 25 Marek Kašík 2017-03-03 14:13:57 UTC
Review of attachment 347075 [details] [review]:

I'm sorry but we need one more change. When I was testing the patch I've got a crash. It was caused by not cancelled cancellable. We need to cancel the cancellable if there is any if we are updating the dialog too soon.

::: panels/printers/pp-jobs-dialog.c
@@ +222,3 @@
       dialog->ref_count++;
+
+      dialog->get_jobs_cancellable = g_cancellable_new ();

You have to cancel the cancellable if it is there (and free) before this.
Comment 26 Marek Kašík 2017-03-03 14:14:44 UTC
Review of attachment 347074 [details] [review]:

Lets do the same in this patch.

::: panels/printers/pp-printer-entry.c
@@ +453,3 @@
+  PpPrinter *printer;
+
+  self->get_jobs_cancellable = g_cancellable_new ();

You have to cancel (and free) the cancellable if it is there before this.
Comment 27 Felipe Borges 2017-03-06 12:45:54 UTC
Created attachment 347309 [details] [review]
printers: Introduce pp_printer_get_jobs_async ()

It is a PpPrinter method to query asychronously for printing jobs
information.

It should replace cups_get_jobs_async ()
Comment 28 Felipe Borges 2017-03-06 12:46:05 UTC
Created attachment 347310 [details] [review]
printers: Port PpJobsDialog to pp_printer_get_jobs_async
Comment 29 Marek Kašík 2017-03-06 13:16:38 UTC
Review of attachment 347309 [details] [review]:

Thank you for the change and all the patches. Push it to master please.
Comment 30 Marek Kašík 2017-03-06 13:17:02 UTC
Review of attachment 347310 [details] [review]:

This one too.
Comment 31 Felipe Borges 2017-03-06 15:09:12 UTC
thanks!

Attachment 347061 [details] pushed as 2ad93bc - printers: Properly free pp_jobs_dialog
Attachment 347062 [details] pushed as 1df4da5 - printers: Drop cups_get_jobs_async
Attachment 347309 [details] pushed as 1d0ae49 - printers: Introduce pp_printer_get_jobs_async ()
Attachment 347310 [details] pushed as c40772a - printers: Port PpJobsDialog to pp_printer_get_jobs_async