Skip to content

Commit f71ca1c

Browse files
author
Thomas Perret
committed
Merge branch 'wip-cache' into 'master'
Reduce requests to underlying API Closes openpaperwork#1 See merge request World/OpenPaperwork/libinsane!6
2 parents a5d7c7a + 71c7d07 commit f71ca1c

23 files changed

Lines changed: 921 additions & 31 deletions

subprojects/libinsane/include/libinsane/dumb.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void lis_dumb_set_list_devices_return(struct lis_api *self, enum lis_error ret);
2929
void lis_dumb_set_get_device_return(struct lis_api *self, enum lis_error ret);
3030

3131
void lis_dumb_add_option(struct lis_api *self, const struct lis_option_descriptor *opt,
32-
const union lis_value *default_value);
32+
const union lis_value *default_value, int set_flags);
3333

3434
struct lis_dumb_read {
3535
const void *content;
@@ -45,6 +45,8 @@ void lis_dumb_set_scan_result(
4545
);
4646
int lis_dumb_get_nb_get(struct lis_api *self);
4747
int lis_dumb_get_nb_set(struct lis_api *self);
48+
int lis_dumb_get_nb_list_options(struct lis_api *self);
49+
4850

4951
#ifdef __cplusplus
5052
}

subprojects/libinsane/include/libinsane/workarounds.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,26 @@ extern enum lis_error lis_api_workaround_one_page_flatbed(
172172
struct lis_api *to_wrap, struct lis_api **out_impl
173173
);
174174

175+
176+
/*!
177+
* \brief Minimize calls to underlying API
178+
*
179+
* - API: Sane (maybe others)
180+
* - Culprit: HP drivers + sane backend 'net' (+ difference of versions
181+
* between servers and clients) (maybe
182+
* others)
183+
*
184+
* Some drivers or combinations of drivers seem to be very touchy. This
185+
* workaround aim to reduce to a strict minimum all the calls to
186+
* list_options(), option->fn.set(), option->fn.get().
187+
*
188+
* Assumes that the 'set_fllags' when calling option->fn.set() is reliable.
189+
*/
190+
extern enum lis_error lis_api_workaround_cache(
191+
struct lis_api *to_wrap, struct lis_api **out_impl
192+
);
193+
194+
175195
#ifdef __cplusplus
176196
}
177197
#endif

subprojects/libinsane/src/bases/dumb.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
struct lis_dumb_option {
1717
struct lis_option_descriptor parent;
1818
struct lis_dumb_private *impl;
19+
int set_flags;
1920

2021
int has_value;
2122
union lis_value default_value;
@@ -62,6 +63,7 @@ struct lis_dumb_private {
6263
} scan;
6364

6465
struct {
66+
int list;
6567
int set;
6668
int get;
6769
} nb;
@@ -270,7 +272,7 @@ static enum lis_error dumb_opt_set_value(struct lis_option_descriptor *self,
270272
lis_copy(self->value.type, &value, &private->value);
271273
private->has_value = 1;
272274

273-
*set_flags = LIS_SET_FLAG_MUST_RELOAD_PARAMS;
275+
*set_flags = private->set_flags;
274276
return LIS_OK;
275277
}
276278

@@ -280,6 +282,7 @@ static enum lis_error dumb_get_options(
280282
)
281283
{
282284
struct lis_dumb_item *private = LIS_DUMB_ITEM(self);
285+
private->impl->nb.list++;
283286
*out_descs = private->impl->opts;
284287
return LIS_OK;
285288
}
@@ -406,7 +409,7 @@ void lis_dumb_set_get_device_return(struct lis_api *self, enum lis_error ret)
406409

407410

408411
void lis_dumb_add_option(struct lis_api *self, const struct lis_option_descriptor *opt,
409-
const union lis_value *default_value)
412+
const union lis_value *default_value, int set_flags)
410413
{
411414

412415
struct lis_dumb_private *private = LIS_DUMB_PRIVATE(self);
@@ -415,6 +418,7 @@ void lis_dumb_add_option(struct lis_api *self, const struct lis_option_descripto
415418

416419
opt_private = calloc(1, sizeof(struct lis_dumb_option));
417420
opt_private->impl = private;
421+
opt_private->set_flags = set_flags;
418422
memcpy(&opt_private->parent, opt, sizeof(opt_private->parent));
419423
if (opt_private->parent.fn.get_value == NULL) {
420424
opt_private->parent.fn.get_value = dumb_opt_get_value;
@@ -523,3 +527,10 @@ int lis_dumb_get_nb_set(struct lis_api *self)
523527
struct lis_dumb_private *private = LIS_DUMB_PRIVATE(self);
524528
return private->nb.set;
525529
}
530+
531+
532+
int lis_dumb_get_nb_list_options(struct lis_api *self)
533+
{
534+
struct lis_dumb_private *private = LIS_DUMB_PRIVATE(self);
535+
return private->nb.list;
536+
}

subprojects/libinsane/src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ libinsane_srcs = files(
2121
'safebet.c',
2222
'str2impls.c',
2323
'util.c',
24+
'workarounds/cache.c',
2425
'workarounds/check_capabilities.c',
2526
'workarounds/dedicated_thread.c',
2627
'workarounds/one_page_flatbed.c',

subprojects/libinsane/src/safebet.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ static const struct {
3939
.wrap_cb = lis_api_workaround_check_capabilities,
4040
.enabled_by_default = 1,
4141
},
42+
{
43+
.name = "workaround_cache",
44+
.env = "LIBINSANE_WORKAROUND_CACHE",
45+
.wrap_cb = lis_api_workaround_cache,
46+
.enabled_by_default = 1,
47+
},
4248
{
4349
.name = "normalizer_source_nodes",
4450
.env = "LIBINSANE_NORMALIZER_SOURCE_NODES",

subprojects/libinsane/src/str2impls.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ enum lis_error lis_str2impls(const char *list_of_impls, struct lis_api **impls)
101101
err = lis_api_workaround_opt_values(*impls, &next);
102102
} else if (strcmp(tok, "one_page_flatbed") == 0) {
103103
err = lis_api_workaround_one_page_flatbed(*impls, &next);
104+
} else if (strcmp(tok, "cache") == 0) {
105+
err = lis_api_workaround_cache(*impls, &next);
104106
} else {
105107
lis_log_error("Unknown API wrapper: %s", tok);
106108
err = LIS_ERR_INTERNAL_NOT_IMPLEMENTED;
@@ -109,7 +111,7 @@ enum lis_error lis_str2impls(const char *list_of_impls, struct lis_api **impls)
109111
}
110112

111113
if (LIS_IS_ERROR(err)) {
112-
lis_log_error("Failed to instanciate API implementation '%s'", tok);
114+
lis_log_error("Failed to instantiate API implementation '%s'", tok);
113115
goto error;
114116
}
115117

0 commit comments

Comments
 (0)