code_device/hgsane/sane_opt/sane_opts.h

67 lines
1.3 KiB
C
Raw Normal View History

// sane_opts.h : include file for options of SANE
#pragma once
#include <string>
#include <vector>
#include <map>
#include <sane/sane_ex.h>
#define FIXED_ID_BASE 0x8000
class gb_json;
// For: option json to SANE_Option_Descriptor*, and depends logic
//
// NOTE: re-call method 'from_json_text' if language was changed
class sane_opt
{
int fix_id_;
int sn_;
bool enabled_;
SANE_Option_Descriptor opt_desc_;
void clear();
void set_opt_desc_string_value(char** buf, const char* val);
void init_cap(gb_json* jsn);
void init_range(gb_json* jsn);
public:
sane_opt();
~sane_opt();
public:
int get_fix_id(void);
int get_sn(void);
SANE_Option_Descriptor* get_descriptor(void);
const char* name(void);
bool is_enabled(void);
bool from_json_text(int sn, const char* key, const char* json, void(*err_msg)(const char*) = nullptr);
};
class device_opts
{
std::map<int, sane_opt*> opts_;
int opt_cnt_;
SANE_Option_Descriptor opt_0_;
void clear(void);
bool add_or_replace_opt(int sn, const char* name, const char* jsn_text, void(*err_msg)(const char*));
public:
device_opts();
~device_opts();
public:
bool init_from(const char* jsn_text/*all options*/, void(*err_msg)(const char*));
SANE_Option_Descriptor* get_opt_descriptor(const void* opt, int* fix_id = nullptr);
int get_option_count(void);
};