Skip to content

Commit

Permalink
posix: printDirect added explicit errors #45
Browse files Browse the repository at this point in the history
  • Loading branch information
tojocky committed Feb 12, 2015
1 parent 39ccaf8 commit 0b0b881
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/node_printer_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,21 @@ MY_NODE_MODULE_CALLBACK(PrintDirect)
int num_options = 0;
cups_option_t *options = NULL;
int job_id = cupsCreateJob(CUPS_HTTP_DEFAULT, *printername, *docname, num_options, options);
if(job_id > 0)
{
cupsStartDocument(CUPS_HTTP_DEFAULT, *printername, job_id, *docname, type_str.c_str(), 1 /*last document*/);
/* cupsWriteRequestData can be called as many times as needed */
//TODO: to split big buffer
cupsWriteRequestData(CUPS_HTTP_DEFAULT, data.c_str(), data.size());
cupsFinishDocument(CUPS_HTTP_DEFAULT, *printername);
if(job_id == 0) {
RETURN_EXCEPTION_STR(cupsLastErrorString());
}

if(HTTP_CONTINUE != cupsStartDocument(CUPS_HTTP_DEFAULT, *printername, job_id, *docname, type_str.c_str(), 1 /*last document*/)) {
RETURN_EXCEPTION_STR(cupsLastErrorString());
}

/* cupsWriteRequestData can be called as many times as needed */
//TODO: to split big buffer
if (HTTP_STATUS_CONTINUE != cupsWriteRequestData(CUPS_HTTP_DEFAULT, data.c_str(), data.size())) {
RETURN_EXCEPTION_STR(cupsLastErrorString());
}

cupsFinishDocument(CUPS_HTTP_DEFAULT, *printername);

MY_NODE_MODULE_RETURN_VALUE(V8_VALUE_NEW(Number, job_id));
}

0 comments on commit 0b0b881

Please sign in to comment.