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