// scanner business handler // // created on 2023-03-27 // #pragma once #include #include #include class hg_scanner; class imgproc_mgr; class device_option; class scanner_handler; class hguser; struct libusb_device; typedef struct _online_scanner { int vid; int pid; int addr; libusb_device *dev; // the unique usb device hg_scanner *scanner; std::string family; std::string display_name; // unique. same device name should append sn bool operator==(const libusb_device* d) { return d == dev; } bool operator==(const char* name) { return display_name == name; } bool operator==(const hg_scanner* s) { return s == scanner; } }ONLNSCANNER; class hg_scanner : public sane_opt_provider { int status_; std::string msg_; std::string dump_path_; ONLNSCANNER dev_; device_option *dev_opts_ = nullptr; imgproc_mgr *imgproc_ = nullptr; shared_memory *singleton_ = nullptr; scanner_handler *scanner_ = nullptr; hguser *user_ = nullptr; chronograph scan_time_; int final_cnt_ = 0; double tx_prg_ = .0f; // file transfer progress std::function scan_over_notify_ = std::function(); // finish(err) volatile bool cancelled_ = false; volatile bool run_ = true; safe_fifo raw_imgs_; safe_fifo final_imgs_; uint32_t cur_img_pos_ = 0; // transmission position of front image uint32_t dpi_ = 200; #ifdef USE_SAFE_THREAD safe_thread imgpr_thread_; #else std::unique_ptr imgpr_thread_; #endif bool online_ = true; std::map img_prc_name_; // static shared_memory* create_device_singleton(int vid, int pid, int addr); static image_holder_ptr make_finished_image_holder(int err); static bool is_finished_image_holder(image_holder_ptr ptr, int* err); void init(void); void thread_image_processor(void); void process_image(image_holder_ptr img); image_holder_ptr wait_image(void); public: hg_scanner(ONLNSCANNER* dev, imgproc_mgr* imgproc = nullptr, hguser* user = nullptr, std::vector* constopts = nullptr); protected: virtual ~hg_scanner(); // sane_opt_provider public: virtual char* get_value(const char* name, void* value, size_t* size, int* err = nullptr) override; virtual int set_value(const char* name, void* val) override; // scanner operation ... public: int start(std::string* devcfg, std::function over_cb = std::function()); int stop(void); int close(void); int re_connect(void); int get_image_info(SANE_Parameters* pii); int read_image_data(uint8_t* buf, size_t* len); int get_resolution(void); void clear_images(void); int status(EP0REPLYSTATUS* ds = nullptr, bool en_dev_log = false/*enable device write log of this status*/); std::string status_message(void); bool is_online(void); char* get_option_value(const char* name, void* value, size_t* size, int* err); // advanced functions ... public: device_option* get_device_opt(void); int get_peer_config(LPPEERCFG cfg); int file_transfer(const char* local, const char* remote, bool to_remote); // get_value("tx-prog", (double*)percent) to query progress };