]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
The scheduler now returns completed jobs in the correct newest-to-oldest order
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Wed, 30 Jul 2014 18:30:44 +0000 (18:30 +0000)
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Wed, 30 Jul 2014 18:30:44 +0000 (18:30 +0000)
(STR #4396)

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@12066 a1ca3aef-8c08-0410-bb20-df032aa958be

CHANGES.txt
scheduler/ipp.c
scheduler/job.c
scheduler/job.h
systemv/lpstat.c
test/5.5-lp.sh

index 577c6c776e10168c9f195ac3c966002bbdbc5415..529cc4e455ea78cea6e40f8fd282c4ab8a57681e 100644 (file)
@@ -1,4 +1,4 @@
-CHANGES.txt - 2.0b1 - 2014-06-12
+CHANGES.txt - 2.0b1 - 2014-07-30
 --------------------------------
 
 CHANGES IN CUPS V2.0b1
@@ -13,6 +13,8 @@ CHANGES IN CUPS V2.0b1
          scheduler (STR #4321)
        - CUPS TLS support now supports certificate validation and policy
          enforcement (STR #1616)
+       - The scheduler now returns completed jobs in the correct newest-to-
+         oldest order (STR #4396)
        - The configure script now supports target-specific tools for pkg-config
          and others (STR #4423)
        - The ipptool program now supports EXPECT statements for collection
index 0a99ec9fc216995741d1a313d37ece69145a4d73..563d296ab3b59223f350b3c838768b6c09be2d9b 100644 (file)
@@ -6108,6 +6108,7 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
   cupsd_job_t  *job;                   /* Current job pointer */
   cupsd_printer_t *printer;            /* Printer */
   cups_array_t *list;                  /* Which job list... */
+  int          delete_list = 0;        /* Delete the list afterwards? */
   cups_array_t *ra,                    /* Requested attributes array */
                *exclude;               /* Private attributes array */
   cupsd_policy_t *policy;              /* Current policy */
@@ -6207,13 +6208,15 @@ get_jobs(cupsd_client_t  *con,          /* I - Client connection */
   {
     job_comparison = 1;
     job_state      = IPP_JOB_CANCELED;
-    list           = Jobs;
+    list           = cupsdGetCompletedJobs(printer);
+    delete_list    = 1;
   }
   else if (!strcmp(attr->values[0].string.text, "aborted"))
   {
     job_comparison = 0;
     job_state      = IPP_JOB_ABORTED;
-    list           = Jobs;
+    list           = cupsdGetCompletedJobs(printer);
+    delete_list    = 1;
   }
   else if (!strcmp(attr->values[0].string.text, "all"))
   {
@@ -6225,7 +6228,8 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
   {
     job_comparison = 0;
     job_state      = IPP_JOB_CANCELED;
-    list           = Jobs;
+    list           = cupsdGetCompletedJobs(printer);
+    delete_list    = 1;
   }
   else if (!strcmp(attr->values[0].string.text, "pending"))
   {
@@ -6427,6 +6431,9 @@ get_jobs(cupsd_client_t  *con,            /* I - Client connection */
 
   cupsArrayDelete(ra);
 
+  if (delete_list)
+    cupsArrayDelete(list);
+
   con->response->request.status.status_code = IPP_OK;
 }
 
index 610d4e0245ed82fa519589fbad4f741e611d654f..0d9aafbc1396987fca97adfbe7c2c6cc2c69eb6b 100644 (file)
@@ -119,6 +119,7 @@ static mime_filter_t        gziptoany_filter =
  */
 
 static int     compare_active_jobs(void *first, void *second, void *data);
+static int     compare_completed_jobs(void *first, void *second, void *data);
 static int     compare_jobs(void *first, void *second, void *data);
 static void    dump_job_history(cupsd_job_t *job);
 static void    finalize_job(cupsd_job_t *job, int set_job_state);
@@ -1455,6 +1456,30 @@ cupsdFindJob(int id)                     /* I - Job ID */
 }
 
 
+/*
+ * 'cupsdGetCompletedJobs()'- Generate a completed jobs list.
+ */
+
+cups_array_t *                         /* O - Array of jobs */
+cupsdGetCompletedJobs(
+    cupsd_printer_t *p)                        /* I - Printer */
+{
+  cups_array_t *list;                  /* Array of jobs */
+  cupsd_job_t  *job;                   /* Current job */
+
+
+  list = cupsArrayNew(compare_completed_jobs, NULL);
+
+  for (job = (cupsd_job_t *)cupsArrayFirst(Jobs);
+       job;
+       job = (cupsd_job_t *)cupsArrayNext(Jobs))
+    if ((!p || !_cups_strcasecmp(p->name, job->dest)) && job->state_value >= IPP_JOB_STOPPED && job->completed_time)
+      cupsArrayAdd(list, job);
+
+  return (list);
+}
+
+
 /*
  * 'cupsdGetPrinterJobCount()' - Get the number of pending, processing,
  *                               or held jobs in a printer or class.
@@ -1654,6 +1679,8 @@ cupsdLoadJob(cupsd_job_t *job)            /* I - Job */
       (attr = ippFindAttribute(job->attrs, "time-at-completed",
                               IPP_TAG_INTEGER)) != NULL)
   {
+    job->completed_time = attr->values[0].integer;
+
     if (JobHistory < INT_MAX)
       job->history_time = attr->values[0].integer + JobHistory;
     else
@@ -2128,8 +2155,11 @@ cupsdSaveAllJobs(void)
   {
     cupsFilePrintf(fp, "<Job %d>\n", job->id);
     cupsFilePrintf(fp, "State %d\n", job->state_value);
+    if (job->completed_time)
+      cupsFilePrintf(fp, "Completed %ld\n", (long)job->completed_time);
     cupsFilePrintf(fp, "Priority %d\n", job->priority);
-    cupsFilePrintf(fp, "HoldUntil %d\n", (int)job->hold_until);
+    if (job->hold_until)
+      cupsFilePrintf(fp, "HoldUntil %ld\n", (long)job->hold_until);
     cupsFilePrintf(fp, "Username %s\n", job->username);
     cupsFilePrintf(fp, "Destination %s\n", job->dest);
     cupsFilePrintf(fp, "DestType %d\n", job->dtype);
@@ -2793,6 +2823,28 @@ compare_active_jobs(void *first, /* I - First job */
 }
 
 
+/*
+ * 'compare_completed_jobs()' - Compare the job IDs and completion times of two jobs.
+ */
+
+static int                             /* O - Difference */
+compare_completed_jobs(void *first,    /* I - First job */
+                       void *second,   /* I - Second job */
+                      void *data)      /* I - App data (not used) */
+{
+  int  diff;                           /* Difference */
+
+
+  (void)data;
+
+  if ((diff = ((cupsd_job_t *)second)->completed_time -
+              ((cupsd_job_t *)first)->completed_time) != 0)
+    return (diff);
+  else
+    return (((cupsd_job_t *)first)->id - ((cupsd_job_t *)second)->id);
+}
+
+
 /*
  * 'compare_jobs()' - Compare the job IDs of two jobs.
  */
@@ -4060,6 +4112,14 @@ load_job_cache(const char *filename)     /* I - job.cache filename */
 
       if (job->state_value <= IPP_JOB_STOPPED && cupsdLoadJob(job))
        cupsArrayAdd(ActiveJobs, job);
+      else if (job->state_value > IPP_JOB_STOPPED)
+      {
+        if (!job->completed_time)
+       {
+         cupsdLoadJob(job);
+         unload_job(job);
+       }
+      }
 
       job = NULL;
     }
@@ -4077,9 +4137,13 @@ load_job_cache(const char *filename)     /* I - job.cache filename */
       else if (job->state_value > IPP_JOB_COMPLETED)
         job->state_value = IPP_JOB_COMPLETED;
     }
+    else if (!_cups_strcasecmp(line, "Completed"))
+    {
+      job->completed_time = strtol(value, NULL, 10);
+    }
     else if (!_cups_strcasecmp(line, "HoldUntil"))
     {
-      job->hold_until = atoi(value);
+      job->hold_until = strtol(value, NULL, 10);
     }
     else if (!_cups_strcasecmp(line, "Priority"))
     {
@@ -4417,6 +4481,8 @@ set_time(cupsd_job_t *job,                /* I - Job to update */
 
   if (!strcmp(name, "time-at-completed"))
   {
+    job->completed_time = curtime;
+
     if (JobHistory < INT_MAX && attr)
       job->history_time = attr->values[0].integer + JobHistory;
     else
index c5d723e0ba7ba47b589ae7113334297a3b57fbce..ef66078e1f8e7982e785b0eae4028c3087acd430 100644 (file)
@@ -47,6 +47,7 @@ struct cupsd_job_s                    /**** Job request ****/
   ipp_attribute_t      *sheets;        /* job-media-sheets-completed */
   time_t               access_time,    /* Last access time */
                        cancel_time,    /* When to cancel/send SIGTERM */
+                       completed_time, /* When job was completed (0 if not) */
                        file_time,      /* Job file retain time */
                        history_time,   /* Job history retain time */
                        hold_until,     /* Hold expiration date/time */
@@ -148,6 +149,7 @@ extern void         cupsdDeleteJob(cupsd_job_t *job,
                                       cupsd_jobaction_t action);
 extern cupsd_job_t     *cupsdFindJob(int id);
 extern void            cupsdFreeAllJobs(void);
+extern cups_array_t    *cupsdGetCompletedJobs(cupsd_printer_t *p);
 extern int             cupsdGetPrinterJobCount(const char *dest);
 extern int             cupsdGetUserJobCount(const char *username);
 extern void            cupsdLoadAllJobs(void);
index 985db37b7c1e5db0d80fe5f1b1af2875859bf779..f77fc5873d436c1b1a45427b81ac4688f215a213 100644 (file)
@@ -1271,7 +1271,8 @@ show_jobs(const char *dests,              /* I - Destinations */
   const char   *dest,                  /* Pointer into job-printer-uri */
                *username,              /* Pointer to job-originating-user-name */
                *title,                 /* Pointer to job-name */
-               *message;               /* Pointer to job-printer-state-message */
+               *message,               /* Pointer to job-printer-state-message */
+               *time_at;               /* time-at-xxx attribute name to use */
   int          rank,                   /* Rank in queue */
                jobid,                  /* job-id */
                size;                   /* job-k-octets */
@@ -1287,7 +1288,8 @@ show_jobs(const char *dests,              /* I - Destinations */
                  "job-printer-state-message",
                  "job-printer-uri",
                  "job-state-reasons",
-                 "time-at-creation"
+                 "time-at-creation",
+                 "time-at-completed"
                };
 
 
@@ -1353,6 +1355,13 @@ show_jobs(const char *dests,             /* I - Destinations */
     * Loop through the job list and display them...
     */
 
+    if (!strcmp(which, "aborted") ||
+        !strcmp(which, "canceled") ||
+        !strcmp(which, "completed"))
+      time_at = "time-at-completed";
+    else
+      time_at = "time-at-creation";
+
     rank = -1;
 
     for (attr = response->attrs; attr != NULL; attr = attr->next)
@@ -1388,8 +1397,7 @@ show_jobs(const char *dests,              /* I - Destinations */
         else if (!strcmp(attr->name, "job-k-octets") &&
                 attr->value_tag == IPP_TAG_INTEGER)
          size = attr->values[0].integer;
-        else if (!strcmp(attr->name, "time-at-creation") &&
-                attr->value_tag == IPP_TAG_INTEGER)
+        else if (!strcmp(attr->name, time_at) && attr->value_tag == IPP_TAG_INTEGER)
          jobtime = attr->values[0].integer;
         else if (!strcmp(attr->name, "job-printer-state-message") &&
                 attr->value_tag == IPP_TAG_TEXT)
index a74f19bf739a6f8163e8ac80beee0a882f56bc91..94e2b3cb6e6220239ec9e718e05ba143773b1a5f 100644 (file)
@@ -81,6 +81,19 @@ echo ""
 
 ./waitjobs.sh
 
+echo "LPSTAT Completed Jobs Order Test"
+echo ""
+echo "    lpstat -W completed -o"
+$VALGRIND ../systemv/lpstat -W completed -o | tee $BASE/lpstat-completed.txt
+if test "`uniq -d $BASE/lpstat-completed.txt`" != ""; then
+       echo "    FAILED"
+       exit 1
+else
+       echo "    PASSED"
+fi
+echo ""
+
+
 #
 # End of "$Id$".
 #