1 /*
2 * Copyright (c) 2025 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
16 #include "uv_queue.h"
17 #include "ans_inner_errors.h"
18
19 namespace OHOS {
20 namespace NotificationNapi {
Call(napi_env env,OperationOnCallBack * data,uv_after_work_cb afterCallback)21 bool UvQueue::Call(napi_env env, OperationOnCallBack *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 ANS_LOGW("null loop");
27 delete data;
28 return false;
29 }
30 uv_work_t *work = new (std::nothrow) uv_work_t;
31 if (work == nullptr) {
32 ANS_LOGW("null work");
33 delete data;
34 return false;
35 }
36 work->data = data;
37 int ret = uv_queue_work_with_qos(
38 loop, work, [](uv_work_t *work) {}, afterCallback, uv_qos_user_initiated);
39 if (ret != 0) {
40 ANS_LOGW("uv_queue_work Failed.");
41 delete data;
42 delete work;
43 return false;
44 }
45 return true;
46 }
47 } // namespace NotificationNapi
48 } // namespace OHOS
49
50