• 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 <array>
17 #include <ani.h>
18 #include "ani_signature.h"
19 #include "bind_function.h"
20 #include "statvfs_ani.h"
21 
22 using namespace OHOS::FileManagement::ModuleFileIO::ANI;
23 using namespace OHOS::FileManagement::ModuleFileIO::ANI::AniSignature;
24 
BindStaticMethods(ani_env * env)25 static ani_status BindStaticMethods(ani_env *env)
26 {
27     auto classDesc = Impl::StatvfsImpl::classDesc.c_str();
28 
29     std::array methods = {
30         ani_native_function { "getFreeSizeSync", nullptr, reinterpret_cast<void *>(StatvfsAni::GetFreeSizeSync) },
31         ani_native_function { "getTotalSizeSync", nullptr, reinterpret_cast<void *>(StatvfsAni::GetTotalSizeSync) },
32     };
33     return BindClass(env, classDesc, methods);
34 }
35 
ANI_Constructor(ani_vm * vm,uint32_t * result)36 ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result)
37 {
38     if (vm == nullptr) {
39         HILOGE("Invalid parameter vm");
40         return ANI_INVALID_ARGS;
41     }
42 
43     if (result == nullptr) {
44         HILOGE("Invalid parameter result");
45         return ANI_INVALID_ARGS;
46     }
47 
48     ani_env *env;
49     ani_status status = vm->GetEnv(ANI_VERSION_1, &env);
50     if (status != ANI_OK) {
51         HILOGE("Invalid ani version!");
52         return ANI_INVALID_VERSION;
53     }
54 
55     if ((status = BindStaticMethods(env)) != ANI_OK) {
56         HILOGE("Cannot bind native static methods for statvfs!");
57         return status;
58     };
59 
60     *result = ANI_VERSION_1;
61     return ANI_OK;
62 }