From cf43d0fd9812643653910fccf65ef36a9d4b0605 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Sat, 8 Oct 2022 17:18:17 +0800 Subject: [PATCH] =?UTF-8?q?SANE=E8=AE=BE=E5=A4=87=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E6=AF=8F=E4=B8=AAPID=E4=BF=9D=E6=8C=81=E5=94=AF=E4=B8=80?= =?UTF-8?q?=EF=BC=9B=E6=97=A5=E5=BF=97=E6=96=87=E4=BB=B6=E4=BB=A5=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E6=96=B9=E5=BC=8F=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hgdriver/hgdev/scanner_manager.cpp | 46 +++++++++++---------- hgdriver/wrapper/hg_log.cpp | 66 +++++++++++++++++++++--------- hgsane/sane_hg_mdw.cpp | 6 +-- 3 files changed, 75 insertions(+), 43 deletions(-) diff --git a/hgdriver/hgdev/scanner_manager.cpp b/hgdriver/hgdev/scanner_manager.cpp index 9b0f4da..4625a59 100644 --- a/hgdriver/hgdev/scanner_manager.cpp +++ b/hgdriver/hgdev/scanner_manager.cpp @@ -20,6 +20,10 @@ /// /// supporting devices : +/// +#define TO_STR(s) #s +#define PID_AND_NAME(p, n) 0x##p, std::string(n) + " - " + TO_STR(p) + static struct { uint16_t vid; // vendor ID @@ -31,15 +35,15 @@ static struct } g_supporting_devices[] = { #ifdef OEM_LISICHENG - {0x31c9, 0x8200, SCANNER_NAME_LSC_G42S, "G42x0F", "", &hg_scanner_mgr::create_scanner_g300} - , {0x31c9, 0x8420, SCANNER_NAME_LSC_G42S, "G426xF", "", &hg_scanner_mgr::create_scanner_g300} - , {0x31c9, 0x8429, SCANNER_NAME_LSC_G42S, "G42x0F", "", &hg_scanner_mgr::create_scanner_empty} - , {0x31c9, 0x8520, SCANNER_NAME_LSC_G52S, "G52x0F", "", &hg_scanner_mgr::create_scanner_g400} - , {0x31c9, 0x8529, SCANNER_NAME_LSC_G52S, "G52x0F", "", &hg_scanner_mgr::create_scanner_g239} - , {0x31c9, 0x8620, SCANNER_NAME_LSC_G62S, "G6290U", "", &hg_scanner_mgr::create_scanner_g100} - , {0x31c9, 0x8629, SCANNER_NAME_LSC_G62S, "G6290U", "", &hg_scanner_mgr::create_scanner_g239} - , {0x31c9, 0x8730, SCANNER_NAME_LSC_G73S, "G73x0U", "", &hg_scanner_mgr::create_scanner_g100} - , {0x31c9, 0x8739, SCANNER_NAME_LSC_G73S, "G73x0U", "", &hg_scanner_mgr::create_scanner_g239} + {0x31c9, PID_AND_NAME(8200, SCANNER_NAME_LSC_G42S), "G42S", "",&hg_scanner_mgr::create_scanner_g300} + , {0x31c9, PID_AND_NAME(8420, SCANNER_NAME_LSC_G42S), "G42S", "",&hg_scanner_mgr::create_scanner_g300} + , {0x31c9, PID_AND_NAME(8429, SCANNER_NAME_LSC_G42S), "G42S", "",&hg_scanner_mgr::create_scanner_empty} + , {0x31c9, PID_AND_NAME(8520, SCANNER_NAME_LSC_G52S), "G52S", "",&hg_scanner_mgr::create_scanner_g400} + , {0x31c9, PID_AND_NAME(8529, SCANNER_NAME_LSC_G52S), "G52S", "",&hg_scanner_mgr::create_scanner_g239} + , {0x31c9, PID_AND_NAME(8620, SCANNER_NAME_LSC_G62S), "G62S", "",&hg_scanner_mgr::create_scanner_g100} + , {0x31c9, PID_AND_NAME(8629, SCANNER_NAME_LSC_G62S), "G62S", "",&hg_scanner_mgr::create_scanner_g239} + , {0x31c9, PID_AND_NAME(8730, SCANNER_NAME_LSC_G73S), "G73S", "",&hg_scanner_mgr::create_scanner_g100} + , {0x31c9, PID_AND_NAME(8739, SCANNER_NAME_LSC_G73S), "G73S", "", &hg_scanner_mgr::create_scanner_g239} #elif defined(OEM_HANWANG) {0x2903, 0x1000, SCANNER_NAME_HW_1000, SCANNER_NAME_HW_1000, "",& hg_scanner_mgr::create_scanner_g300} // "HW-1060A" @@ -50,18 +54,18 @@ g_supporting_devices[] = { , {0x2903, 0x8000, SCANNER_NAME_HW_8000, SCANNER_NAME_HW_8000, "", &hg_scanner_mgr::create_scanner_g239} // "HW-8090F" , {0x2903, 0x9000, SCANNER_NAME_HW_9000, SCANNER_NAME_HW_9000, "", &hg_scanner_mgr::create_scanner_g239} // "HW-9110E" #else - {0x3072, 0x100, SCANNER_NAME_HG_G100, "GScanO200", "", &hg_scanner_mgr::create_scanner_g100} - , {0x3072, 0x139, SCANNER_NAME_HG_G100, "GScanO1003399", "", &hg_scanner_mgr::create_scanner_g239} - , {0x3072, 0x200, SCANNER_NAME_HG_G200, "GScanO200", "", &hg_scanner_mgr::create_scanner_g100} - , {0x3072, 0x239, SCANNER_NAME_HG_G200, "GScanO1003399", "", &hg_scanner_mgr::create_scanner_g239} - , {0x3072, 0x300, SCANNER_NAME_HG_G300, "GScanO400", "", &hg_scanner_mgr::create_scanner_g300} - , {0x3072, 0x302, SCANNER_NAME_HG_G300, "GScanO400", "", &hg_scanner_mgr::create_scanner_g302} - , {0x3072, 0x339, SCANNER_NAME_HG_G300, "GScanO1003399", "", &hg_scanner_mgr::create_scanner_empty} - , {0x3072, 0x400, SCANNER_NAME_HG_G400, "GScanO400", "", &hg_scanner_mgr::create_scanner_g400} - , {0x3072, 0x402, SCANNER_NAME_HG_G400, "GScanO4003399", "", &hg_scanner_mgr::create_scanner_g402} - , {0x3072, 0x439, SCANNER_NAME_HG_G400, "GScanO1003399", "", &hg_scanner_mgr::create_scanner_g239} - , {0x064B, 0x7823,SCANNER_NAME_HG_G200, "GScanO200", "", &hg_scanner_mgr::create_scanner_empty} -#endif + {0x3072, PID_AND_NAME(100, SCANNER_NAME_HG_G100), "G100", "",& hg_scanner_mgr::create_scanner_g100} + , {0x3072, PID_AND_NAME(139, SCANNER_NAME_HG_G100), "G100", "", &hg_scanner_mgr::create_scanner_g239} + , {0x3072, PID_AND_NAME(200, SCANNER_NAME_HG_G200), "G200", "", &hg_scanner_mgr::create_scanner_g100} + , {0x3072, PID_AND_NAME(239, SCANNER_NAME_HG_G200), "G200", "", &hg_scanner_mgr::create_scanner_g239} + , {0x3072, PID_AND_NAME(300, SCANNER_NAME_HG_G300), "G300", "",&hg_scanner_mgr::create_scanner_g300} + , {0x3072, PID_AND_NAME(302, SCANNER_NAME_HG_G300), "G300", "",&hg_scanner_mgr::create_scanner_g302} + , {0x3072, PID_AND_NAME(339, SCANNER_NAME_HG_G300), "G300", "",&hg_scanner_mgr::create_scanner_empty} + , {0x3072, PID_AND_NAME(400, SCANNER_NAME_HG_G400), "G400", "", &hg_scanner_mgr::create_scanner_g400} + , {0x3072, PID_AND_NAME(402, SCANNER_NAME_HG_G400), "G400", "",&hg_scanner_mgr::create_scanner_g402} + , {0x3072, PID_AND_NAME(439, SCANNER_NAME_HG_G400), "G400", "",&hg_scanner_mgr::create_scanner_g239} + , {0x064B, PID_AND_NAME(7823,SCANNER_NAME_HG_G200), "G200", "",&hg_scanner_mgr::create_scanner_empty} +#endif }; static std::string g_vendor = COMPANY_NAME; diff --git a/hgdriver/wrapper/hg_log.cpp b/hgdriver/wrapper/hg_log.cpp index 85a911e..d79e3dc 100644 --- a/hgdriver/wrapper/hg_log.cpp +++ b/hgdriver/wrapper/hg_log.cpp @@ -40,7 +40,7 @@ extern std::string g_scanner_path; // Ending with '\\' class log_cls { - typedef void(*log_to)(const char*, void*); + typedef void(*log_to)(const char*, void*, void*); std::string path_file_; FILE* file_; @@ -51,20 +51,55 @@ class log_cls static log_cls* inst_; - static void log_none(const char* info, void* param) + static FILE* create_log_file(const char* path_file, bool truncate) + { + FILE* file_ = fopen(path_file, "a+b"); + + if (file_) + { + fseek(file_, 0, SEEK_END); + if (ftell(file_)) + { + std::string sep("\n\n\n============================\n"); + fwrite(sep.c_str(), 1, sep.length(), file_); + } + else + { + unsigned char bom[] = { 0x0ef, 0x0bb, 0x0bf }; + fwrite(bom, sizeof(bom), 1, file_); + } + + std::string now(g_time_tag + hg_log::current_time() + g_time_tag); + now += truncate ? " trcated.\n" : " started.\n"; + fwrite(now.c_str(), 1, now.length(), file_); + } + + return file_; + } + static void log_none(const char* info, void* param, void* param2) {} - static void log_consonle(const char* info, void* param) + static void log_consonle(const char* info, void* param, void* param2) { printf(info); } - static void log_file(const char* info, void* param) + static void log_file(const char* info, void* param, void* param2) { - FILE* file = (FILE*)param; + FILE** file = (FILE**)param; - fwrite(info, 1, strlen(info), file); - fflush(file); - if (ftell(file) >= MAX_LOG_FILE_SIZE) - fseek(file, 0, SEEK_SET); + if(*file == nullptr) + *file = create_log_file(((std::string*)param2)->c_str(), false); + + if (*file) + { + fwrite(info, 1, strlen(info), *file); + fflush(*file); + if (ftell(*file) >= MAX_LOG_FILE_SIZE) + { + fclose(*file); + remove(((std::string*)param2)->c_str()); + *file = create_log_file(((std::string*)param2)->c_str(), true); + } + } } protected: @@ -113,16 +148,9 @@ public: if (param) { path_file_ = (char*)param; - file_ = fopen(path_file_.c_str(), "w+b"); + file_ = create_log_file(path_file_.c_str(), false); if (file_) - { - unsigned char bom[] = { 0x0ef, 0x0bb, 0x0bf }; - fwrite(bom, sizeof(bom), 1, file_); - - std::string now(g_time_tag + hg_log::current_time() + g_time_tag + " started.\n"); - fwrite(now.c_str(), 1, now.length(), file_); ret = 0; - } } } else if (type == LOG_TYPE_CALLBACK) @@ -148,13 +176,13 @@ public: { std::lock_guard lock(lock_); - log_(info, (void*)file_); + log_(info, &file_, &path_file_); } std::string get_log_file_path(bool copy) { std::string file(""); - if (log_ == &log_cls::log_file) + if (log_ == &log_cls::log_file && file_) { file = path_file_; diff --git a/hgsane/sane_hg_mdw.cpp b/hgsane/sane_hg_mdw.cpp index ecb2ce6..e4044e1 100644 --- a/hgsane/sane_hg_mdw.cpp +++ b/hgsane/sane_hg_mdw.cpp @@ -1196,7 +1196,7 @@ SANE_Status hg_sane_middleware::get_devices(const SANE_Device*** device_list, SA hgerr = hg_scanner_enum(dev, &count, local_only); if (hgerr != SCANNER_ERR_OK) { - free(dev); + local_utility::free_memory(dev); dev = NULL; } } @@ -1205,13 +1205,13 @@ SANE_Status hg_sane_middleware::get_devices(const SANE_Device*** device_list, SA { *device_list = hg_sane_middleware::to_sane_device(dev, count); if (dev) - free(dev); + local_utility::free_memory(dev); } else ret = local_utility::scanner_err_2_sane_statu(hgerr); if (hg_sane_middleware::dev_list_) - free(hg_sane_middleware::dev_list_); + local_utility::free_memory(hg_sane_middleware::dev_list_); hg_sane_middleware::dev_list_ = *device_list; return ret;