modify comment of ohprint interface

Signed-off-by: guoshengbang <guoshengbang@huawei.com>
Change-Id: Ib1c430c321ddcf1a2b12644d090a06bc9cba9590
This commit is contained in:
guoshengbang 2024-09-03 18:09:23 +08:00
parent 1621af0b23
commit 5dc7923b82
6 changed files with 73 additions and 73 deletions

View File

@ -502,8 +502,8 @@ typedef void(*Print_WriteResultCallback)(const char *jobId, uint32_t code);
*
* @param jobId The print job id of one print task.
* @param fd The file descriptor to be written.
* @param oldAttrs The atrributes of last.
* @param newAttrs The atrributes of current.
* @param oldAttrs The attributes of last.
* @param newAttrs The attributes of current.
* @param writeCallback The Write files result callback.
* @since 13
*/
@ -772,7 +772,7 @@ Print_ErrorCode OH_Print_UpdatePrinterProperties(const char *printerId, const Pr
Print_ErrorCode OH_Print_RestorePrinterProperties(const char *printerId, const Print_StringList *propertyKeyList);
/**
* @brief This API restores printer properties to default settings based on the list of property keywords.
* @brief This API provides capacity to start print service.
*
* @permission {@code ohos.permission.PRINT}
* @param printJobName The name of this print job.

View File

@ -148,8 +148,8 @@ private:
const char * const *pattrs);
private:
bool toCups = true;
IPrintAbilityBase* printAbility = nullptr;
bool toCups_ = true;
IPrintAbilityBase* printAbility_ = nullptr;
std::vector<JobParameters*> jobQueue_;
JobParameters *currentJob_ = nullptr;
};

View File

@ -155,14 +155,14 @@ static void DeviceCb(const char *deviceClass, const char *deviceId, const char *
PrintCupsClient::PrintCupsClient()
{
printAbility = new (std::nothrow) PrintCupsWrapper();
printAbility_ = new (std::nothrow) PrintCupsWrapper();
}
PrintCupsClient::~PrintCupsClient()
{
if (printAbility != nullptr) {
delete printAbility;
printAbility = nullptr;
if (printAbility_ != nullptr) {
delete printAbility_;
printAbility_ = nullptr;
}
}
@ -371,8 +371,8 @@ void PrintCupsClient::QueryPPDInformation(const char *makeModel, std::vector<std
const char *ppd_make_model;
const char *ppd_name;
if (printAbility == nullptr) {
PRINT_HILOGW("printAbility is null");
if (printAbility_ == nullptr) {
PRINT_HILOGW("printAbility_ is null");
return;
}
request = ippNewRequest(CUPS_GET_PPDS);
@ -381,7 +381,7 @@ void PrintCupsClient::QueryPPDInformation(const char *makeModel, std::vector<std
}
PRINT_HILOGD("CUPS_GET_PPDS start.");
response = printAbility->DoRequest(CUPS_HTTP_DEFAULT, request, "/");
response = printAbility_->DoRequest(CUPS_HTTP_DEFAULT, request, "/");
if (response == NULL) {
PRINT_HILOGE("GetAvaiablePPDS failed: %{public}s", cupsLastErrorString());
return;
@ -452,8 +452,8 @@ int32_t PrintCupsClient::AddPrinterToCups(const std::string &printerUri, const s
PRINT_HILOGI("add success, printer has added");
return E_PRINT_NONE;
}
if (printAbility == nullptr) {
PRINT_HILOGW("printAbility is null");
if (printAbility_ == nullptr) {
PRINT_HILOGW("printAbility_ is null");
return E_PRINT_SERVER_FAILURE;
}
request = ippNewRequest(IPP_OP_CUPS_ADD_MODIFY_PRINTER);
@ -468,7 +468,7 @@ int32_t PrintCupsClient::AddPrinterToCups(const std::string &printerUri, const s
ippAddBoolean(request, IPP_TAG_PRINTER, "printer-is-accepting-jobs", 1);
ippAddBoolean(request, IPP_TAG_PRINTER, "printer-is-shared", 1);
PRINT_HILOGD("IPP_OP_CUPS_ADD_MODIFY_PRINTER cupsDoRequest");
ippDelete(printAbility->DoRequest(NULL, request, "/admin/"));
ippDelete(printAbility_->DoRequest(NULL, request, "/admin/"));
if (cupsLastError() > IPP_STATUS_OK_EVENTS_COMPLETE) {
PRINT_HILOGE("add error: %s", cupsLastErrorString());
return E_PRINT_SERVER_FAILURE;
@ -553,8 +553,8 @@ int32_t PrintCupsClient::DeletePrinterFromCups(const std::string &printerUri, co
PRINT_HILOGI("printer has not added");
return E_PRINT_NONE;
}
if (printAbility == nullptr) {
PRINT_HILOGW("printAbility is null");
if (printAbility_ == nullptr) {
PRINT_HILOGW("printAbility_ is null");
return E_PRINT_SERVER_FAILURE;
}
request = ippNewRequest(IPP_OP_CUPS_DELETE_PRINTER);
@ -566,7 +566,7 @@ int32_t PrintCupsClient::DeletePrinterFromCups(const std::string &printerUri, co
ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL, printerUri.c_str());
ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, "ppd-name", NULL, ppd.c_str());
PRINT_HILOGD("IPP_OP_CUPS_DELETE_PRINTER cupsDoRequest");
ippDelete(printAbility->DoRequest(NULL, request, "/admin/"));
ippDelete(printAbility_->DoRequest(NULL, request, "/admin/"));
if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) {
PRINT_HILOGE("delete error: %s", cupsLastErrorString());
return E_PRINT_SERVER_FAILURE;
@ -581,15 +581,15 @@ int32_t PrintCupsClient::DeleteCupsPrinter(const char *printerName)
char uri[HTTP_MAX_URI] = {0};
PRINT_HILOGD("PrintCupsClient DeleteCupsPrinter start: %{private}s", printerName);
if (printAbility == nullptr) {
PRINT_HILOGW("printAbility is null");
if (printAbility_ == nullptr) {
PRINT_HILOGW("printAbility_ is null");
return E_PRINT_SERVER_FAILURE;
}
request = ippNewRequest(IPP_OP_CUPS_DELETE_PRINTER);
httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, "localhost", 0, "/printers/%s", printerName);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser());
ippDelete(printAbility->DoRequest(NULL, request, "/admin/"));
ippDelete(printAbility_->DoRequest(NULL, request, "/admin/"));
if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) {
PRINT_HILOGE("DeleteCupsPrinter error: %{public}s", cupsLastErrorString());
return E_PRINT_SERVER_FAILURE;
@ -609,8 +609,8 @@ ipp_t *PrintCupsClient::QueryPrinterAttributesByUri(const std::string &printerUr
char resource[HTTP_MAX_URI] = {0}; /* Resource portion of URI */
int port = 0; /* Port portion of URI */
PRINT_HILOGD("QueryPrinterAttributesByUri enter");
if (printAbility == nullptr) {
PRINT_HILOGW("printAbility is null");
if (printAbility_ == nullptr) {
PRINT_HILOGW("printAbility_ is null");
return nullptr;
}
httpSeparateURI(HTTP_URI_CODING_ALL, printerUri.c_str(), scheme, sizeof(scheme), username, sizeof(username), host,
@ -629,7 +629,7 @@ ipp_t *PrintCupsClient::QueryPrinterAttributesByUri(const std::string &printerUr
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", num, NULL, pattrs);
response = printAbility->DoRequest(http, request, "/");
response = printAbility_->DoRequest(http, request, "/");
httpClose(http);
http = nullptr;
if (response == nullptr) {
@ -694,16 +694,16 @@ int32_t PrintCupsClient::QueryPrinterCapabilityFromPPD(const std::string &printe
PRINT_HILOGI("QueryPrinterCapabilityFromPPD printerName: %{public}s", standardName.c_str());
cups_dest_t *dest = nullptr;
if (printAbility == nullptr) {
PRINT_HILOGW("printAbility is null");
if (printAbility_ == nullptr) {
PRINT_HILOGW("printAbility_ is null");
return E_PRINT_SERVER_FAILURE;
}
dest = printAbility->GetNamedDest(CUPS_HTTP_DEFAULT, standardName.c_str(), NULL);
dest = printAbility_->GetNamedDest(CUPS_HTTP_DEFAULT, standardName.c_str(), NULL);
if (dest == nullptr) {
PRINT_HILOGE("the printer is not found");
return E_PRINT_SERVER_FAILURE;
}
cups_dinfo_t *dinfo = printAbility->CopyDestInfo(CUPS_HTTP_DEFAULT, dest);
cups_dinfo_t *dinfo = printAbility_->CopyDestInfo(CUPS_HTTP_DEFAULT, dest);
if (dinfo == nullptr) {
PRINT_HILOGE("cupsCopyDestInfo failed");
delete dest;
@ -759,7 +759,7 @@ void PrintCupsClient::StartNextJob()
PRINT_HILOGW("nextJob is nullptr");
return;
}
if (toCups) {
if (toCups_) {
auto self = shared_from_this();
CallbackFunc callback = [self]() { self->JobCompleteCallback(); };
std::thread StartPrintThread([self, callback] {self->StartCupsJob(self->currentJob_, callback);});
@ -887,8 +887,8 @@ int32_t PrintCupsClient::QueryAddedPrinterList(std::vector<std::string> &printer
int32_t PrintCupsClient::SetDefaultPrinter(const std::string &printerName)
{
http_t *http;
if (printAbility == nullptr) {
PRINT_HILOGW("printAbility is null");
if (printAbility_ == nullptr) {
PRINT_HILOGW("printAbility_ is null");
return E_PRINT_SERVER_FAILURE;
}
ippSetPort(CUPS_SEVER_PORT);
@ -906,7 +906,7 @@ int32_t PrintCupsClient::SetDefaultPrinter(const std::string &printerName)
"printer-uri", NULL, uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
NULL, cupsUser());
ippDelete(printAbility->DoRequest(http, request, "/admin/"));
ippDelete(printAbility_->DoRequest(http, request, "/admin/"));
httpClose(http);
const char* default_printer = cupsGetDefault();
@ -960,12 +960,12 @@ ppd_file_t* PrintCupsClient::GetPPDFile(const std::string &printerName)
int32_t PrintCupsClient::QueryPrinterAttrList(const std::string &printerName, const std::vector<std::string> &keyList,
std::vector<std::string> &valueList)
{
if (printAbility == nullptr) {
PRINT_HILOGW("printAbility is null");
if (printAbility_ == nullptr) {
PRINT_HILOGW("printAbility_ is null");
return E_PRINT_SERVER_FAILURE;
}
cups_dest_t *dest = nullptr;
dest = printAbility->GetNamedDest(CUPS_HTTP_DEFAULT, printerName.c_str(), NULL);
dest = printAbility_->GetNamedDest(CUPS_HTTP_DEFAULT, printerName.c_str(), NULL);
if (dest == nullptr) {
PRINT_HILOGW("the printer is not found");
return E_PRINT_SERVER_FAILURE;
@ -978,7 +978,7 @@ int32_t PrintCupsClient::QueryPrinterAttrList(const std::string &printerName, co
valueList.emplace_back(value);
}
}
printAbility->FreeDests(1, dest);
printAbility_->FreeDests(1, dest);
PRINT_HILOGI("QueryPrinterAttr end");
return E_PRINT_NONE;
}
@ -986,17 +986,17 @@ int32_t PrintCupsClient::QueryPrinterAttrList(const std::string &printerName, co
int32_t PrintCupsClient::QueryPrinterInfoByPrinterId(const std::string& printerId, PrinterInfo &info)
{
PRINT_HILOGD("the printerInfo printerName %{public}s", info.GetPrinterName().c_str());
if (printAbility == nullptr) {
PRINT_HILOGW("printAbility is null");
if (printAbility_ == nullptr) {
PRINT_HILOGW("printAbility_ is null");
return E_PRINT_SERVER_FAILURE;
}
cups_dest_t *dest = nullptr;
dest = printAbility->GetNamedDest(CUPS_HTTP_DEFAULT, info.GetPrinterName().c_str(), NULL);
dest = printAbility_->GetNamedDest(CUPS_HTTP_DEFAULT, info.GetPrinterName().c_str(), NULL);
if (dest == nullptr) {
PRINT_HILOGW("the printer is not found");
return E_PRINT_SERVER_FAILURE;
}
printAbility->FreeDests(1, dest);
printAbility_->FreeDests(1, dest);
if (info.HasOption()) {
PRINT_HILOGI("the printerInfo option");
PrinterCapability printerCaps;
@ -1040,21 +1040,21 @@ bool PrintCupsClient::CheckPrinterMakeModel(JobParameters *jobParams)
PRINT_HILOGE("The jobParams is null");
return isMakeModelRight;
}
if (printAbility == nullptr) {
PRINT_HILOGW("printAbility is null");
if (printAbility_ == nullptr) {
PRINT_HILOGW("printAbility_ is null");
return isMakeModelRight;
}
while (retryCount < MAX_RETRY_TIMES) {
dest = printAbility->GetNamedDest(CUPS_HTTP_DEFAULT, jobParams->printerName.c_str(), NULL);
dest = printAbility_->GetNamedDest(CUPS_HTTP_DEFAULT, jobParams->printerName.c_str(), NULL);
if (dest != NULL) {
const char *makeModel = cupsGetOption("printer-make-and-model", dest->num_options, dest->options);
PRINT_HILOGD("makeModel=%{private}s", makeModel);
if (makeModel != nullptr && strcmp(makeModel, "Local Raw Printer") != 0) {
isMakeModelRight = true;
printAbility->FreeDests(1, dest);
printAbility_->FreeDests(1, dest);
break;
}
printAbility->FreeDests(1, dest);
printAbility_->FreeDests(1, dest);
} else {
PRINT_HILOGE("The dest is null");
}
@ -1372,8 +1372,8 @@ void PrintCupsClient::QueryJobState(http_t *http, JobMonitorParam *param, JobSta
"job-state-reasons",
"job-printer-state-reasons"
};
if (printAbility == nullptr) {
PRINT_HILOGW("printAbility is null");
if (printAbility_ == nullptr) {
PRINT_HILOGW("printAbility_ is null");
return;
}
if (param == nullptr || jobStatus == nullptr) {
@ -1387,7 +1387,7 @@ void PrintCupsClient::QueryJobState(http_t *http, JobMonitorParam *param, JobSta
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, DEFAULT_USER.c_str());
ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", jattrsLen, NULL, jattrs);
PRINT_HILOGD("get job state from cups service: start");
response = printAbility->DoRequest(http, request, "/");
response = printAbility_->DoRequest(http, request, "/");
if ((attr = ippFindAttribute(response, "job-state", IPP_TAG_ENUM)) != NULL) {
jobStatus->job_state = (ipp_jstate_t)ippGetInteger(attr, 0);
}
@ -1635,11 +1635,11 @@ bool PrintCupsClient::IsPrinterExist(const char *printerUri, const char *printer
bool printerExist = false;
cups_dest_t *dest;
PRINT_HILOGD("IsPrinterExist enter");
if (printAbility == nullptr) {
PRINT_HILOGW("printAbility is null");
if (printAbility_ == nullptr) {
PRINT_HILOGW("printAbility_ is null");
return printerExist;
}
dest = printAbility->GetNamedDest(CUPS_HTTP_DEFAULT, printerName, NULL);
dest = printAbility_->GetNamedDest(CUPS_HTTP_DEFAULT, printerName, NULL);
if (dest != NULL) {
const char *deviceUri = cupsGetOption("device-uri", dest->num_options, dest->options);
PRINT_HILOGD("deviceUri=%{private}s", deviceUri);
@ -1648,7 +1648,7 @@ bool PrintCupsClient::IsPrinterExist(const char *printerUri, const char *printer
int printerState = cupsGetIntegerOption("printer-state", dest->num_options, dest->options);
PRINT_HILOGD("printerState=%{private}d", printerState);
if (printerState == IPP_PRINTER_STOPPED || makeModel == nullptr || strcmp(deviceUri, printerUri) != 0) {
printAbility->FreeDests(1, dest);
printAbility_->FreeDests(1, dest);
PRINT_HILOGI("Printer information needs to be modified");
return printerExist;
}
@ -1664,7 +1664,7 @@ bool PrintCupsClient::IsPrinterExist(const char *printerUri, const char *printer
DeleteCupsPrinter(printerName);
}
}
printAbility->FreeDests(1, dest);
printAbility_->FreeDests(1, dest);
}
return printerExist;
}

View File

@ -3348,11 +3348,11 @@ int32_t PrintServiceAbility::TryConnectPrinterByIp(const std::string &params)
}
std::string ip = connectParamJson["ip"].get<std::string>();
vendorManager.SetConnectingPrinter(IP_AUTO, ip);
PRINT_HILOGD("connecting printer by ip: %{public}s", ip.c_str());
if (!vendorManager.ConnectPrinterByIp(ip, "auto")) {
PRINT_HILOGW("ConnectPrinterByIp fail");
return E_PRINT_SERVER_FAILURE;
}
PRINT_HILOGD("connecting printer by ip success");
return E_PRINT_NONE;
}
} // namespace OHOS::Print

View File

@ -263,7 +263,7 @@ HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0014, TestSize.Level1)
HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0015, TestSize.Level1)
{
auto printCupsClient = std::make_shared<OHOS::Print::PrintCupsClient>();
printCupsClient->toCups = false;
printCupsClient->toCups_ = false;
printCupsClient->StartNextJob();
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
}
@ -288,7 +288,7 @@ HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0016, TestSize.Level1)
testJob.SetOption(JOB_OPTIONS);
JobParameters *jobParams = printCupsClient->BuildJobParameters(testJob);
printCupsClient->jobQueue_.push_back(jobParams);
printCupsClient->toCups = false;
printCupsClient->toCups_ = false;
printCupsClient->StartNextJob();
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
delete jobParams;
@ -305,7 +305,7 @@ HWTEST_F(PrintCupsClientTest, PrintCupsClientTest_0018, TestSize.Level1)
auto printCupsClient = std::make_shared<OHOS::Print::PrintCupsClient>();
JobParameters *jobParams = nullptr;
printCupsClient->jobQueue_.push_back(jobParams);
printCupsClient->toCups = false;
printCupsClient->toCups_ = false;
printCupsClient->StartNextJob();
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
delete jobParams;

View File

@ -74,16 +74,16 @@ void PrintCupsWrapperTest::DoMockTest(MockTestFunc func)
return;
}
PrintCupsClient printCupsClient;
if (printCupsClient.printAbility != nullptr) {
delete printCupsClient.printAbility;
printCupsClient.printAbility = nullptr;
if (printCupsClient.printAbility_ != nullptr) {
delete printCupsClient.printAbility_;
printCupsClient.printAbility_ = nullptr;
}
auto mock = new (std::nothrow) MockPrintCupsWrapper();
if (mock == nullptr) {
PRINT_HILOGE("mock is null");
return;
}
printCupsClient.printAbility = mock;
printCupsClient.printAbility_ = mock;
func(printCupsClient, *mock);
}
@ -96,9 +96,9 @@ void PrintCupsWrapperTest::DoMockTest(MockTestFunc func)
HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0001, TestSize.Level1)
{
PrintCupsClient printCupsClient;
if (printCupsClient.printAbility != nullptr) {
delete printCupsClient.printAbility;
printCupsClient.printAbility = nullptr;
if (printCupsClient.printAbility_ != nullptr) {
delete printCupsClient.printAbility_;
printCupsClient.printAbility_ = nullptr;
}
std::string printerName = "testPrinterName";
std::string printUri;
@ -161,9 +161,9 @@ HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0003, TestSize.Level1)
HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0010, TestSize.Level1)
{
PrintCupsClient printCupsClient;
if (printCupsClient.printAbility != nullptr) {
delete printCupsClient.printAbility;
printCupsClient.printAbility = nullptr;
if (printCupsClient.printAbility_ != nullptr) {
delete printCupsClient.printAbility_;
printCupsClient.printAbility_ = nullptr;
}
std::string printerId = "testPrinterId";
PrinterInfo info;
@ -281,9 +281,9 @@ HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0015, TestSize.Level1)
HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0020, TestSize.Level1)
{
PrintCupsClient printCupsClient;
if (printCupsClient.printAbility != nullptr) {
delete printCupsClient.printAbility;
printCupsClient.printAbility = nullptr;
if (printCupsClient.printAbility_ != nullptr) {
delete printCupsClient.printAbility_;
printCupsClient.printAbility_ = nullptr;
}
JobParameters jobParams;
EXPECT_EQ(printCupsClient.CheckPrinterMakeModel(&jobParams), false);
@ -333,9 +333,9 @@ HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0022, TestSize.Level1)
HWTEST_F(PrintCupsWrapperTest, PrintCupsWrapperTest_0030, TestSize.Level1)
{
PrintCupsClient printCupsClient;
if (printCupsClient.printAbility != nullptr) {
delete printCupsClient.printAbility;
printCupsClient.printAbility = nullptr;
if (printCupsClient.printAbility_ != nullptr) {
delete printCupsClient.printAbility_;
printCupsClient.printAbility_ = nullptr;
}
std::string name = "testName";
std::string uri = "testUri";