Skip to content

Commit 5064b62

Browse files
committed
Add cancel-job
1 parent 15f3a96 commit 5064b62

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

lib/ippprinter.cpp

+21-3
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ Error IppPrinter::identify()
365365

366366
Error IppPrinter::setAttributes(List<std::pair<std::string, std::string>> attrStrs)
367367
{
368-
Error err;
368+
Error error;
369369
IppAttrs attrs;
370370
for(const auto& [name, value] : attrStrs)
371371
{
@@ -384,8 +384,8 @@ Error IppPrinter::setAttributes(List<std::pair<std::string, std::string>> attrSt
384384
}
385385
IppMsg req = _mkMsg(IppMsg::SetPrinterAttrs, {}, {}, attrs);
386386
IppMsg resp;
387-
err = _doRequest(req, resp);
388-
return err;
387+
error = _doRequest(req, resp);
388+
return error;
389389
}
390390

391391
Error IppPrinter::getJobs(List<IppPrinter::JobInfo>& jobInfos)
@@ -408,6 +408,24 @@ Error IppPrinter::getJobs(List<IppPrinter::JobInfo>& jobInfos)
408408
return error;
409409
}
410410

411+
Error IppPrinter::cancelJob(int jobId)
412+
{
413+
Error error;
414+
IppAttrs cancelJobOpAttrs = {{"job-id", {IppTag::Integer, jobId}}};
415+
IppMsg req = _mkMsg(IppMsg::CancelJob, cancelJobOpAttrs);
416+
IppMsg resp;
417+
error = _doRequest(req, resp);
418+
if(error)
419+
{
420+
return error;
421+
}
422+
if(resp.getStatus() > 0xff)
423+
{
424+
error = resp.getOpAttrs().get<std::string>("status-message", "unknown");
425+
}
426+
return error;
427+
}
428+
411429
Error IppPrinter::_doRequest(IppMsg::Operation op, IppMsg& resp)
412430
{
413431
IppMsg req = _mkMsg(op);

lib/ippprinter.h

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class IppPrinter
8282
Error identify();
8383
Error setAttributes(List<std::pair<std::string, std::string>> attrStrs);
8484
Error getJobs(List<JobInfo>& jobInfos);
85+
Error cancelJob(int jobId);
8586

8687
private:
8788
Error _doRequest(IppMsg::Operation op, IppMsg& resp);

utils/ippclient.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ int main(int argc, char** argv)
181181

182182
bool antiAlias;
183183

184+
int id;
185+
184186
std::string addr;
185187
std::string attrs;
186188
std::string inFile;
@@ -226,6 +228,8 @@ int main(int argc, char** argv)
226228

227229
SwitchArg<bool> antiAliasOpt(antiAlias, {"-aa", "--antaialias"}, "Enable antialiasing in rasterization");
228230

231+
SwitchArg<int> idOpt(id, {"--id"}, "Id of print job.");
232+
229233
PosArg addrArg(addr, "printer address");
230234
PosArg attrsArg(attrs, "name=value[,name=value]");
231235
PosArg pdfArg(inFile, "input file");
@@ -240,6 +244,8 @@ int main(int argc, char** argv)
240244
{&addrArg, &attrsArg}}},
241245
{"get-jobs", {{&helpOpt, &verboseOpt},
242246
{&addrArg}}},
247+
{"cancel-job", {{&helpOpt, &verboseOpt, &idOpt},
248+
{&addrArg}}},
243249
{"print", {{&helpOpt, &verboseOpt, &forceOpt, &oneStageOpt,
244250
&pagesOpt, &copiesOpt, &collatedCopiesOpt, &paperSizeOpt,
245251
&resolutionOpt, &resolutionXOpt, &resolutionYOpt,
@@ -332,11 +338,25 @@ int main(int argc, char** argv)
332338
error = printer.getJobs(jobInfos);
333339
if(error)
334340
{
335-
std::cerr << "Get-jobs attributes failed: " << error.value() << std::endl;
341+
std::cerr << "Get-jobs failed: " << error.value() << std::endl;
336342
return 1;
337343
}
338344
std::cout << jobInfos;
339345
}
346+
else if(args.subCommand() == "cancel-job")
347+
{
348+
if(!idOpt.isSet())
349+
{
350+
std::cerr << "Please specify a job id with --id." << std::endl;
351+
return 1;
352+
}
353+
error = printer.cancelJob(id);
354+
if(error)
355+
{
356+
std::cerr << "Cancel-job failed: " << error.value() << std::endl;
357+
return 1;
358+
}
359+
}
340360
else if(args.subCommand() == "print")
341361
{
342362
IppPrintJob job = printer.createJob();

0 commit comments

Comments
 (0)