OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Implementations of IPP requests for printer queue information. |
| 6 |
| 7 #ifndef PRINTING_BACKEND_CUPS_JOBS_H_ |
| 8 #define PRINTING_BACKEND_CUPS_JOBS_H_ |
| 9 |
| 10 #include <cups/cups.h> |
| 11 |
| 12 #include <string> |
| 13 #include <vector> |
| 14 |
| 15 #include "printing/printing_export.h" |
| 16 |
| 17 namespace printing { |
| 18 |
| 19 // Represents a print job sent to the queue. |
| 20 struct PRINTING_EXPORT CupsJob { |
| 21 // Corresponds to job-state from RFC2911. |
| 22 enum JobState { |
| 23 UNKNOWN, |
| 24 PENDING, // waiting to be processed |
| 25 HELD, // the job has not begun printing and will not without intervention |
| 26 COMPLETED, |
| 27 PROCESSING, // job is being sent to the printer/printed |
| 28 STOPPED, // job was being processed and has now stopped |
| 29 CANCELED, // either the spooler or a user canclled the job |
| 30 ABORTED // an error occurred causing the printer to give up |
| 31 }; |
| 32 |
| 33 // job id |
| 34 int id = -1; |
| 35 // printer name in CUPS |
| 36 std::string printer_id; |
| 37 JobState state = UNKNOWN; |
| 38 // the last page printed |
| 39 int current_pages = -1; |
| 40 // detail for the job state |
| 41 std::vector<std::string> state_reasons; |
| 42 // human readable message explaining the state |
| 43 std::string state_message; |
| 44 // most recent timestamp where the job entered PROCESSING |
| 45 int processing_started = 0; |
| 46 }; |
| 47 |
| 48 // Represents the status of a printer containing the properties printer-state, |
| 49 // printer-state-reasons, and printer-state-message. |
| 50 struct PrinterStatus { |
| 51 struct PrinterReason { |
| 52 // Standardized reasons from RFC2911. |
| 53 enum Reason { |
| 54 UNKNOWN_REASON, |
| 55 NONE, |
| 56 MEDIA_NEEDED, |
| 57 MEDIA_JAM, |
| 58 MOVING_TO_PAUSED, |
| 59 PAUSED, |
| 60 SHUTDOWN, |
| 61 CONNECTING_TO_DEVICE, |
| 62 TIMED_OUT, |
| 63 STOPPING, |
| 64 STOPPED_PARTLY, |
| 65 TONER_LOW, |
| 66 TONER_EMPTY, |
| 67 SPOOL_AREA_FULL, |
| 68 COVER_OPEN, |
| 69 INTERLOCK_OPEN, |
| 70 DOOR_OPEN, |
| 71 INPUT_TRAY_MISSING, |
| 72 MEDIA_LOW, |
| 73 MEDIA_EMPTY, |
| 74 OUTPUT_TRAY_MISSING, |
| 75 OUTPUT_AREA_ALMOST_FULL, |
| 76 OUTPUT_AREA_FULL, |
| 77 MARKER_SUPPLY_LOW, |
| 78 MARKER_SUPPLY_EMPTY, |
| 79 MARKER_WASTE_ALMOST_FULL, |
| 80 MARKER_WASTE_FULL, |
| 81 FUSER_OVER_TEMP, |
| 82 FUSER_UNDER_TEMP, |
| 83 OPC_NEAR_EOL, |
| 84 OPC_LIFE_OVER, |
| 85 DEVELOPER_LOW, |
| 86 DEVELOPER_EMPTY, |
| 87 INTERPRETER_RESOURCE_UNAVAILABLE |
| 88 }; |
| 89 |
| 90 // Severity of the state-reason. |
| 91 enum Severity { UNKNOWN_SEVERITY, REPORT, WARNING, ERROR }; |
| 92 |
| 93 Reason reason; |
| 94 Severity severity; |
| 95 }; |
| 96 |
| 97 // printer-state |
| 98 ipp_pstate_t state; |
| 99 // printer-state-reasons |
| 100 std::vector<PrinterReason> reasons; |
| 101 // printer-state-message |
| 102 std::string message; |
| 103 }; |
| 104 |
| 105 // Specifies classes of jobs. |
| 106 enum JobCompletionState { |
| 107 COMPLETED, // only completed jobs |
| 108 PROCESSING // only jobs that are being processed |
| 109 }; |
| 110 |
| 111 // Extracts structured job information from the |response| for |printer_id|. |
| 112 // Extracted jobs are added to |jobs|. |
| 113 void ParseJobsResponse(ipp_t* response, |
| 114 const std::string& printer_id, |
| 115 std::vector<CupsJob>* jobs); |
| 116 |
| 117 // Attempts to extract a PrinterStatus object out of |response|. |
| 118 void ParsePrinterStatus(ipp_t* response, PrinterStatus* printer_status); |
| 119 |
| 120 // Attempts to retrieve printer status using connection |http| for |printer_id|. |
| 121 // Returns true if succcssful and updates the fields in |printer_status| as |
| 122 // appropriate. Returns false if the request failed. |
| 123 bool GetPrinterStatus(http_t* http, |
| 124 const std::string& printer_id, |
| 125 PrinterStatus* printer_status); |
| 126 |
| 127 // Attempts to retrieve job information using connection |http| for the printer |
| 128 // named |printer_id|. Retrieves at most |limit| jobs. If |completed| then |
| 129 // completed jobs are retrieved. Otherwise, jobs that are currently in progress |
| 130 // are retrieved. Results are added to |jobs| if the operation was successful. |
| 131 bool GetCupsJobs(http_t* http, |
| 132 const std::string& printer_id, |
| 133 int limit, |
| 134 JobCompletionState completed, |
| 135 std::vector<CupsJob>* jobs); |
| 136 |
| 137 } // namespace printing |
| 138 |
| 139 #endif // PRINTING_BACKEND_CUPS_JOBS_H_ |
OLD | NEW |