1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "hilog_wrapper.h"
16 #include "uv_queue.h"
17
18
19 namespace OHOS::MiscServices {
20 using namespace WallpaperMgrService;
Call(napi_env env,void * data,uv_after_work_cb afterCallback)21 bool UvQueue::Call(napi_env env, void *data, uv_after_work_cb afterCallback)
22 {
23 uv_loop_s *loop = nullptr;
24 napi_get_uv_event_loop(env, &loop);
25 if (loop == nullptr) {
26 return false;
27 }
28 uv_work_t *work = new (std::nothrow) uv_work_t;
29 if (work == nullptr) {
30 delete static_cast<WorkData *>(data);
31 return false;
32 }
33 work->data = data;
34 auto ret = uv_queue_work_with_qos(loop, work, [](uv_work_t *work) {}, afterCallback, uv_qos_user_initiated);
35 if (ret != 0) {
36 HILOG_ERROR("uv_queue_work_with_qos faild retCode:%{public}d!", ret);
37 delete static_cast<WorkData *>(data);
38 delete work;
39 return false;
40 }
41 return true;
42 }
43 } // namespace OHOS::MiscServices