diff --git a/lib/ippprinter.cpp b/lib/ippprinter.cpp index 175836e..dc72a34 100644 --- a/lib/ippprinter.cpp +++ b/lib/ippprinter.cpp @@ -388,6 +388,26 @@ Error IppPrinter::setAttributes(List> attrSt return err; } +Error IppPrinter::getJobs(List& jobInfos) +{ + IppAttrs getJobsOpAttrs = {{"requested-attributes", {IppTag::Keyword, "all"}}}; + IppMsg req = _mkMsg(IppMsg::GetJobs, getJobsOpAttrs); + IppMsg resp; + Error error = _doRequest(req, resp); + if(error) + { + return error; + } + for(const IppAttrs& jobAttrs : resp.getJobAttrs()) + { + jobInfos.push_back(JobInfo {jobAttrs.get("job-id"), + jobAttrs.get("job-name"), + jobAttrs.get("job-state"), + jobAttrs.get("job-printer-state-message")}); + } + return error; +} + Error IppPrinter::_doRequest(IppMsg::Operation op, IppMsg& resp) { IppMsg req = _mkMsg(op); diff --git a/lib/ippprinter.h b/lib/ippprinter.h index 6ebef58..4e9df5b 100644 --- a/lib/ippprinter.h +++ b/lib/ippprinter.h @@ -29,6 +29,13 @@ class IppPrinter std::string version; bool operator==(const Firmware& other) const; }; + struct JobInfo + { + int id = 0; + std::string name; + int state = 0; + std::string stateMessage; + }; IppPrinter() = delete; IppPrinter(std::string addr); @@ -74,6 +81,7 @@ class IppPrinter bool identifySupported(); Error identify(); Error setAttributes(List> attrStrs); + Error getJobs(List& jobInfos); private: Error _doRequest(IppMsg::Operation op, IppMsg& resp); diff --git a/utils/ippclient.cpp b/utils/ippclient.cpp index 93d3bd3..8863047 100644 --- a/utils/ippclient.cpp +++ b/utils/ippclient.cpp @@ -92,6 +92,21 @@ std::string resolution_list(List l) return ss.str(); } +std::ostream& operator<<(std::ostream& os, List jobInfos) +{ + for(const IppPrinter::JobInfo& jobInfo : jobInfos) + { + os << jobInfo.id << ": " << jobInfo.name << std::endl; + os << "State: " << jobInfo.state; + if(jobInfo.stateMessage != "") + { + os << " (" << jobInfo.stateMessage << ")"; + } + os << std::endl; + } + return os; +} + template void print_if_set(std::string title, T value) { @@ -223,6 +238,8 @@ int main(int argc, char** argv) {&addrArg}}}, {"set-attrs", {{&helpOpt, &verboseOpt}, {&addrArg, &attrsArg}}}, + {"get-jobs", {{&helpOpt, &verboseOpt}, + {&addrArg}}}, {"print", {{&helpOpt, &verboseOpt, &forceOpt, &oneStageOpt, &pagesOpt, &copiesOpt, &collatedCopiesOpt, &paperSizeOpt, &resolutionOpt, &resolutionXOpt, &resolutionYOpt, @@ -309,6 +326,17 @@ int main(int argc, char** argv) return 1; } } + else if(args.subCommand() == "get-jobs") + { + List jobInfos; + error = printer.getJobs(jobInfos); + if(error) + { + std::cerr << "Get-jobs attributes failed: " << error.value() << std::endl; + return 1; + } + std::cout << jobInfos; + } else if(args.subCommand() == "print") { IppPrintJob job = printer.createJob();