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/printing_export.h" |
| 15 #include "url/gurl.h" |
| 16 |
| 17 namespace base { |
| 18 class FilePath; |
| 19 } |
| 20 |
| 21 namespace printing { |
| 22 |
| 23 struct PrinterBasicInfo; |
| 24 |
| 25 class DestinationDeleter { |
| 26 public: |
| 27 void operator()(cups_dest_t* dest) const; |
| 28 }; |
| 29 |
| 30 class DestInfoDeleter { |
| 31 public: |
| 32 void operator()(cups_dinfo_t* info) const; |
| 33 }; |
| 34 |
| 35 // Represents a CUPS printer. |
| 36 // Retrieves information from CUPS printer objects as requested. |
| 37 class PRINTING_EXPORT CupsPrinter { |
| 38 public: |
| 39 // This object now owns |dest| and |info|. |
| 40 explicit CupsPrinter(std::shared_ptr<http_t> http, |
| 41 cups_dest_t* dest, |
| 42 cups_dinfo_t* info); |
| 43 |
| 44 CupsPrinter(CupsPrinter&& printer); |
| 45 |
| 46 ~CupsPrinter(); |
| 47 |
| 48 // Returns true if this is the default printer |
| 49 bool is_default() const; |
| 50 |
| 51 // Returns the supported ipp attributes for the given |option_name|. |
| 52 // ipp_attribute_t* is owned by CupsPrinter. |
| 53 ipp_attribute_t* GetSupportedOptionValues( |
| 54 base::StringPiece option_name) const; |
| 55 |
| 56 // Returns supported attribute values for |option_name| where the value can be |
| 57 // convered to a string. |
| 58 std::vector<base::StringPiece> GetSupportedOptionValueStrings( |
| 59 base::StringPiece option_name) const; |
| 60 |
| 61 // Returns the default ipp attributes for the given |option_name|. |
| 62 // ipp_attribute_t* is owned by CupsPrinter. |
| 63 ipp_attribute_t* GetDefaultOptionValue(base::StringPiece option_name) const; |
| 64 |
| 65 bool CheckOptionSupported(base::StringPiece name, |
| 66 base::StringPiece value) const; |
| 67 |
| 68 // Returns the file name for the PPD retrieved from the print server. |
| 69 base::FilePath GetPPD() const; |
| 70 |
| 71 // Returns the name of the printer as configured in CUPS |
| 72 const std::string GetName() const; |
| 73 |
| 74 const std::string GetMakeAndModel() const; |
| 75 |
| 76 // Returns true if the printer is currently reachable and working. |
| 77 bool IsAvailable() const; |
| 78 |
| 79 // Populates |basic_info| with the relevant information about the printer |
| 80 bool ToPrinterInfo(PrinterBasicInfo* basic_info) const; |
| 81 |
| 82 ipp_status_t CreateJob(int* job_id, |
| 83 base::StringPiece job_title, |
| 84 const std::vector<cups_option_t>& options); |
| 85 |
| 86 bool StartDocument(int job_id, |
| 87 base::StringPiece document_name, |
| 88 bool last_doc, |
| 89 const std::vector<cups_option_t>& options); |
| 90 |
| 91 bool StreamData(char* buffer, int len); |
| 92 |
| 93 bool FinishDocument(); |
| 94 |
| 95 ipp_status_t CloseJob(int job_id); |
| 96 |
| 97 private: |
| 98 bool InitializeDestInfo() const; |
| 99 |
| 100 std::shared_ptr<http_t> cups_http_; |
| 101 std::unique_ptr<cups_dest_t, DestinationDeleter> destination_; |
| 102 mutable std::unique_ptr<cups_dinfo_t, DestInfoDeleter> dest_info_; |
| 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(CupsPrinter); |
| 105 }; |
| 106 |
| 107 } // namespace printing |
| 108 |
| 109 #endif // PRINTING_BACKEND_CUPS_PRINTER_H_ |
OLD | NEW |