cups_connection.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #ifndef PRINTING_BACKEND_CUPS_CONNECTION_H_
  5. #define PRINTING_BACKEND_CUPS_CONNECTION_H_
  6. #include <cups/cups.h>
  7. #include <memory>
  8. #include <string>
  9. #include <vector>
  10. #include "base/component_export.h"
  11. #include "base/memory/weak_ptr.h"
  12. #include "printing/backend/cups_deleters.h"
  13. #include "printing/backend/cups_jobs.h"
  14. #include "printing/backend/cups_printer.h"
  15. #include "printing/printer_status.h"
  16. #include "url/gurl.h"
  17. namespace printing {
  18. // Represents the status of a printer queue.
  19. struct COMPONENT_EXPORT(PRINT_BACKEND) QueueStatus {
  20. QueueStatus();
  21. QueueStatus(const QueueStatus& other);
  22. ~QueueStatus();
  23. PrinterStatus printer_status;
  24. std::vector<CupsJob> jobs;
  25. };
  26. // Represents a connection to a CUPS server.
  27. class COMPONENT_EXPORT(PRINT_BACKEND) CupsConnection {
  28. public:
  29. virtual ~CupsConnection() = default;
  30. static std::unique_ptr<CupsConnection> Create(const GURL& print_server_url,
  31. http_encryption_t encryption,
  32. bool blocking);
  33. // Obtain a vector of all the printers configure on the CUPS server. Returns
  34. // true if the list of printers was obtained, and false if an error was
  35. // encountered during the query.
  36. virtual bool GetDests(
  37. std::vector<std::unique_ptr<CupsPrinter>>& printers) = 0;
  38. // Returns a printer for `printer_name` from the connected server.
  39. virtual std::unique_ptr<CupsPrinter> GetPrinter(
  40. const std::string& printer_name) = 0;
  41. // Queries CUPS for printer queue status for `printer_ids`. Populates `jobs`
  42. // with said information with one QueueStatus per printer_id. Returns true if
  43. // all the queries were successful. In the event of failure, `jobs` will be
  44. // unchanged.
  45. virtual bool GetJobs(const std::vector<std::string>& printer_ids,
  46. std::vector<QueueStatus>* jobs) = 0;
  47. // Queries CUPS for printer status for `printer_id`.
  48. // Returns true if the query was successful.
  49. virtual bool GetPrinterStatus(const std::string& printer_id,
  50. PrinterStatus* printer_status) = 0;
  51. virtual std::string server_name() const = 0;
  52. virtual int last_error() const = 0;
  53. virtual std::string last_error_message() const = 0;
  54. };
  55. } // namespace printing
  56. #endif // PRINTING_BACKEND_CUPS_CONNECTION_H_