Skip to content

Commit

Permalink
Add --print-job-id
Browse files Browse the repository at this point in the history
  • Loading branch information
attah committed Sep 10, 2024
1 parent 6af70c7 commit 5fcb950
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/ippprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,15 @@ Error IppPrinter::doPrint(IppPrintJob& job, std::string inFile, Converter::Conve
if(cres == CURLE_OK)
{
IppMsg response(result);
if(response.getStatus() > 0xff)
if(response.getStatus() < 0xff)
{
if(!response.getJobAttrs().empty() && _printJobId)
{
int jobId = response.getJobAttrs().front().get<int>("job-id");
std::cout << "Job submitted successfully, with id: " << jobId << std::endl;
}
}
else
{
error = "Print job failed: " + response.getOpAttrs().get<std::string>("status-message", "unknown");
}
Expand Down
6 changes: 6 additions & 0 deletions lib/ippprinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ class IppPrinter
Error getJobs(List<JobInfo>& jobInfos);
Error cancelJob(int jobId);

void printJobId(bool printJobId)
{
_printJobId = printJobId;
}

private:
Error _doRequest(IppMsg::Operation op, IppMsg& resp);
Error _doRequest(const IppMsg& req, IppMsg& resp);
Expand All @@ -96,6 +101,7 @@ class IppPrinter

std::string _addr;
bool _ignoreSslErrors = true;
bool _printJobId = false;

Error _error;
IppAttrs _printerAttrs;
Expand Down
5 changes: 4 additions & 1 deletion utils/ippclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ int main(int argc, char** argv)
int rightMargin;

bool antiAlias;
bool printJobId = false;
bool save = false;

int id;
Expand Down Expand Up @@ -235,6 +236,7 @@ int main(int argc, char** argv)
SwitchArg<int> rightMarginOpt(rightMargin, {"-rm", "--right-margin"}, "Right margin (as per IPP)");

SwitchArg<bool> antiAliasOpt(antiAlias, {"-aa", "--antialias"}, "Enable antialiasing in rasterization");
SwitchArg<bool> printJobIdOpt(printJobId, {"--print-job-id"}, "Print job id on successful submission");
SwitchArg<bool> saveOpt(save, {"--save"}, "Save options as local defaults for future jobs");

SwitchArg<int> idOpt(id, {"--id"}, "Id of print job.");
Expand Down Expand Up @@ -262,7 +264,7 @@ int main(int argc, char** argv)
&formatOpt, &mimeTypeOpt,
&mediaTypeOpt, &mediaSourceOpt, &outputBinOpt, &finishingsOpt,
&marginOpt, &topMarginOpt, &bottomMarginOpt, &leftMarginOpt, &rightMarginOpt,
&antiAliasOpt, &saveOpt},
&antiAliasOpt, &printJobIdOpt, &saveOpt},
{&addrArg, &pdfArg}}}});

bool correctArgs = args.get_args(argc, argv);
Expand Down Expand Up @@ -516,6 +518,7 @@ int main(int argc, char** argv)
DBG(<< page << "/" << total);
});

printer.printJobId(printJobId);
error = printer.runJob(job, inFile, mimeType, nPages, progressFun);

if(error)
Expand Down

0 comments on commit 5fcb950

Please sign in to comment.