genesys: Return bool out of *_is_compatible_calibration()

merge-requests/84/head
Povilas Kanapickas 2019-06-30 14:05:16 +03:00
rodzic eaa4cb7766
commit 1685e6e863
5 zmienionych plików z 25 dodań i 55 usunięć

Wyświetl plik

@ -3047,11 +3047,7 @@ genesys_restore_calibration(Genesys_Device * dev, Genesys_Sensor& sensor)
* matching one */
for (auto& cache : dev->calibration_cache)
{
status = dev->model->cmd_set->is_compatible_calibration(dev, sensor, &cache, SANE_FALSE);
/* SANE_STATUS_GOOD, a matching cache has been found
* so we use it to populate calibration data
*/
if (status == SANE_STATUS_GOOD)
if (dev->model->cmd_set->is_compatible_calibration(dev, sensor, &cache, SANE_FALSE))
{
dev->frontend = cache.frontend;
/* we don't restore the gamma fields */
@ -3078,15 +3074,6 @@ genesys_restore_calibration(Genesys_Device * dev, Genesys_Sensor& sensor)
DBG(DBG_proc, "%s: restored\n", __func__);
return SANE_STATUS_GOOD;
}
/* here status is either SANE_STATUS_UNSUPPORTED which mean tested cache
* entry doesn't match, or an fatal error */
if (status != SANE_STATUS_UNSUPPORTED)
{
DBG(DBG_error, "%s: fail while checking compatibility: %s\n", __func__,
sane_strstatus(status));
return status;
}
}
DBG(DBG_proc, "%s: completed(nothing found)\n", __func__);
return SANE_STATUS_UNSUPPORTED;
@ -3096,8 +3083,6 @@ genesys_restore_calibration(Genesys_Device * dev, Genesys_Sensor& sensor)
static SANE_Status
genesys_save_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor)
{
SANE_Status status = SANE_STATUS_UNSUPPORTED;
#ifdef HAVE_SYS_TIME_H
struct timeval time;
#endif
@ -3111,19 +3096,11 @@ genesys_save_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor)
for (auto cache_it = dev->calibration_cache.begin(); cache_it != dev->calibration_cache.end();
cache_it++)
{
status = dev->model->cmd_set->is_compatible_calibration(dev, sensor, &*cache_it, SANE_TRUE);
if (status == SANE_STATUS_UNSUPPORTED)
if (dev->model->cmd_set->is_compatible_calibration(dev, sensor, &*cache_it, SANE_TRUE))
{
continue;
found_cache_it = cache_it;
break;
}
else if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: fail while checking compatibility: %s\n", __func__,
sane_strstatus(status));
return status;
}
found_cache_it = cache_it;
break;
}
/* if we found on overridable cache, we reuse it */
@ -6753,8 +6730,7 @@ get_option_value (Genesys_Scanner * s, int option, void *val)
*(SANE_Bool *) val = SANE_TRUE;
for (auto& cache : s->dev->calibration_cache)
{
if (s->dev->model->
cmd_set->is_compatible_calibration(s->dev, sensor, &cache, SANE_FALSE) == SANE_STATUS_GOOD)
if (s->dev->model->cmd_set->is_compatible_calibration(s->dev, sensor, &cache, SANE_FALSE))
{
*(SANE_Bool *) val = SANE_FALSE;
}

Wyświetl plik

@ -4648,13 +4648,13 @@ write_control (Genesys_Device * dev, const Genesys_Sensor& sensor, int resolutio
/**
* check if a stored calibration is compatible with requested scan.
* @return SANE_STATUS_GOOD if compatible, SANE_STATUS_UNSUPPORTED if not.
* @return true if compatible, false if not.
* Whenever an error is met, it is returned.
* @param dev scanner device
* @param cache cache entry to test
* @param for_overwrite reserved for future use ...
*/
static SANE_Status
static bool
gl646_is_compatible_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor,
Genesys_Calibration_Cache * cache,
int for_overwrite)
@ -4668,7 +4668,7 @@ gl646_is_compatible_calibration (Genesys_Device * dev, const Genesys_Sensor& sen
DBG(DBG_proc, "%s: start (for_overwrite=%d)\n", __func__, for_overwrite);
if (cache == NULL)
return SANE_STATUS_UNSUPPORTED;
return false;
/* build minimal current_setup for calibration cache use only, it will be better
* computed when during setup for scan
@ -4710,7 +4710,7 @@ gl646_is_compatible_calibration (Genesys_Device * dev, const Genesys_Sensor& sen
if (!compatible)
{
DBG(DBG_proc, "%s: completed, non compatible cache\n", __func__);
return SANE_STATUS_UNSUPPORTED;
return false;
}
/* a cache entry expires after 30 minutes for non sheetfed scanners */
@ -4723,13 +4723,13 @@ gl646_is_compatible_calibration (Genesys_Device * dev, const Genesys_Sensor& sen
&& (dev->model->is_sheetfed == SANE_FALSE))
{
DBG(DBG_proc, "%s: expired entry, non compatible cache\n", __func__);
return SANE_STATUS_UNSUPPORTED;
return false;
}
}
#endif
DBG(DBG_proc, "%s: completed, cache compatible\n", __func__);
return SANE_STATUS_GOOD;
return true;
}
/**

Wyświetl plik

@ -4920,7 +4920,7 @@ sanei_gl841_repark_head (Genesys_Device * dev)
return status;
}
static SANE_Status
static bool
gl841_is_compatible_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor,
Genesys_Calibration_Cache *cache,
int for_overwrite)
@ -4934,7 +4934,7 @@ gl841_is_compatible_calibration (Genesys_Device * dev, const Genesys_Sensor& sen
/* calibration cache not working yet for this model */
if (dev->model->ccd_type == CCD_PLUSTEK_3600)
{
return SANE_STATUS_UNSUPPORTED;
return false;
}
gl841_calculate_current_setup (dev, sensor);
@ -4942,7 +4942,7 @@ gl841_is_compatible_calibration (Genesys_Device * dev, const Genesys_Sensor& sen
DBG(DBG_proc, "%s: checking\n", __func__);
if (dev->current_setup.ccd_size_divisor != cache->used_setup.ccd_size_divisor)
return SANE_STATUS_UNSUPPORTED;
return false;
/* a cache entry expires after 30 minutes for non sheetfed scanners */
/* this is not taken into account when overwriting cache entries */
@ -4954,13 +4954,13 @@ gl841_is_compatible_calibration (Genesys_Device * dev, const Genesys_Sensor& sen
&& (dev->model->is_sheetfed == SANE_FALSE))
{
DBG(DBG_proc, "%s: expired entry, non compatible cache\n", __func__);
return SANE_STATUS_UNSUPPORTED;
return false;
}
}
#endif
DBGCOMPLETED;
return SANE_STATUS_GOOD;
return true;
}
/*

Wyświetl plik

@ -1870,11 +1870,8 @@ int sanei_genesys_get_lowest_dpi(Genesys_Device *dev)
* flatbed cache entries are considred too old and then expires if they
* are older than the expiration time option, forcing calibration at least once
* then given time. */
SANE_Status
sanei_genesys_is_compatible_calibration (Genesys_Device * dev,
const Genesys_Sensor& sensor,
Genesys_Calibration_Cache * cache,
int for_overwrite)
bool sanei_genesys_is_compatible_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor,
Genesys_Calibration_Cache * cache, int for_overwrite)
{
#ifdef HAVE_SYS_TIME_H
struct timeval time;
@ -1886,7 +1883,7 @@ sanei_genesys_is_compatible_calibration (Genesys_Device * dev,
if(dev->model->cmd_set->calculate_current_setup==NULL)
{
DBG (DBG_proc, "%s: no calculate_setup, non compatible cache\n", __func__);
return SANE_STATUS_UNSUPPORTED;
return false;
}
dev->model->cmd_set->calculate_current_setup(dev, sensor);
@ -1926,7 +1923,7 @@ sanei_genesys_is_compatible_calibration (Genesys_Device * dev,
if (!compatible)
{
DBG (DBG_proc, "%s: completed, non compatible cache\n", __func__);
return SANE_STATUS_UNSUPPORTED;
return false;
}
/* a cache entry expires after afetr expiration time for non sheetfed scanners */
@ -1940,13 +1937,13 @@ sanei_genesys_is_compatible_calibration (Genesys_Device * dev,
&& (dev->settings.scan_method == ScanMethod::FLATBED))
{
DBG (DBG_proc, "%s: expired entry, non compatible cache\n", __func__);
return SANE_STATUS_UNSUPPORTED;
return false;
}
}
#endif
DBGCOMPLETED;
return SANE_STATUS_GOOD;
return true;
}

Wyświetl plik

@ -1041,11 +1041,8 @@ typedef struct Genesys_Command_Set
SANE_Status (*search_strip) (Genesys_Device * dev, const Genesys_Sensor& sensor,
SANE_Bool forward, SANE_Bool black);
SANE_Status (*is_compatible_calibration) (
Genesys_Device * dev,
const Genesys_Sensor& sensor,
Genesys_Calibration_Cache *cache,
SANE_Bool for_overwrite);
bool (*is_compatible_calibration) (Genesys_Device* dev, const Genesys_Sensor& sensor,
Genesys_Calibration_Cache* cache, SANE_Bool for_overwrite);
/* functions for transparency adapter */
/**
@ -1779,7 +1776,7 @@ int sanei_genesys_get_lowest_dpi(Genesys_Device *dev);
extern SANE_Status
sanei_genesys_read_calibration (Genesys_Device * dev);
extern SANE_Status
extern bool
sanei_genesys_is_compatible_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor,
Genesys_Calibration_Cache * cache,
int for_overwrite);