Skip to content

Commit

Permalink
Add get-jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
attah committed Feb 25, 2024
1 parent 20a76a3 commit 15f3a96
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/ippprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,26 @@ Error IppPrinter::setAttributes(List<std::pair<std::string, std::string>> attrSt
return err;
}

Error IppPrinter::getJobs(List<IppPrinter::JobInfo>& 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<int>("job-id"),
jobAttrs.get<std::string>("job-name"),
jobAttrs.get<int>("job-state"),
jobAttrs.get<std::string>("job-printer-state-message")});
}
return error;
}

Error IppPrinter::_doRequest(IppMsg::Operation op, IppMsg& resp)
{
IppMsg req = _mkMsg(op);
Expand Down
8 changes: 8 additions & 0 deletions lib/ippprinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -74,6 +81,7 @@ class IppPrinter
bool identifySupported();
Error identify();
Error setAttributes(List<std::pair<std::string, std::string>> attrStrs);
Error getJobs(List<JobInfo>& jobInfos);

private:
Error _doRequest(IppMsg::Operation op, IppMsg& resp);
Expand Down
28 changes: 28 additions & 0 deletions utils/ippclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ std::string resolution_list(List<IppResolution> l)
return ss.str();
}

std::ostream& operator<<(std::ostream& os, List<IppPrinter::JobInfo> 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 <typename T>
void print_if_set(std::string title, T value)
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -309,6 +326,17 @@ int main(int argc, char** argv)
return 1;
}
}
else if(args.subCommand() == "get-jobs")
{
List<IppPrinter::JobInfo> 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();
Expand Down

0 comments on commit 15f3a96

Please sign in to comment.