修复卸载驱动时,未清空API的问题;增加TRIPLET操作日志记录功能

This commit is contained in:
gb 2023-03-27 12:04:54 +08:00
parent f41bb8730e
commit e6ead9b452
3 changed files with 204 additions and 2 deletions

View File

@ -181,8 +181,14 @@ namespace load_sane_util
} }
void uninitialize(void) void uninitialize(void)
{ {
sane_inst = NULL;
is_on = NULL;
init = NULL;
log = NULL;
if (uninit) if (uninit)
uninit(NULL); uninit(NULL);
uninit = NULL;
if (sane_module) if (sane_module)
{ {

View File

@ -161,6 +161,191 @@ TWPP_ENTRY(huagao_ds)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// utilites ... // utilites ...
// some helper functions to handle capability stuff // some helper functions to handle capability stuff
#define RETURN_ENUM_DESC(en, v, space) \
if(v == space::en) \
return L###en;
const wchar_t* desc_state(DsState s, wchar_t unk[20])
{
RETURN_ENUM_DESC(Closed, s, DsState);
RETURN_ENUM_DESC(Open, s, DsState);
RETURN_ENUM_DESC(Enabled, s, DsState);
RETURN_ENUM_DESC(XferReady, s, DsState);
RETURN_ENUM_DESC(Xferring, s, DsState);
swprintf(unk, L"%d", s);
return unk;
}
const wchar_t* desc_data_group(DataGroup d, wchar_t unk[20])
{
RETURN_ENUM_DESC(Control, d, DataGroup);
RETURN_ENUM_DESC(Image, d, DataGroup);
RETURN_ENUM_DESC(Audio, d, DataGroup);
{
swprintf(unk, L"%d", d);
return unk;
}
}
const wchar_t* desc_data(Dat d, wchar_t unk[20])
{
RETURN_ENUM_DESC(Null, d, Dat);
RETURN_ENUM_DESC(Capability, d, Dat);
RETURN_ENUM_DESC(Event, d, Dat);
RETURN_ENUM_DESC(Identity, d, Dat);
RETURN_ENUM_DESC(Parent, d, Dat);
RETURN_ENUM_DESC(PendingXfers, d, Dat);
RETURN_ENUM_DESC(SetupMemXfer, d, Dat);
RETURN_ENUM_DESC(SetupFileXfer, d, Dat);
RETURN_ENUM_DESC(Status, d, Dat);
RETURN_ENUM_DESC(UserInterface, d, Dat);
RETURN_ENUM_DESC(XferGroup, d, Dat);
RETURN_ENUM_DESC(CustomData, d, Dat);
RETURN_ENUM_DESC(DeviceEvent, d, Dat);
RETURN_ENUM_DESC(FileSystem, d, Dat);
RETURN_ENUM_DESC(PassThrough, d, Dat);
RETURN_ENUM_DESC(Callback, d, Dat);
RETURN_ENUM_DESC(StatusUtf8, d, Dat);
RETURN_ENUM_DESC(Callback2, d, Dat);
RETURN_ENUM_DESC(ImageInfo, d, Dat);
RETURN_ENUM_DESC(ImageLayout, d, Dat);
RETURN_ENUM_DESC(ImageMemXfer, d, Dat);
RETURN_ENUM_DESC(ImageNativeXfer, d, Dat);
RETURN_ENUM_DESC(ImageFileXfer, d, Dat);
RETURN_ENUM_DESC(CieColor, d, Dat);
RETURN_ENUM_DESC(GrayResponse, d, Dat);
RETURN_ENUM_DESC(RgbResponse, d, Dat);
RETURN_ENUM_DESC(JpegCompression, d, Dat);
RETURN_ENUM_DESC(Palette8, d, Dat);
RETURN_ENUM_DESC(ExtImageInfo, d, Dat);
RETURN_ENUM_DESC(Filter, d, Dat);
RETURN_ENUM_DESC(AudioFileXfer, d, Dat);
RETURN_ENUM_DESC(AudioInfo, d, Dat);
RETURN_ENUM_DESC(AudioNativeXfer, d, Dat);
RETURN_ENUM_DESC(IccProfile, d, Dat);
RETURN_ENUM_DESC(ImageMemFileXfer, d, Dat);
RETURN_ENUM_DESC(EntryPoint, d, Dat);
{
swprintf(unk, L"%d", d);
return unk;
}
}
const wchar_t* desc_msg(Msg m, wchar_t unk[20])
{
RETURN_ENUM_DESC(Null, m, Msg);
RETURN_ENUM_DESC(Get, m, Msg);
RETURN_ENUM_DESC(GetCurrent, m, Msg);
RETURN_ENUM_DESC(GetDefault, m, Msg);
RETURN_ENUM_DESC(GetFirst, m, Msg);
RETURN_ENUM_DESC(GetNext, m, Msg);
RETURN_ENUM_DESC(Set, m, Msg);
RETURN_ENUM_DESC(Reset, m, Msg);
RETURN_ENUM_DESC(QuerySupport, m, Msg);
RETURN_ENUM_DESC(GetHelp, m, Msg);
RETURN_ENUM_DESC(GetLabel, m, Msg);
RETURN_ENUM_DESC(GetLabelEnum, m, Msg);
RETURN_ENUM_DESC(SetConstraint, m, Msg);
RETURN_ENUM_DESC(XferReady, m, Msg);
RETURN_ENUM_DESC(CloseDsReq, m, Msg);
RETURN_ENUM_DESC(CloseDsOk, m, Msg);
RETURN_ENUM_DESC(DeviceEvent, m, Msg);
RETURN_ENUM_DESC(OpenDsm, m, Msg);
RETURN_ENUM_DESC(CloseDsm, m, Msg);
RETURN_ENUM_DESC(OpenDs, m, Msg);
RETURN_ENUM_DESC(CloseDs, m, Msg);
RETURN_ENUM_DESC(UserSelect, m, Msg);
RETURN_ENUM_DESC(DisableDs, m, Msg);
RETURN_ENUM_DESC(EnableDs, m, Msg);
RETURN_ENUM_DESC(EnableDsUiOnly, m, Msg);
RETURN_ENUM_DESC(ProcessEvent, m, Msg);
RETURN_ENUM_DESC(EndXfer, m, Msg);
RETURN_ENUM_DESC(StopFeeder, m, Msg);
RETURN_ENUM_DESC(ChangeDir, m, Msg);
RETURN_ENUM_DESC(CreateDir, m, Msg);
RETURN_ENUM_DESC(Delete, m, Msg);
RETURN_ENUM_DESC(FormatMedia, m, Msg);
RETURN_ENUM_DESC(GetClose, m, Msg);
RETURN_ENUM_DESC(GetFirstFile, m, Msg);
RETURN_ENUM_DESC(GetInfo, m, Msg);
RETURN_ENUM_DESC(GetNextFile, m, Msg);
RETURN_ENUM_DESC(Rename, m, Msg);
RETURN_ENUM_DESC(Copy, m, Msg);
RETURN_ENUM_DESC(AutomaticCaptureDir, m, Msg);
RETURN_ENUM_DESC(PassThrough, m, Msg);
RETURN_ENUM_DESC(RegisterCallback, m, Msg);
RETURN_ENUM_DESC(ResetAll, m, Msg);
RETURN_ENUM_DESC(CustomBase, m, Msg);
{
swprintf(unk, L"%d", m);
return unk;
}
}
const wchar_t* desc_return_code(ReturnCode rc, wchar_t unk[20])
{
RETURN_ENUM_DESC(Success, rc, ReturnCode);
RETURN_ENUM_DESC(Failure, rc, ReturnCode);
RETURN_ENUM_DESC(CheckStatus, rc, ReturnCode);
RETURN_ENUM_DESC(Cancel, rc, ReturnCode);
RETURN_ENUM_DESC(DsEvent, rc, ReturnCode);
RETURN_ENUM_DESC(NotDsEvent, rc, ReturnCode);
RETURN_ENUM_DESC(XferDone, rc, ReturnCode);
RETURN_ENUM_DESC(EndOfList, rc, ReturnCode);
RETURN_ENUM_DESC(InfoNotSupported, rc, ReturnCode);
RETURN_ENUM_DESC(DataNotAvailable, rc, ReturnCode);
RETURN_ENUM_DESC(Busy, rc, ReturnCode);
RETURN_ENUM_DESC(ScannerLocked, rc, ReturnCode);
{
swprintf(unk, L"%d", rc);
return unk;
}
}
const wchar_t* desc_condition_code(ConditionCode c, wchar_t unk[20])
{
RETURN_ENUM_DESC(Success, c, ConditionCode);
RETURN_ENUM_DESC(Bummer, c, ConditionCode);
RETURN_ENUM_DESC(LowMemory, c, ConditionCode);
RETURN_ENUM_DESC(NoDs, c, ConditionCode);
RETURN_ENUM_DESC(MaxConnections, c, ConditionCode);
RETURN_ENUM_DESC(OperationError, c, ConditionCode);
RETURN_ENUM_DESC(BadCap, c, ConditionCode);
RETURN_ENUM_DESC(BadProtocol, c, ConditionCode);
RETURN_ENUM_DESC(BadValue, c, ConditionCode);
RETURN_ENUM_DESC(SeqError, c, ConditionCode);
RETURN_ENUM_DESC(BadDest, c, ConditionCode);
RETURN_ENUM_DESC(CapUnsupported, c, ConditionCode);
RETURN_ENUM_DESC(CapBadOperation, c, ConditionCode);
RETURN_ENUM_DESC(CapSeqError, c, ConditionCode);
RETURN_ENUM_DESC(Denied, c, ConditionCode);
RETURN_ENUM_DESC(FileExists, c, ConditionCode);
RETURN_ENUM_DESC(FileNotFound, c, ConditionCode);
RETURN_ENUM_DESC(NotEmpty, c, ConditionCode);
RETURN_ENUM_DESC(PaperJam, c, ConditionCode);
RETURN_ENUM_DESC(PaperDoubleFeed, c, ConditionCode);
RETURN_ENUM_DESC(FileWriteError, c, ConditionCode);
RETURN_ENUM_DESC(CheckDeviceOnline, c, ConditionCode);
RETURN_ENUM_DESC(InterLock, c, ConditionCode);
RETURN_ENUM_DESC(DamagedCorner, c, ConditionCode);
RETURN_ENUM_DESC(FocusError, c, ConditionCode);
RETURN_ENUM_DESC(DocTooLight, c, ConditionCode);
RETURN_ENUM_DESC(DocTooDark, c, ConditionCode);
RETURN_ENUM_DESC(NoMedia, c, ConditionCode);
{
swprintf(unk, L"%d", c);
return unk;
}
}
template<typename T> template<typename T>
static Result oneValGet(Msg msg, Capability& data, const T& value) { static Result oneValGet(Msg msg, Capability& data, const T& value) {
switch (msg) { switch (msg) {
@ -668,7 +853,7 @@ static const SCANNERID scanner_guid = MAKE_SCANNER_ID(PRODUCT_PID, PRODUCT_VID);
static std::once_flag oc; static std::once_flag oc;
huagao_ds::huagao_ds() : cur_head_(NULL), dpi_(200) huagao_ds::huagao_ds() : cur_head_(NULL), dpi_(200), log_all_triple_(false)
{ {
//std::call_once(oc, [&]() { log4cplus::Initializer(); }); //std::call_once(oc, [&]() { log4cplus::Initializer(); });
} }
@ -866,6 +1051,7 @@ Result huagao_ds::identityOpenDs(const Identity& id)
cur_head_ = new SANE_Parameters; cur_head_ = new SANE_Parameters;
memset(cur_head_, 0, sizeof(SANE_Parameters)); memset(cur_head_, 0, sizeof(SANE_Parameters));
} }
log_all_triple_ = get_config_number(L"twain-app", L"log-all-triple") == 1;
m_compression = Compression::None; m_compression = Compression::None;
init_support_caps(); init_support_caps();
@ -1417,7 +1603,16 @@ Result huagao_ds::call(const Identity& origin, DataGroup dg, Dat dat, Msg msg, v
notifyXferReady(); notifyXferReady();
} }
return Base::call(origin, dg, dat, msg, data); Result rt;
rt = Base::call(origin, dg, dat, msg, data);
if(log_all_triple_ || (int)rt.returnCode())
{
wchar_t buf[128] = { 0 }, dgs[20] = { 0 }, dts[20] = { 0 }, ms[20] = { 0 }, ss[20] = { 0 }, rcs[20] = { 0 }, cs[20] = { 0 };
swprintf_s(buf, _countof(buf) - 1, L"[%x - %s]DSEntry(%s, %s, %s) = {%s, %s}\r\n", GetCurrentThreadId(), desc_state(state(), ss),
desc_data_group(dg, dgs), desc_data(dat, dts), desc_msg(msg, ms), desc_return_code(rt, rcs), desc_condition_code((ConditionCode)(Status)rt, cs));
load_sane_util::log_info(buf, 0);
}
return rt;
} }
catch (const CapabilityException& e) { catch (const CapabilityException& e) {
//FileTools::writelog(log_ERROR, e.what()); //FileTools::writelog(log_ERROR, e.what());

View File

@ -42,6 +42,7 @@ class huagao_ds : public Twpp::SourceFromThis<huagao_ds> {
Twpp::Compression m_compression = Twpp::Compression::None; Twpp::Compression m_compression = Twpp::Compression::None;
SANE_Parameters* cur_head_; SANE_Parameters* cur_head_;
int dpi_; int dpi_;
bool log_all_triple_;
static std::string get_hidedlg_path(void); static std::string get_hidedlg_path(void);
static void showmsg(const char* msg, int err); static void showmsg(const char* msg, int err);