From 0bdce7928f55b2706a29418b363c184ff9f8ba2e Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 28 Mar 2020 23:15:47 +0200 Subject: [PATCH] genesys: Turn Genesys_USB_Device_Entry into a class --- backend/genesys/device.h | 2 +- backend/genesys/fwd.h | 2 +- backend/genesys/genesys.cpp | 14 ++++++------- backend/genesys/low.h | 21 ++++++++++++------- backend/genesys/tables_model.cpp | 4 ++-- backend/genesys/tables_sensor.cpp | 2 +- .../backend/genesys/session_config_test.cpp | 21 +++++++++++-------- 7 files changed, 38 insertions(+), 28 deletions(-) diff --git a/backend/genesys/device.h b/backend/genesys/device.h index 8250eb526..fae0ab31f 100644 --- a/backend/genesys/device.h +++ b/backend/genesys/device.h @@ -283,7 +283,7 @@ struct Genesys_Device // acquiring the positions of the black and white strips and the actual scan area bool ignore_offsets = false; - Genesys_Model *model = nullptr; + const Genesys_Model* model = nullptr; // pointers to low level functions std::unique_ptr cmd_set; diff --git a/backend/genesys/fwd.h b/backend/genesys/fwd.h index bd4375e0b..ee45a44d4 100644 --- a/backend/genesys/fwd.h +++ b/backend/genesys/fwd.h @@ -86,7 +86,7 @@ struct Pixel; struct RawPixel; // low.h -struct Genesys_USB_Device_Entry; +struct UsbDeviceEntry; // motor.h struct Genesys_Motor; diff --git a/backend/genesys/genesys.cpp b/backend/genesys/genesys.cpp index 5b911921c..2fbe96260 100644 --- a/backend/genesys/genesys.cpp +++ b/backend/genesys/genesys.cpp @@ -4231,7 +4231,7 @@ static void init_options(Genesys_Scanner* s) { DBG_HELPER(dbg); SANE_Int option; - Genesys_Model *model = s->dev->model; + const Genesys_Model* model = s->dev->model; memset (s->opt, 0, sizeof (s->opt)); @@ -4796,10 +4796,10 @@ check_present (SANE_String_Const devname) noexcept static Genesys_Device* attach_usb_device(const char* devname, std::uint16_t vendor_id, std::uint16_t product_id) { - Genesys_USB_Device_Entry* found_usb_dev = nullptr; + UsbDeviceEntry* found_usb_dev = nullptr; for (auto& usb_dev : *s_usb_devices) { - if (usb_dev.vendor == vendor_id && - usb_dev.product == product_id) + if (usb_dev.vendor_id() == vendor_id && + usb_dev.product_id() == product_id) { found_usb_dev = &usb_dev; break; @@ -4815,9 +4815,9 @@ static Genesys_Device* attach_usb_device(const char* devname, Genesys_Device* dev = &s_devices->back(); dev->file_name = devname; - dev->model = &found_usb_dev->model; - dev->vendorId = found_usb_dev->vendor; - dev->productId = found_usb_dev->product; + dev->model = &found_usb_dev->model(); + dev->vendorId = found_usb_dev->vendor_id(); + dev->productId = found_usb_dev->product_id(); dev->usb_mode = 0; // i.e. unset dev->already_initialized = false; return dev; diff --git a/backend/genesys/low.h b/backend/genesys/low.h index e356a2069..39297bf0e 100644 --- a/backend/genesys/low.h +++ b/backend/genesys/low.h @@ -168,18 +168,25 @@ namespace genesys { -struct Genesys_USB_Device_Entry { +class UsbDeviceEntry { +public: - Genesys_USB_Device_Entry(unsigned v, unsigned p, const Genesys_Model& m) : - vendor(v), product(p), model(m) + UsbDeviceEntry(std::uint16_t vendor_id, std::uint16_t product_id, + const Genesys_Model& model) : + vendor_{vendor_id}, product_{product_id}, model_{model} {} + std::uint16_t vendor_id() const { return vendor_; } + std::uint16_t product_id() const { return product_; } + const Genesys_Model& model() const { return model_; } + +private: // USB vendor identifier - std::uint16_t vendor; + std::uint16_t vendor_; // USB product identifier - std::uint16_t product; + std::uint16_t product_; // Scanner model information - Genesys_Model model; + Genesys_Model model_; }; /*--------------------------------------------------------------------------*/ @@ -467,7 +474,7 @@ extern StaticInit> s_frontends; extern StaticInit> s_gpo; extern StaticInit> s_memory_layout; extern StaticInit> s_motors; -extern StaticInit> s_usb_devices; +extern StaticInit> s_usb_devices; void genesys_init_sensor_tables(); void genesys_init_frontend_tables(); diff --git a/backend/genesys/tables_model.cpp b/backend/genesys/tables_model.cpp index 7cf0c12aa..1ccaee37e 100644 --- a/backend/genesys/tables_model.cpp +++ b/backend/genesys/tables_model.cpp @@ -58,7 +58,7 @@ namespace genesys { -StaticInit> s_usb_devices; +StaticInit> s_usb_devices; void genesys_init_usb_device_tables() { @@ -2760,7 +2760,7 @@ void genesys_init_usb_device_tables() void verify_usb_device_tables() { for (const auto& device : *s_usb_devices) { - const auto& model = device.model; + const auto& model = device.model(); if (model.x_size_calib_mm == 0.0f) { throw SaneException("Calibration width can't be zero"); diff --git a/backend/genesys/tables_sensor.cpp b/backend/genesys/tables_sensor.cpp index 619f49ea7..9aa24e8ec 100644 --- a/backend/genesys/tables_sensor.cpp +++ b/backend/genesys/tables_sensor.cpp @@ -3651,7 +3651,7 @@ void verify_sensor_tables() { std::map sensor_to_asic; for (const auto& device : *s_usb_devices) { - sensor_to_asic[device.model.sensor_id] = device.model.asic_type; + sensor_to_asic[device.model().sensor_id] = device.model().asic_type; } for (const auto& sensor : *s_sensors) { if (sensor_to_asic.count(sensor.sensor_id) == 0) { diff --git a/testsuite/backend/genesys/session_config_test.cpp b/testsuite/backend/genesys/session_config_test.cpp index 78ea166e7..4f4e486a1 100644 --- a/testsuite/backend/genesys/session_config_test.cpp +++ b/testsuite/backend/genesys/session_config_test.cpp @@ -397,30 +397,33 @@ std::vector get_all_test_configs() std::unordered_set model_names; for (const auto& usb_dev : *genesys::s_usb_devices) { - if (genesys::has_flag(usb_dev.model.flags, genesys::ModelFlag::UNTESTED)) { + + const auto& model = usb_dev.model(); + + if (genesys::has_flag(model.flags, genesys::ModelFlag::UNTESTED)) { continue; } - if (model_names.find(usb_dev.model.name) != model_names.end()) { + if (model_names.find(model.name) != model_names.end()) { continue; } - model_names.insert(usb_dev.model.name); + model_names.insert(model.name); for (auto scan_mode : { genesys::ScanColorMode::LINEART, genesys::ScanColorMode::GRAY, genesys::ScanColorMode::COLOR_SINGLE_PASS }) { - auto depth_values = usb_dev.model.bpp_gray_values; + auto depth_values = model.bpp_gray_values; if (scan_mode == genesys::ScanColorMode::COLOR_SINGLE_PASS) { - depth_values = usb_dev.model.bpp_color_values; + depth_values = model.bpp_color_values; } for (unsigned depth : depth_values) { - for (auto method_resolutions : usb_dev.model.resolutions) { + for (auto method_resolutions : model.resolutions) { for (auto method : method_resolutions.methods) { for (unsigned resolution : method_resolutions.get_resolutions()) { TestConfig config; - config.vendor_id = usb_dev.vendor; - config.product_id = usb_dev.product; - config.model_name = usb_dev.model.name; + config.vendor_id = usb_dev.vendor_id(); + config.product_id = usb_dev.product_id(); + config.model_name = model.name; config.method = method; config.depth = depth; config.resolution = resolution;