usb_printer_id.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2019 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_USB_PRINTER_ID_H_
  5. #define CHROMEOS_PRINTING_USB_PRINTER_ID_H_
  6. #include <map>
  7. #include <memory>
  8. #include <string>
  9. #include <utility>
  10. #include <vector>
  11. #include "base/component_export.h"
  12. #include "base/containers/span.h"
  13. namespace chromeos {
  14. // This class parses and holds the IEEE 1284 Device ID string as queried
  15. // from a USB-connected printer.
  16. class COMPONENT_EXPORT(CHROMEOS_PRINTING) UsbPrinterId {
  17. public:
  18. UsbPrinterId();
  19. UsbPrinterId(const UsbPrinterId& other);
  20. ~UsbPrinterId();
  21. // Expects |printer_id_data| to contain the data portion response to a USB
  22. // Printer Class-Specific GET_DEVICE_ID Request.
  23. explicit UsbPrinterId(base::span<const uint8_t> printer_id_data);
  24. // Accessors.
  25. const std::string& make() const { return make_; }
  26. const std::string& model() const { return model_; }
  27. const std::vector<std::string>& command_set() const { return command_set_; }
  28. // Setters (only used in testing).
  29. void set_make(std::string make) { make_ = make; }
  30. void set_model(std::string model) { model_ = model; }
  31. void set_command_set(std::vector<std::string> command_set) {
  32. command_set_ = std::move(command_set);
  33. }
  34. private:
  35. std::string make_;
  36. std::string model_;
  37. // List of supported document formats (MIME types).
  38. std::vector<std::string> command_set_;
  39. // Holds the fully parsed IEEE 1284 Device ID.
  40. std::map<std::string, std::vector<std::string>> id_mappings_;
  41. };
  42. // Expects data to hold a IEEE 1284 Device ID. Parses |data| and returns the
  43. // resulting key-value(s) pairs.
  44. COMPONENT_EXPORT(CHROMEOS_PRINTING)
  45. std::map<std::string, std::vector<std::string>> BuildDeviceIdMapping(
  46. base::span<const uint8_t> data);
  47. } // namespace chromeos
  48. #endif // CHROMEOS_PRINTING_USB_PRINTER_ID_H_