Skip to content

Commit

Permalink
Fix scan behavior with ADFs (tested with SANE test backend)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimulPiscator committed Oct 15, 2023
1 parent 918fd7b commit 26d70d4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
6 changes: 6 additions & 0 deletions sanecpp/sanecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,12 @@ session::start()
log << "sane_start(" << m_device.get() << ") with options:" << m_options
<< std::endl;
m_status = ::sane_start(m_device.get());
switch (m_status) {
case SANE_STATUS_GOOD:
break;
default:
log << "sane_start(" << m_device.get() << "): " << m_status << std::endl;
}
if (m_status == SANE_STATUS_GOOD)
m_status = ::sane_get_parameters(m_device.get(), &m_parameters);
return *this;
Expand Down
42 changes: 26 additions & 16 deletions server/scanjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ struct ScanJob::Private
bool atomicTransition(State from, State to);
void updateStatus(SANE_Status);

void openSession();
SANE_Status openSession();
void startSession();
void closeSession();

bool beginTransfer();
Expand Down Expand Up @@ -264,9 +265,9 @@ ScanJob::Private::init(const ScanSettingsXml& settings, bool autoselectFormat, c
else if (inputSource == "Feeder") {
mScanSource = mpScanner->adfSourceName();
mImagesToTransfer = std::numeric_limits<int>::max();
double batchIfPossible = settings.getNumber("BatchIfPossible");
if (batchIfPossible == 1.0 && mDocumentFormat == HttpServer::MIME_TYPE_PDF)
mKind = adfBatch;
double concatIfPossible = settings.getNumber("ConcatIfPossible");
if (concatIfPossible == 1.0 && mDocumentFormat == HttpServer::MIME_TYPE_PDF)
mKind = adfConcat;
else
mKind = adfSingle;
}
Expand All @@ -293,8 +294,8 @@ ScanJob::Private::kindString() const
switch (mKind) {
case single:
return "single";
case adfBatch:
return "ADF batch";
case adfConcat:
return "ADF concat";
case adfSingle:
return "ADF single";
}
Expand Down Expand Up @@ -461,25 +462,27 @@ ScanJob::Private::updateStatus(SANE_Status status)
mState = pending;
mStateReason = PWG_NONE;
}
closeSession();
break;
case adfSingle:
mState = pending;
mStateReason = PWG_NONE;
break;
case adfBatch:
case adfConcat:
updateStatus(mpSession->start().status());
break;
}
break;
case SANE_STATUS_NO_DOCS:
if (mImagesCompleted > 0 && (mKind == adfSingle || mKind == adfBatch)) {
if (mImagesCompleted > 0 && (mKind == adfSingle || mKind == adfConcat)) {
mState = completed;
mStateReason = PWG_JOB_COMPLETED_SUCCESSFULLY;
} else {
mState = aborted;
mStateReason = PWG_RESOURCES_ARE_NOT_READY;
}
mAdfStatus = status;
closeSession();
break;
default:
mState = aborted;
Expand Down Expand Up @@ -530,14 +533,18 @@ ScanJob::Private::beginTransfer()
{
if(!atomicTransition(pending, processing))
return false;
openSession();
bool ok = isProcessing();
bool ok = true;
if (!mpSession)
ok = (openSession() == SANE_STATUS_GOOD);
if (ok)
startSession();
ok = isProcessing();
if (!ok)
closeSession();
return ok;
}

void
SANE_Status
ScanJob::Private::openSession()
{
SANE_Status status = SANE_STATUS_GOOD;
Expand Down Expand Up @@ -583,10 +590,14 @@ ScanJob::Private::openSession()
if (!ok)
status = SANE_STATUS_INVAL;
}
if (status == SANE_STATUS_GOOD) {
status = mpSession->start().status();
updateStatus(status);
}
return status;
}

void
ScanJob::Private::startSession()
{
SANE_Status status = mpSession->start().status();
updateStatus(status);
}

void
Expand Down Expand Up @@ -694,7 +705,6 @@ ScanJob::Private::finishTransfer(std::ostream& os)
}
if (pEncoder)
pEncoder->endDocument();
closeSession();
}

ScanJob&
Expand Down
2 changes: 1 addition & 1 deletion server/scanjob.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ScanJob
bool autoselectFormat,
const OptionsFile::Options&);

enum { single, adfSingle, adfBatch };
enum { single, adfSingle, adfConcat };
int kind() const;

int ageSeconds() const;
Expand Down
2 changes: 1 addition & 1 deletion server/scannerpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ buildScanJobTicket(const Dictionary& dict)
d.eraseKey("PaperSize");
d["XOffset"] = "0";
d["YOffset"] = "0";
d["BatchIfPossible"] = "1";
d["ConcatIfPossible"] = "1";
std::string ticket = "<x:ContentRegionUnits>escl:ThreeHundredthsOfInches</"
"x:ContentRegionUnits>\n";
for (auto& s : d) // just enough xml syntax for ScanJob to recognize
Expand Down

0 comments on commit 26d70d4

Please sign in to comment.