From fcf012d2925e620aeca5baf2e006d1f52a537627 Mon Sep 17 00:00:00 2001 From: Peter Kirchgessner Date: Mon, 23 Oct 2000 18:32:37 +0000 Subject: [PATCH] Change sanei_debug-interface Allocate accessor only once (for fixed size accessors) --- backend/hp-accessor.c | 6 +- backend/hp-device.c | 5 +- backend/hp-handle.c | 7 +- backend/hp-hpmem.c | 5 +- backend/hp-option.c | 176 ++++++++++++++++++++++++++++++++---------- backend/hp-scl.c | 5 +- backend/hp.c | 7 +- backend/hp.h | 1 + 8 files changed, 162 insertions(+), 50 deletions(-) diff --git a/backend/hp-accessor.c b/backend/hp-accessor.c index eaf4a6b30..ebab15f56 100644 --- a/backend/hp-accessor.c +++ b/backend/hp-accessor.c @@ -42,8 +42,10 @@ HP Scanner Control Language (SCL). */ -#define STUBS -extern int sanei_debug_hp; +/* #define STUBS +extern int sanei_debug_hp; */ +#define DEBUG_DECLARE_ONLY + #include "sane/config.h" #include diff --git a/backend/hp-device.c b/backend/hp-device.c index a16cb8008..308eee2c7 100644 --- a/backend/hp-device.c +++ b/backend/hp-device.c @@ -42,8 +42,9 @@ HP Scanner Control Language (SCL). */ -#define STUBS -extern int sanei_debug_hp; +/*#define STUBS +extern int sanei_debug_hp;*/ +#define DEBUG_DECLARE_ONLY #include "sane/config.h" #include diff --git a/backend/hp-handle.c b/backend/hp-handle.c index 57d914a45..111cfb332 100644 --- a/backend/hp-handle.c +++ b/backend/hp-handle.c @@ -42,8 +42,9 @@ HP Scanner Control Language (SCL). */ -#define STUBS -extern int sanei_debug_hp; +/* #define STUBS +extern int sanei_debug_hp; */ +#define DEBUG_DECLARE_ONLY #include "sane/config.h" #ifdef HAVE_UNISTD_H @@ -441,12 +442,14 @@ sanei_hp_handle_startScan (HpHandle this) != SANE_STATUS_GOOD ) { DBG(1, "start: Error checking if ADF is ready\n"); + sanei_hp_scsi_destroy(scsi,0); return SANE_STATUS_UNSUPPORTED; } if ( adfstat != 1 ) { DBG(1, "start: ADF scan requested without paper. Finished.\n"); + sanei_hp_scsi_destroy(scsi,0); return SANE_STATUS_NO_DOCS; } } diff --git a/backend/hp-hpmem.c b/backend/hp-hpmem.c index 815cf3585..75e035529 100644 --- a/backend/hp-hpmem.c +++ b/backend/hp-hpmem.c @@ -41,9 +41,10 @@ This file is part of a SANE backend for HP Scanners supporting HP Scanner Control Language (SCL). */ - +/* #define STUBS -extern int sanei_debug_hp; +extern int sanei_debug_hp;*/ +#define DEBUG_DECLARE_ONLY #include "sane/config.h" #include diff --git a/backend/hp-option.c b/backend/hp-option.c index 35e741412..6d7981ff9 100644 --- a/backend/hp-option.c +++ b/backend/hp-option.c @@ -49,11 +49,14 @@ #endif #endif +/* To be done: dont reallocate choice accessors */ +/* #define HP_ALLOC_CHOICEACC_ONCE 1 */ /* #define HP_EXPERIMENTAL -*/ +*/ /* #define STUBS -extern int sanei_debug_hp; +extern int sanei_debug_hp; */ +#define DEBUG_DECLARE_ONLY #include "sane/config.h" #include @@ -742,8 +745,12 @@ _probe_int (_HpOption this, HpScsi scsi, HpOptSet optset, HpData data) if (minval >= maxval) return SANE_STATUS_UNSUPPORTED; - if (!(this->data_acsr = sanei_hp_accessor_int_new(data))) - return SANE_STATUS_NO_MEM; + /* If we dont have an accessor, get one */ + if (!this->data_acsr) + { + if (!(this->data_acsr = sanei_hp_accessor_int_new(data))) + return SANE_STATUS_NO_MEM; + } sanei_hp_accessor_setint(this->data_acsr, data, val); _set_size(this, data, sizeof(SANE_Int)); return _set_range(this, data, minval, 1, maxval); @@ -779,8 +786,13 @@ _probe_int_brightness (_HpOption this, HpScsi scsi, HpOptSet optset, if (minval >= maxval) return SANE_STATUS_UNSUPPORTED; - if (!(this->data_acsr = sanei_hp_accessor_int_new(data))) - return SANE_STATUS_NO_MEM; + /* If we dont have an accessor, get one */ + if (!this->data_acsr) + { + if (!(this->data_acsr = sanei_hp_accessor_int_new(data))) + return SANE_STATUS_NO_MEM; + } + sanei_hp_accessor_setint(this->data_acsr, data, val); _set_size(this, data, sizeof(SANE_Int)); return _set_range(this, data, minval, 1, maxval); @@ -851,8 +863,13 @@ _probe_bool (_HpOption this, HpScsi scsi, HpOptSet optset, HpData data) if (scl) RETURN_IF_FAIL( sanei_hp_scl_inquire(scsi, scl, &val, 0, 0) ); - if (!(this->data_acsr = sanei_hp_accessor_bool_new(data))) - return SANE_STATUS_NO_MEM; + /* If we dont have an accessor, get one */ + if (!this->data_acsr) + { + if (!(this->data_acsr = sanei_hp_accessor_bool_new(data))) + return SANE_STATUS_NO_MEM; + } + sanei_hp_accessor_setint(this->data_acsr, data, val); _set_size(this, data, sizeof(SANE_Bool)); return SANE_STATUS_GOOD; @@ -877,8 +894,13 @@ _probe_change_doc (_HpOption this, HpScsi scsi, HpOptSet optset, HpData data) if ( status != SANE_STATUS_GOOD ) return SANE_STATUS_UNSUPPORTED; - if (!(this->data_acsr = sanei_hp_accessor_bool_new(data))) - return SANE_STATUS_NO_MEM; + /* If we dont have an accessor, get one */ + if (!this->data_acsr) + { + if (!(this->data_acsr = sanei_hp_accessor_bool_new(data))) + return SANE_STATUS_NO_MEM; + } + sanei_hp_accessor_setint(this->data_acsr, data, cap); _set_size(this, data, sizeof(SANE_Bool)); @@ -907,8 +929,13 @@ _probe_unload (_HpOption this, HpScsi scsi, HpOptSet optset, HpData data) if ( status != SANE_STATUS_GOOD ) return SANE_STATUS_UNSUPPORTED; - if (!(this->data_acsr = sanei_hp_accessor_bool_new(data))) - return SANE_STATUS_NO_MEM; + /* If we dont have an accessor, get one */ + if (!this->data_acsr) + { + if (!(this->data_acsr = sanei_hp_accessor_bool_new(data))) + return SANE_STATUS_NO_MEM; + } + sanei_hp_accessor_setint(this->data_acsr, data, cap); _set_size(this, data, sizeof(SANE_Bool)); @@ -947,8 +974,13 @@ _probe_calibrate (_HpOption this, HpScsi scsi, HpOptSet optset, HpData data) /* And the desired ID of 10963 does not work. So we have to trust */ /* the evaluated HP model number. */ - if (!(this->data_acsr = sanei_hp_accessor_bool_new(data))) - return SANE_STATUS_NO_MEM; + /* If we dont have an accessor, get one */ + if (!this->data_acsr) + { + if (!(this->data_acsr = sanei_hp_accessor_bool_new(data))) + return SANE_STATUS_NO_MEM; + } + sanei_hp_accessor_setint(this->data_acsr, data, val); _set_size(this, data, sizeof(SANE_Bool)); @@ -1075,8 +1107,12 @@ _probe_choice (_HpOption this, HpScsi scsi, HpOptSet optset, HpData data) if (!choices) return SANE_STATUS_UNSUPPORTED; - this->data_acsr = sanei_hp_accessor_choice_new(data, choices, - this->descriptor->may_change); + /* If no accessor, create one here. */ +#ifdef HP_ALLOC_CHOICEACC_ONCE + if (!(this->data_acsr)) +#endif + this->data_acsr = sanei_hp_accessor_choice_new(data, choices, + this->descriptor->may_change); if (!(this->data_acsr)) return SANE_STATUS_NO_MEM; @@ -1118,9 +1154,16 @@ _probe_each_choice (_HpOption this, HpScsi scsi, HpOptSet optset, HpData data) if (!choices) return SANE_STATUS_UNSUPPORTED; - if (!(this->data_acsr = sanei_hp_accessor_choice_new(data, choices, - this->descriptor->may_change ))) - return SANE_STATUS_NO_MEM; + /* If we dont have an accessor, get one */ +#ifdef HP_ALLOC_CHOICEACC_ONCE + if (!this->data_acsr) +#endif + { + if (!(this->data_acsr = sanei_hp_accessor_choice_new(data, choices, + this->descriptor->may_change ))) + return SANE_STATUS_NO_MEM; + } + sanei_hp_accessor_setint(this->data_acsr, data, val); _set_stringlist(this, data, @@ -1146,9 +1189,16 @@ _probe_ps_exposure_time (_HpOption this, HpScsi scsi, HpOptSet optset, info = sanei_hp_device_info_get ( sanei_hp_scsi_devicename (scsi) ); - if (!(this->data_acsr = sanei_hp_accessor_choice_new(data, choices, - this->descriptor->may_change ))) - return SANE_STATUS_NO_MEM; + /* If we dont have an accessor, get one */ +#ifdef HP_ALLOC_CHOICEACC_ONCE + if (!this->data_acsr) +#endif + { + if (!(this->data_acsr = sanei_hp_accessor_choice_new(data, choices, + this->descriptor->may_change ))) + return SANE_STATUS_NO_MEM; + } + sanei_hp_accessor_setint(this->data_acsr, data, val); _set_stringlist(this, data, @@ -1211,9 +1261,16 @@ _probe_scan_type (_HpOption this, HpScsi scsi, HpOptSet optset, info = sanei_hp_device_info_get ( sanei_hp_scsi_devicename (scsi) ); - if (!(this->data_acsr = sanei_hp_accessor_choice_new(data, choices, - this->descriptor->may_change ))) - return SANE_STATUS_NO_MEM; + /* If we dont have an accessor, get one */ +#ifdef HP_ALLOC_CHOICEACC_ONCE + if (!this->data_acsr) +#endif + { + if (!(this->data_acsr = sanei_hp_accessor_choice_new(data, choices, + this->descriptor->may_change ))) + return SANE_STATUS_NO_MEM; + } + sanei_hp_accessor_setint(this->data_acsr, data, val); _set_stringlist(this, data, @@ -1248,9 +1305,16 @@ _probe_mirror_horiz (_HpOption this, HpScsi scsi, HpOptSet optset, HpData data) if (!choices) return SANE_STATUS_UNSUPPORTED; - if (!(this->data_acsr = sanei_hp_accessor_choice_new(data, choices, - this->descriptor->may_change ))) - return SANE_STATUS_NO_MEM; + /* If we dont have an accessor, get one */ +#ifdef HP_ALLOC_CHOICEACC_ONCE + if (!this->data_acsr) +#endif + { + if (!(this->data_acsr = sanei_hp_accessor_choice_new(data, choices, + this->descriptor->may_change ))) + return SANE_STATUS_NO_MEM; + } + sanei_hp_accessor_setint(this->data_acsr, data, val); _set_stringlist(this, data, @@ -1284,9 +1348,16 @@ _probe_mirror_vert (_HpOption this, HpScsi scsi, HpOptSet optset, HpData data) if (!choices) return SANE_STATUS_UNSUPPORTED; - if (!(this->data_acsr = sanei_hp_accessor_choice_new(data, choices, - this->descriptor->may_change ))) - return SANE_STATUS_NO_MEM; + /* If we dont have an accessor, get one */ +#ifdef HP_ALLOC_CHOICEACC_ONCE + if (!this->data_acsr) +#endif + { + if (!(this->data_acsr = sanei_hp_accessor_choice_new(data, choices, + this->descriptor->may_change ))) + return SANE_STATUS_NO_MEM; + } + sanei_hp_accessor_setint(this->data_acsr, data, val); _set_stringlist(this, data, @@ -1309,8 +1380,12 @@ static SANE_Status _probe_front_button(_HpOption this, HpScsi scsi, _set_size(this, data, sizeof(SANE_Bool)); - if ( !(this->data_acsr = sanei_hp_accessor_bool_new(data)) ) - return SANE_STATUS_NO_MEM; + /* If we dont have an accessor, get one */ + if (!this->data_acsr) + { + if ( !(this->data_acsr = sanei_hp_accessor_bool_new(data)) ) + return SANE_STATUS_NO_MEM; + } sanei_hp_accessor_setint(this->data_acsr, data, 0); @@ -1422,8 +1497,13 @@ _probe_custom_gamma (_HpOption this, HpScsi scsi, HpOptSet optset, RETURN_IF_FAIL( sanei_hp_scl_inquire(scsi, scl, &val, 0, 0) ); } - if (!(this->data_acsr = sanei_hp_accessor_bool_new(data))) - return SANE_STATUS_NO_MEM; + /* If we dont have an accessor, get one */ + if (!this->data_acsr) + { + if (!(this->data_acsr = sanei_hp_accessor_bool_new(data))) + return SANE_STATUS_NO_MEM; + } + sanei_hp_accessor_setint(this->data_acsr, data, val); _set_size(this, data, sizeof(SANE_Bool)); return SANE_STATUS_GOOD; @@ -1479,7 +1559,13 @@ _probe_vector (_HpOption this, HpScsi scsi, HpOptSet optset, HpData data) assert(type->scl); RETURN_IF_FAIL ( _probe_download_type (scl, scsi) ); - this->data_acsr = (*type->creator)(data, type->length, type->depth); + /* If we dont have an accessor, get one */ +#ifdef HP_ALLOC_CHOICEACC_ONCE + if (!this->data_acsr) +#endif + { + this->data_acsr = (*type->creator)(data, type->length, type->depth); + } } else { @@ -1494,8 +1580,14 @@ _probe_vector (_HpOption this, HpScsi scsi, HpOptSet optset, HpData data) super = hp_optset_get(optset, type->super); assert(super); - this->data_acsr = sanei_hp_accessor_subvector_new( - (HpAccessorVector) super->data_acsr, type->nchan, type->chan); + /* If we dont have an accessor, get one */ +#ifdef HP_ALLOC_CHOICEACC_ONCE + if (!this->data_acsr) +#endif + { + this->data_acsr = sanei_hp_accessor_subvector_new( + (HpAccessorVector) super->data_acsr, type->nchan, type->chan); + } } if (!this->data_acsr) @@ -1575,8 +1667,12 @@ _probe_matrix (_HpOption this, HpScsi scsi, HpOptSet optset, HpData data) static SANE_Status _probe_num_options (_HpOption this, HpScsi scsi, HpOptSet optset, HpData data) { - if (!(this->data_acsr = sanei_hp_accessor_int_new(data))) - return SANE_STATUS_NO_MEM; + /* If we dont have an accessor, get one */ + if (!this->data_acsr) + { + if (!(this->data_acsr = sanei_hp_accessor_int_new(data))) + return SANE_STATUS_NO_MEM; + } _set_size(this, data, sizeof(SANE_Int)); return SANE_STATUS_GOOD; } diff --git a/backend/hp-scl.c b/backend/hp-scl.c index 1a12f2ce5..be83d1598 100644 --- a/backend/hp-scl.c +++ b/backend/hp-scl.c @@ -42,8 +42,10 @@ HP Scanner Control Language (SCL). */ +/* #define STUBS -extern int sanei_debug_hp; +extern int sanei_debug_hp;*/ +#define DEBUG_DECLARE_ONLY #include "sane/config.h" #include /* Must be first */ @@ -51,6 +53,7 @@ extern int sanei_debug_hp; # include #endif #include +#include #include #include #include diff --git a/backend/hp.c b/backend/hp.c index 3628e04d4..de30a2b2b 100644 --- a/backend/hp.c +++ b/backend/hp.c @@ -43,9 +43,14 @@ HP Scanner Control Language (SCL). */ -static char *hp_backend_version = "0.91"; +static char *hp_backend_version = "0.92"; /* Changes: + V 0.92, 03-Oct-2000, Rupert W. Curwen (rcurwen@uk.research.att.com): + - try to not allocate accessors twice (only for accessors + that have fixed length) + - fix problem with leaving connection open for some error conditions + V 0.91, 04-Sep-2000, David Paschal (paschal@rcsis.com): - Added support for flatbed HP OfficeJets - (PK) fix problem with cancel preview diff --git a/backend/hp.h b/backend/hp.h index e0e3f85b8..015a2b500 100644 --- a/backend/hp.h +++ b/backend/hp.h @@ -50,6 +50,7 @@ #undef BACKEND_NAME #define BACKEND_NAME hp +#define DEBUG_NOT_STATIC #include "sane/sanei_debug.h" /* FIXME: these should be options? */