OpenPrinting CUPS is the most current version of CUPS, a standards-based, open source printing system for Linux® and other Unix®-like operating systems. CUPS supports printing to:
- AirPrint™ and IPP Everywhere™ printers,
- Network and local (USB) printers with Printer Applications, and
- Network and local (USB) printers with (legacy) PPD-based printer drivers.
You can also learn more about the CUPS project through the official website
In the process of OpenHarmony's southward ecological development, it is necessary to be compatible with printers in the stock market. The use of CUPS printing system can directly connect with most printers in the market, which also reduces the difficulty for printer manufacturers to adapt to OpenHarmony.
#include <cups/cups-private.h>
Add in the bundle. json file
"deps": {
"third_part": [
"cups"
]
}
Add dependencies where needed in BUILD.gn
deps += [ "//third_party/cups:cups" ]
// Example of using CUPS interface to query printer capabilities
ipp_t *request; /* IPP Request */
ipp_t *response; /* IPP response */
http_t *http = NULL;
char scheme[HTTP_MAX_URI]; // Protocol
char username[HTTP_MAX_URI];
char host[HTTP_MAX_URI];
int port;
// Declare which printer capabilities need to be queried, here are all
static const char * const pattrs[] = {
"all"
};
// Connect to printer
http = httpConnect2(host, port, NULL, AF_UNSPEC, HTTP_ENCRYPTION_IF_REQUESTED, 1, TIME_OUT, NULL);
if (http == nullptr) {
return;
}
request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, printerUri.c_str());
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser());
ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes",
(int)(sizeof(pattrs) / sizeof(pattrs[0])), NULL, pattrs);
response = cupsDoRequest(http, request, "/");
// parse response
if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) {
ippDelete(response);
return;
}
// close http
httpClose(http);