mirror of
https://gitee.com/openharmony/print_print_fwk
synced 2025-01-19 08:07:23 +00:00
commit
202bc45461
@ -21,6 +21,8 @@
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS::Scan {
|
||||
const int32_t MAX_BUFSIZE = 1024 * 1024 * 1024; // 1G
|
||||
|
||||
SanePictureData::SanePictureData() : data_(nullptr), size_(0) {}
|
||||
SanePictureData::~SanePictureData()
|
||||
{
|
||||
@ -51,6 +53,9 @@ SanePictureData* SanePictureData::Unmarshalling(Parcel &parcel)
|
||||
return nullptr;
|
||||
}
|
||||
int32_t dataSize = parcel.ReadInt32();
|
||||
if (dataSize > MAX_BUFSIZE) {
|
||||
return obj;
|
||||
}
|
||||
obj->size_ = dataSize;
|
||||
if (dataSize == INVALID_DATA) {
|
||||
SCAN_HILOGW("No data was read because of the failure");
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <uv.h>
|
||||
#include <functional>
|
||||
#include "scan_callback.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "napi_scan_utils.h"
|
||||
#include "scan_log.h"
|
||||
|
||||
@ -36,29 +37,31 @@ ScanCallback::~ScanCallback()
|
||||
return;
|
||||
}
|
||||
SCAN_HILOGI("callback has been destroyed");
|
||||
uv_loop_s *loop = nullptr;
|
||||
napi_get_uv_event_loop(env_, &loop);
|
||||
if (loop == nullptr) {
|
||||
return;
|
||||
}
|
||||
Param *param = new (std::nothrow) Param;
|
||||
if (param == nullptr) {
|
||||
return;
|
||||
}
|
||||
param->env = env_;
|
||||
param->callbackRef = ref_;
|
||||
uv_work_t *work = new (std::nothrow) uv_work_t;
|
||||
if (work == nullptr) {
|
||||
auto task = [param]() {
|
||||
SCAN_HILOGI("napi_send_event ScanCallback DeleteReference");
|
||||
if (param == nullptr) {
|
||||
return;
|
||||
}
|
||||
napi_handle_scope scope = nullptr;
|
||||
napi_open_handle_scope(param->env, &scope);
|
||||
if (scope == nullptr) {
|
||||
delete param;
|
||||
return;
|
||||
}
|
||||
napi_ref callbackRef = param->callbackRef;
|
||||
NapiScanUtils::DeleteReference(param->env, callbackRef);
|
||||
napi_close_handle_scope(param->env, scope);
|
||||
delete param;
|
||||
return;
|
||||
}
|
||||
work->data = reinterpret_cast<void*>(param);
|
||||
int retVal = UvQueueWork(loop, work);
|
||||
if (retVal != 0) {
|
||||
SCAN_HILOGE("Failed to get uv_queue_work.");
|
||||
};
|
||||
if (napi_send_event(env_, task, napi_eprio_low) != napi_ok) {
|
||||
SCAN_HILOGE("Failed to send event");
|
||||
delete param;
|
||||
delete work;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -321,35 +324,4 @@ bool ScanCallback::OnGetDevicesList(std::vector<ScanDeviceInfo> &infos)
|
||||
callbackFunction_(infos);
|
||||
return true;
|
||||
}
|
||||
|
||||
int ScanCallback::UvQueueWork(uv_loop_s *loop, uv_work_t *work)
|
||||
{
|
||||
if (loop == nullptr || work == nullptr) {
|
||||
return -1; // parameter error
|
||||
}
|
||||
int retVal = uv_queue_work(loop, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) {
|
||||
SCAN_HILOGI("uv_queue_work ScanCallback DeleteReference");
|
||||
if (work == nullptr) {
|
||||
return;
|
||||
}
|
||||
Param *param = reinterpret_cast<Param*>(work->data);
|
||||
if (param == nullptr) {
|
||||
delete work;
|
||||
return;
|
||||
}
|
||||
napi_handle_scope scope = nullptr;
|
||||
napi_open_handle_scope(param->env, &scope);
|
||||
if (scope == nullptr) {
|
||||
delete param;
|
||||
delete work;
|
||||
return;
|
||||
}
|
||||
napi_ref callbackRef = param->callbackRef;
|
||||
NapiScanUtils::DeleteReference(param->env, callbackRef);
|
||||
napi_close_handle_scope(param->env, scope);
|
||||
delete param;
|
||||
delete work;
|
||||
});
|
||||
return retVal;
|
||||
}
|
||||
} // namespace OHOS::Scan
|
||||
|
@ -121,10 +121,20 @@ napi_value JsPrintCallback::Exec(
|
||||
PRINT_HILOGE("Failed to build JS worker");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (UvQueueWork(loop, worker) != 0) {
|
||||
PRINT_HILOGE("Failed to uv_queue_work");
|
||||
PRINT_SAFE_DELETE(worker);
|
||||
PRINT_SAFE_DELETE(worker);
|
||||
auto task = [jsWorkParam = &jsParam_]() {
|
||||
napi_call_function(jsWorkParam->nativeEngine, jsWorkParam->jsObj,
|
||||
jsWorkParam->jsMethod, jsWorkParam->argc, jsWorkParam->argv, &(jsWorkParam->jsResult));
|
||||
jsWorkParam->isCompleted = true;
|
||||
if (jsWorkParam->isSync) {
|
||||
jsWorkParam->self = nullptr;
|
||||
} else {
|
||||
std::unique_lock<std::mutex> lock(jsWorkParam->self->conditionMutex_);
|
||||
jsWorkParam->self->syncCon_.notify_one();
|
||||
}
|
||||
};
|
||||
if (napi_send_event(jsParam_.nativeEngine, task, napi_eprio_low) != napi_ok) {
|
||||
PRINT_HILOGE("Failed to send event");
|
||||
return nullptr;
|
||||
}
|
||||
if (isSync) {
|
||||
@ -139,34 +149,5 @@ napi_value JsPrintCallback::Exec(
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int JsPrintCallback::UvQueueWork(uv_loop_s* loop, uv_work_t* worker)
|
||||
{
|
||||
return uv_queue_work(
|
||||
loop, worker, [](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int statusInt) {
|
||||
if (work == nullptr) {
|
||||
PRINT_HILOGE("work is nullptr!");
|
||||
return;
|
||||
}
|
||||
auto jsWorkParam = reinterpret_cast<JsPrintCallback::JsWorkParam*>(work->data);
|
||||
if (jsWorkParam == nullptr) {
|
||||
PRINT_HILOGE("jsWorkParam is nullptr!");
|
||||
PRINT_SAFE_DELETE(work);
|
||||
return;
|
||||
}
|
||||
napi_call_function(jsWorkParam->nativeEngine, jsWorkParam->jsObj,
|
||||
jsWorkParam->jsMethod, jsWorkParam->argc, jsWorkParam->argv, &(jsWorkParam->jsResult));
|
||||
jsWorkParam->isCompleted = true;
|
||||
if (jsWorkParam->isSync) {
|
||||
jsWorkParam->self = nullptr;
|
||||
} else {
|
||||
std::unique_lock<std::mutex> lock(jsWorkParam->self->conditionMutex_);
|
||||
jsWorkParam->self->syncCon_.notify_one();
|
||||
}
|
||||
PRINT_SAFE_DELETE(jsWorkParam);
|
||||
PRINT_SAFE_DELETE(work);
|
||||
});
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
@ -1239,7 +1239,7 @@ void PrintCupsClient::StartCupsJob(JobParameters *jobParams, CallbackFunc callba
|
||||
http_t *http = nullptr;
|
||||
int num_options = 0;
|
||||
cups_option_t *options = nullptr;
|
||||
uint32_t jobId;
|
||||
uint32_t jobId = 0;
|
||||
|
||||
if (!VerifyPrintJob(jobParams, num_options, jobId, options, http)) {
|
||||
callback();
|
||||
|
@ -130,6 +130,10 @@ void VendorIppEveryWhere::ConnectPrinterByPrinterIdAndUri(const std::string &pri
|
||||
{
|
||||
PRINT_HILOGI("ConnectPrinterByPrinterIdAndUri enter");
|
||||
auto printerInfo = QueryPrinterInfoByUri(uri);
|
||||
if (printerInfo == nullptr) {
|
||||
PRINT_HILOGW("connect fail");
|
||||
return;
|
||||
}
|
||||
printerInfo->SetPrinterId(printerId);
|
||||
if (!ConnectPrinter(printerInfo)) {
|
||||
PRINT_HILOGW("connect fail");
|
||||
|
Loading…
x
Reference in New Issue
Block a user