SANE设备名称每个PID保持唯一;日志文件以追加方式创建
This commit is contained in:
parent
c4fbab77ca
commit
cf43d0fd98
|
@ -20,6 +20,10 @@
|
|||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
|
||||
|
|
|
@ -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<std::mutex> 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_;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue