2022-05-23 03:52:53 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <string>
|
|
|
|
#include <stdio.h>
|
2022-07-18 08:56:03 +00:00
|
|
|
#if defined(WIN32) || defined(_WIN64)
|
2022-05-23 03:52:53 +00:00
|
|
|
#define bzero(b, s) memset(b, 0, s)
|
|
|
|
#else
|
|
|
|
#include <iconv.h>
|
|
|
|
#endif
|
|
|
|
#include "../sdk/hginclude/huagaoxxx_warraper_ex.h"
|
|
|
|
#include "sane/sane_ex.h"
|
|
|
|
#include "json.h"
|
2023-07-11 10:04:26 +00:00
|
|
|
#include <memory>
|
2022-05-23 03:52:53 +00:00
|
|
|
|
|
|
|
namespace local_utility
|
|
|
|
{
|
|
|
|
void* acquire_memory(size_t bytes, const char* info);
|
|
|
|
void free_memory(void* m);
|
2023-07-11 10:04:26 +00:00
|
|
|
|
|
|
|
template<typename ... Args>
|
|
|
|
void to_log(int level, const char* fmt, Args ... args)
|
|
|
|
{
|
|
|
|
size_t size = snprintf(nullptr, 0, fmt, args ...) + 2;
|
|
|
|
std::unique_ptr<char[]> buf(new char[size]);
|
|
|
|
|
|
|
|
snprintf(buf.get(), size, fmt, args ...);
|
|
|
|
hg_scanner_log(buf.get(), level);
|
|
|
|
}
|
2022-05-23 03:52:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class sane_std_opts
|
|
|
|
{
|
|
|
|
typedef struct _sane_opt
|
|
|
|
{
|
|
|
|
SANE_Option_Descriptor* desc;
|
|
|
|
int opt;
|
|
|
|
}SANEOPT;
|
|
|
|
typedef struct _opt_map
|
|
|
|
{
|
|
|
|
SANEOPT known;
|
|
|
|
SANEOPT user;
|
2022-06-15 03:05:36 +00:00
|
|
|
std::string init;
|
2022-05-23 03:52:53 +00:00
|
|
|
}OPTMAP;
|
|
|
|
std::vector<OPTMAP> known_opts_;
|
|
|
|
int opt_num_base_;
|
|
|
|
int page_width_;
|
|
|
|
int page_height_;
|
|
|
|
|
|
|
|
SANE_Option_Descriptor* get_known_option(int opt, int* ind = nullptr);
|
|
|
|
SANE_Option_Descriptor* get_known_option(const char* name, int* ind = nullptr);
|
|
|
|
void to_known_opt_value(OPTMAP* opmap, const void* data, void* known_data);
|
|
|
|
void* from_known_opt_value(OPTMAP* opmap, const void* known_data, long* len);
|
|
|
|
|
|
|
|
public:
|
|
|
|
sane_std_opts(int opt_base);
|
|
|
|
~sane_std_opts();
|
|
|
|
|
|
|
|
public:
|
|
|
|
static json* get_opt_json(scanner_handle h, int opt); // call delete to free the returned object
|
|
|
|
static void* get_current_value(scanner_handle h, int opt); // call local_utility::free_memory to free the returned buffer
|
|
|
|
|
|
|
|
public:
|
|
|
|
void init_known_opt(int option, SANE_Option_Descriptor* desc);
|
|
|
|
SANE_Option_Descriptor* get_option(int option);
|
2023-06-19 10:40:05 +00:00
|
|
|
void clear(void);
|
2022-05-23 03:52:53 +00:00
|
|
|
|
|
|
|
bool is_known_option(int opt, SANE_Option_Descriptor** user = nullptr);
|
2022-06-15 03:05:36 +00:00
|
|
|
void* get_default_value(scanner_handle h, int opt); // call local_utility::free_memory to free the returned buffer
|
2022-05-23 03:52:53 +00:00
|
|
|
scanner_err get_value(scanner_handle h, int opt, void* buf); // call this ONLY when is_known_option returnning true
|
|
|
|
scanner_err set_value(scanner_handle h, int opt, void* buf); // call this ONLY when is_known_option returnning true
|
|
|
|
};
|