Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef PRINTING_BACKEND_CUPS_PRINTER_H_ | |
| 6 #define PRINTING_BACKEND_CUPS_PRINTER_H_ | |
| 7 | |
| 8 #include <cups/cups.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 #include <string> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "printing/backend/cups_deleters.h" | |
| 15 #include "printing/printing_export.h" | |
| 16 #include "url/gurl.h" | |
| 17 | |
| 18 namespace base { | |
| 19 class FilePath; | |
| 20 } | |
| 21 | |
| 22 namespace printing { | |
| 23 | |
| 24 struct PrinterBasicInfo; | |
| 25 | |
| 26 // Provides information regarding cups options. | |
| 27 class PRINTING_EXPORT CupsOptionProvider { | |
| 28 public: | |
| 29 virtual ~CupsOptionProvider() = default; | |
| 30 | |
| 31 // Returns the supported ipp attributes for the given |option_name|. | |
| 32 // ipp_attribute_t* is owned by CupsOptionProvider. | |
| 33 virtual ipp_attribute_t* GetSupportedOptionValues( | |
| 34 base::StringPiece option_name) const = 0; | |
| 35 | |
| 36 // Returns supported attribute values for |option_name| where the value can be | |
| 37 // convered to a string. | |
| 38 virtual std::vector<base::StringPiece> GetSupportedOptionValueStrings( | |
| 39 base::StringPiece option_name) const = 0; | |
| 40 | |
| 41 // Returns the default ipp attributes for the given |option_name|. | |
| 42 // ipp_attribute_t* is owned by CupsOptionProvider. | |
| 43 virtual ipp_attribute_t* GetDefaultOptionValue( | |
| 44 base::StringPiece option_name) const = 0; | |
| 45 | |
| 46 // Returns true if the |value| is supported by option |name|. | |
| 47 virtual bool CheckOptionSupported(base::StringPiece name, | |
| 48 base::StringPiece value) const = 0; | |
| 49 }; | |
| 50 | |
| 51 // Represents a CUPS printer. | |
| 52 // Retrieves information from CUPS printer objects as requested. This class | |
| 53 // is only valid as long as the CupsConnection which created it exists as they | |
| 54 // share an http connection which the CupsConnection closes on destruction. | |
| 55 class PRINTING_EXPORT CupsPrinter : public CupsOptionProvider { | |
| 56 public: | |
| 57 // Create a printer with a connection defined by |http| and |dest|. |info| | |
| 58 // can be null and will be | |
| 59 // lazily initialized when needed. | |
|
Lei Zhang
2016/07/21 20:31:30
Combine with previous line. If you are using "git
skau
2016/07/21 23:33:10
I have been using git cl format. Thanks.
| |
| 60 CupsPrinter(http_t* http, | |
| 61 std::unique_ptr<cups_dest_t, DestinationDeleter> dest, | |
| 62 std::unique_ptr<cups_dinfo_t, DestInfoDeleter> info); | |
| 63 | |
| 64 CupsPrinter(CupsPrinter&& printer); | |
| 65 | |
| 66 ~CupsPrinter() override; | |
| 67 | |
| 68 // Returns true if this is the default printer | |
| 69 bool is_default() const; | |
| 70 | |
| 71 // CupsOptionProvider | |
| 72 ipp_attribute_t* GetSupportedOptionValues( | |
| 73 base::StringPiece option_name) const override; | |
| 74 std::vector<base::StringPiece> GetSupportedOptionValueStrings( | |
| 75 base::StringPiece option_name) const override; | |
| 76 ipp_attribute_t* GetDefaultOptionValue( | |
| 77 base::StringPiece option_name) const override; | |
| 78 bool CheckOptionSupported(base::StringPiece name, | |
| 79 base::StringPiece value) const override; | |
| 80 | |
| 81 // Returns the file name for the PPD retrieved from the print server. | |
| 82 base::FilePath GetPPD() const; | |
| 83 | |
| 84 // Returns the name of the printer as configured in CUPS | |
| 85 std::string GetName() const; | |
| 86 | |
| 87 std::string GetMakeAndModel() const; | |
| 88 | |
| 89 // Returns true if the printer is currently reachable and working. | |
| 90 bool IsAvailable() const; | |
| 91 | |
| 92 // Populates |basic_info| with the relevant information about the printer | |
| 93 bool ToPrinterInfo(PrinterBasicInfo* basic_info) const; | |
| 94 | |
| 95 // Start a print job. Writes the id of the started job to |job_id|. |job_id| | |
| 96 // is 0 if there is an error. Check availability before using this operation. | |
| 97 // Usage on an unavailable printer is undefined. | |
| 98 ipp_status_t CreateJob(int* job_id, | |
| 99 base::StringPiece job_title, | |
| 100 const std::vector<cups_option_t>& options); | |
| 101 | |
| 102 // Add a document to a print job. |job_id| must be non-zero and refer to a | |
| 103 // job started with CreateJob. |document_name| will be displayed in print | |
| 104 // status. |last_doc| should be true if this is the last document for this | |
| 105 // print job. |options| should be IPP key value pairs for the Send-Document | |
| 106 // operation. | |
| 107 bool StartDocument(int job_id, | |
| 108 base::StringPiece document_name, | |
| 109 bool last_doc, | |
| 110 const std::vector<cups_option_t>& options); | |
| 111 | |
| 112 // Add data to the current document started by StartDocument. Calling this | |
| 113 // without a started document will fail. | |
| 114 bool StreamData(const std::vector<char>& buffer); | |
| 115 | |
| 116 // Finish the current document. Another document can be added or the job can | |
| 117 // be closed to complete printing. | |
| 118 bool FinishDocument(); | |
| 119 | |
| 120 // Close the job. If the job is not closed, the documents will not be | |
| 121 // printed. |job_id| should match the id from CreateJob. | |
| 122 ipp_status_t CloseJob(int job_id); | |
| 123 | |
| 124 private: | |
| 125 // Lazily initialize dest info as it can require a network call | |
| 126 bool InitializeDestInfo() const; | |
| 127 | |
| 128 // http connection owned by the CupsConnection which created this object | |
| 129 http_t* const cups_http_; | |
| 130 | |
| 131 // information to identify a printer | |
| 132 std::unique_ptr<cups_dest_t, DestinationDeleter> destination_; | |
| 133 | |
| 134 // opaque object containing printer attributes and options | |
| 135 mutable std::unique_ptr<cups_dinfo_t, DestInfoDeleter> dest_info_; | |
| 136 | |
| 137 DISALLOW_COPY_AND_ASSIGN(CupsPrinter); | |
| 138 }; | |
| 139 | |
| 140 } // namespace printing | |
| 141 | |
| 142 #endif // PRINTING_BACKEND_CUPS_PRINTER_H_ | |
| OLD | NEW |