code_device/hgsane/sane_opt/sane_opts.h

74 lines
2.0 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_;
bool enabled_;
bool visible_;
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();
static std::string readable_text(const char* type, void* value);
static std::string readable_text(SANE_Value_Type type, void* value);
public:
int get_fix_id(void);
SANE_Option_Descriptor* get_descriptor(void);
const char* name(void);
bool is_enabled(void);
bool is_visible(void);
bool from_json_text(const char* key, const char* json, void(*err_msg)(const char*) = nullptr);
2023-11-04 03:44:30 +00:00
bool from_json_object(gb_json* jsn, void(*err_msg)(const char*) = nullptr);
};
class sane_options
{
std::map<int, sane_opt*> opts_; // SANE_Int && fix-id point the same object. SANE_Int is visible and accessible, only accessible by fix-id if without SANE_Int
int opt_cnt_; // count for visible options
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*));
2023-11-04 03:44:30 +00:00
bool add_or_replace_opt(int& sn, gb_json* jsn, void(*err_msg)(const char*));
public:
sane_options();
~sane_options();
public:
2023-11-04 03:44:30 +00:00
// clear_prev: call from device openned or closed, should clear all options; call from SANE_RELOAD_xxx should keep the SANE_Option_Descriptor* stable
bool init_from(const char* jsn_text/*all options*/, void(*err_msg)(const char*), bool clear_prev);
2023-09-18 03:21:14 +00:00
SANE_Option_Descriptor* get_opt_descriptor(const void* opt, int* fix_id = nullptr, int ind_base = 0);
int get_option_count(void);
bool enum_invisible_fix_ids(struct _fix_id_cb* fcb); // return whether the callback stopped the enumeration
};