• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "task_signal_wrapper.h"
17 
18 #include "ani_signature.h"
19 #include "error_handler.h"
20 #include "filemgmt_libhilog.h"
21 #include "fs_task_signal.h"
22 #include "type_converter.h"
23 
24 namespace OHOS {
25 namespace FileManagement {
26 namespace ModuleFileIO {
27 namespace ANI {
28 using namespace std;
29 using namespace OHOS::FileManagement::ModuleFileIO;
30 using namespace OHOS::FileManagement::ModuleFileIO::ANI::AniSignature;
31 
Unwrap(ani_env * env,ani_object object)32 FsTaskSignal *TaskSignalWrapper::Unwrap(ani_env *env, ani_object object)
33 {
34     ani_long nativePtr;
35     auto status = env->Object_GetFieldByName_Long(object, "nativeTaskSignal", &nativePtr);
36     if (status != ANI_OK) {
37         HILOGE("Unwrap taskSignal obj failed! status: %{public}d", status);
38         return nullptr;
39     }
40 
41     FsTaskSignal *copySignal = reinterpret_cast<FsTaskSignal *>(nativePtr);
42     return copySignal;
43 }
44 
Wrap(ani_env * env,ani_object object,unique_ptr<FsTaskSignal> signal)45 bool TaskSignalWrapper::Wrap(ani_env *env, ani_object object, unique_ptr<FsTaskSignal> signal)
46 {
47     if (object == nullptr) {
48         HILOGE("TaskSignal obj is null!");
49         return false;
50     }
51 
52     if (signal == nullptr) {
53         HILOGE("FsTaskSignal pointer is null!");
54         return false;
55     }
56 
57     ani_long ptr = reinterpret_cast<ani_long>(signal.get());
58 
59     auto status = env->Object_SetFieldByName_Long(object, "nativeTaskSignal", ptr);
60     if (status != ANI_OK) {
61         HILOGE("Wrap taskSignal obj failed! status: %{public}d", status);
62         return false;
63     }
64     signal.release();
65     return true;
66 }
67 
68 } // namespace ANI
69 } // namespace ModuleFileIO
70 } // namespace FileManagement
71 } // namespace OHOS