• 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 <ani.h>
17 #include <array>
18 #include <string>
19 #include "hilog_ani_base.h"
20 
21 using namespace OHOS::HiviewDFX;
22 static const std::string NAMESPACE_NAME_HILOG = "L@ohos/hilog/hilog;";
ANI_Constructor(ani_vm * vm,uint32_t * result)23 ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result)
24 {
25     ani_env *env;
26     if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) {
27         return ANI_ERROR;
28     }
29 
30     ani_namespace ns {};
31     if (ANI_OK != env->FindNamespace(NAMESPACE_NAME_HILOG.c_str(), &ns)) {
32         return ANI_ERROR;
33     }
34 
35     std::array methods = {
36         ani_native_function {"debug", nullptr, reinterpret_cast<void *>(HilogAniBase::Debug)},
37         ani_native_function {"info", nullptr, reinterpret_cast<void *>(HilogAniBase::Info)},
38         ani_native_function {"warn", nullptr, reinterpret_cast<void *>(HilogAniBase::Warn)},
39         ani_native_function {"error", nullptr, reinterpret_cast<void *>(HilogAniBase::Error)},
40         ani_native_function {"fatal", nullptr, reinterpret_cast<void *>(HilogAniBase::Fatal)},
41         ani_native_function {"isLoggable", nullptr, reinterpret_cast<void *>(HilogAniBase::IsLoggable)},
42         ani_native_function {"setMinLogLevel", nullptr, reinterpret_cast<void *>(HilogAniBase::SetMinLogLevel)},
43     };
44 
45     if (ANI_OK != env->Namespace_BindNativeFunctions(ns, methods.data(), methods.size())) {
46         return ANI_ERROR;
47     };
48 
49     *result = ANI_VERSION_1;
50     return ANI_OK;
51 }
52