cups_printer_status.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2020 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 CHROMEOS_PRINTING_CUPS_PRINTER_STATUS_H_
  5. #define CHROMEOS_PRINTING_CUPS_PRINTER_STATUS_H_
  6. #include <string>
  7. #include "base/component_export.h"
  8. #include "base/containers/flat_set.h"
  9. #include "base/time/time.h"
  10. #include "chromeos/crosapi/mojom/local_printer.mojom.h"
  11. namespace chromeos {
  12. // A container for the results of a printer status query. A printer status query
  13. // can return multiple error reasons so CupsPrinterStatus contains multiple
  14. // CupsPrinterStatusReasons. |timestamp| is set at the time of CupsPrinterStatus
  15. // creation.
  16. class COMPONENT_EXPORT(CHROMEOS_PRINTING) CupsPrinterStatus {
  17. public:
  18. // A combination of a reason, which describes the state of a printer, and a
  19. // severity, which is the level of seriousness of that state.
  20. class COMPONENT_EXPORT(CHROMEOS_PRINTING) CupsPrinterStatusReason {
  21. public:
  22. using Reason = crosapi::mojom::StatusReason::Reason;
  23. using Severity = crosapi::mojom::StatusReason::Severity;
  24. CupsPrinterStatusReason(const Reason& reason, const Severity& severity);
  25. ~CupsPrinterStatusReason();
  26. const Reason& GetReason() const;
  27. const Severity& GetSeverity() const;
  28. bool operator==(const CupsPrinterStatusReason& other) const {
  29. return reason_ == other.reason_ && severity_ == other.severity_;
  30. }
  31. // Comparison operator to support storing CupsPrinterStatusReason in a
  32. // flat_set. Two CupsPrinterStatusReasons are considered matching iff
  33. // |reason| and |severity| are the same.
  34. bool operator<(const CupsPrinterStatusReason& other) const {
  35. return reason_ < other.reason_ ||
  36. (reason_ == other.reason_ && severity_ < other.severity_);
  37. }
  38. private:
  39. Reason reason_;
  40. Severity severity_;
  41. };
  42. // Creates a CupsPrinterStatus from an existing printing::PrinterStatus.
  43. explicit CupsPrinterStatus(const std::string& printer_id);
  44. CupsPrinterStatus();
  45. CupsPrinterStatus(const CupsPrinterStatus& other);
  46. CupsPrinterStatus& operator=(const CupsPrinterStatus& other);
  47. ~CupsPrinterStatus();
  48. const std::string& GetPrinterId() const;
  49. // Returns set of status reasons. Each reason describing status of the
  50. // printer.
  51. const base::flat_set<CupsPrinterStatusReason>& GetStatusReasons() const;
  52. const base::Time& GetTimestamp() const;
  53. // Adds a new CupsPrinterStatusReason to an existing CupsPrinterStatus.
  54. void AddStatusReason(const CupsPrinterStatusReason::Reason& reason,
  55. const CupsPrinterStatusReason::Severity& severity);
  56. private:
  57. std::string printer_id_;
  58. base::flat_set<CupsPrinterStatusReason> status_reasons_;
  59. base::Time timestamp_;
  60. };
  61. } // namespace chromeos
  62. #endif // CHROMEOS_PRINTING_CUPS_PRINTER_STATUS_H_