OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef PRINTING_BACKEND_CUPS_CONNECTION_H_ | 5 #ifndef PRINTING_BACKEND_CUPS_CONNECTION_H_ |
6 #define PRINTING_BACKEND_CUPS_CONNECTION_H_ | 6 #define PRINTING_BACKEND_CUPS_CONNECTION_H_ |
7 | 7 |
8 #include <cups/cups.h> | 8 #include <cups/cups.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "printing/backend/cups_deleters.h" | 16 #include "printing/backend/cups_deleters.h" |
| 17 #include "printing/backend/cups_jobs.h" |
17 #include "printing/backend/cups_printer.h" | 18 #include "printing/backend/cups_printer.h" |
18 #include "printing/printing_export.h" | 19 #include "printing/printing_export.h" |
19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
20 | 21 |
21 namespace printing { | 22 namespace printing { |
22 | 23 |
23 // Represents a print job sent to the queue. | 24 // Represents the status of a printer queue. |
24 struct PRINTING_EXPORT CupsJob { | 25 struct PRINTING_EXPORT QueueStatus { |
25 enum JobState { | 26 PrinterStatus printer_status; |
26 UNKNOWN, | 27 std::vector<CupsJob> jobs; |
27 PENDING, | |
28 HELD, | |
29 COMPLETED, | |
30 PROCESSING, | |
31 STOPPED, | |
32 CANCELED, | |
33 ABORTED | |
34 }; | |
35 | |
36 int id; | |
37 std::string title; | |
38 std::string printer_id; | |
39 JobState state; | |
40 }; | 28 }; |
41 | 29 |
42 // Represents a connection to a CUPS server. | 30 // Represents a connection to a CUPS server. |
43 class PRINTING_EXPORT CupsConnection { | 31 class PRINTING_EXPORT CupsConnection { |
44 public: | 32 public: |
45 CupsConnection(const GURL& print_server_url, | 33 CupsConnection(const GURL& print_server_url, |
46 http_encryption_t encryption, | 34 http_encryption_t encryption, |
47 bool blocking); | 35 bool blocking); |
48 | 36 |
49 CupsConnection(CupsConnection&& connection); | 37 CupsConnection(CupsConnection&& connection); |
50 | 38 |
51 ~CupsConnection(); | 39 ~CupsConnection(); |
52 | 40 |
53 // Returns a vector of all the printers configure on the CUPS server. | 41 // Returns a vector of all the printers configure on the CUPS server. |
54 std::vector<CupsPrinter> GetDests(); | 42 std::vector<CupsPrinter> GetDests(); |
55 | 43 |
56 // Returns a printer for |printer_name| from the connected server. | 44 // Returns a printer for |printer_name| from the connected server. |
57 std::unique_ptr<CupsPrinter> GetPrinter(const std::string& printer_name); | 45 std::unique_ptr<CupsPrinter> GetPrinter(const std::string& printer_name); |
58 | 46 |
59 // Returns a list of print jobs from all connected printers. | 47 // Queries CUPS for printer queue status for |printer_ids|. Populates |jobs| |
60 std::vector<CupsJob> GetJobs(); | 48 // with said information with one QueueStatus per printer_id. Returns true if |
| 49 // all the queries were successful. In the event of failure, |jobs| will be |
| 50 // unchanged. |
| 51 bool GetJobs(const std::vector<std::string>& printer_ids, |
| 52 std::vector<QueueStatus>* jobs); |
61 | 53 |
62 std::string server_name() const; | 54 std::string server_name() const; |
63 | 55 |
64 int last_error() const; | 56 int last_error() const; |
65 | 57 |
66 private: | 58 private: |
67 // lazily initialize http connection | 59 // lazily initialize http connection |
68 bool Connect(); | 60 bool Connect(); |
69 | 61 |
70 GURL print_server_url_; | 62 GURL print_server_url_; |
71 http_encryption_t cups_encryption_; | 63 http_encryption_t cups_encryption_; |
72 bool blocking_; | 64 bool blocking_; |
73 | 65 |
74 std::unique_ptr<http_t, HttpDeleter> cups_http_; | 66 std::unique_ptr<http_t, HttpDeleter> cups_http_; |
75 | 67 |
76 DISALLOW_COPY_AND_ASSIGN(CupsConnection); | 68 DISALLOW_COPY_AND_ASSIGN(CupsConnection); |
77 }; | 69 }; |
78 | 70 |
79 } // namespace printing | 71 } // namespace printing |
80 | 72 |
81 #endif // PRINTING_BACKEND_CUPS_CONNECTION_H_ | 73 #endif // PRINTING_BACKEND_CUPS_CONNECTION_H_ |
OLD | NEW |