• 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 #ifndef OHOS_ABILITY_RUNTIME_ANI_COMMON_UTIL_H
17 #define OHOS_ABILITY_RUNTIME_ANI_COMMON_UTIL_H
18 
19 #include <string>
20 #include <vector>
21 #include "ani.h"
22 
23 namespace OHOS {
24 namespace AppExecFwk {
25 struct RunningProcessInfo;
26 bool GetFieldDoubleByName(ani_env *env, ani_object object, const char *name, double &value);
27 bool SetFieldDoubleByName(ani_env *env, ani_class cls, ani_object object, const char *name, double value);
28 
29 bool GetFieldBoolByName(ani_env *env, ani_object object, const char *name, bool &value);
30 bool SetFieldBoolByName(ani_env *env, ani_class cls, ani_object object, const char *name, bool value);
31 
32 bool GetFieldStringByName(ani_env *env, ani_object object, const char *name, std::string &value);
33 bool SetFieldStringByName(ani_env *env, ani_class cls, ani_object object, const char *name,
34     const std::string &value);
35 
36 bool GetFieldIntByName(ani_env *env, ani_object object, const char *name, int &value);
37 bool SetFieldIntByName(ani_env *env, ani_class cls, ani_object object, const char *name, int value);
38 
39 bool GetFieldStringArrayByName(ani_env *env, ani_object object, const char *name, std::vector<std::string> &value);
40 bool SetFieldArrayStringByName(ani_env *env, ani_class cls, ani_object object, const char *name,
41     const std::vector<std::string> &value);
42 
43 bool GetFieldRefByName(ani_env *env, ani_object object, const char *name, ani_ref &ref);
44 bool SetFieldRefByName(ani_env *env, ani_class cls, ani_object object, const char *name, ani_ref value);
45 
46 bool GetStdString(ani_env *env, ani_string str, std::string &value);
47 ani_string GetAniString(ani_env *env, const std::string &str);
48 bool GetAniStringArray(ani_env *env, const std::vector<std::string> &values, ani_array_ref *value);
49 
50 bool SetOptionalFieldInt(ani_env *env, ani_class cls, ani_object object, const std::string &fieldName, int value);
51 
52 ani_object CreateDouble(ani_env *env, ani_double value);
53 ani_object CreateBoolean(ani_env *env, ani_boolean value);
54 ani_object CreateLong(ani_env *env, ani_long value);
55 ani_object CreateInt(ani_env *env, ani_int value);
56 
57 bool AsyncCallback(ani_env *env, ani_object call, ani_object error, ani_object result);
58 bool GetPropertyRef(ani_env *env, ani_object obj, const char *name, ani_ref &ref, ani_boolean &isUndefined);
59 bool IsExistsField(ani_env *env, ani_object param, const char *name);
60 
61 bool WrapArrayString(ani_env *env, ani_object &arrayObj, const std::vector<std::string> &values);
62 bool UnwrapArrayString(ani_env *env, const ani_object &arrayObj, std::vector<std::string> &stringList);
63 ani_object CreateRunningProcessInfoArray(ani_env *env, std::vector<AppExecFwk::RunningProcessInfo> infos);
64 ani_object CreateEmptyArray(ani_env *env);
65 
66 bool IsExistsProperty(ani_env *env, ani_object param, const char *name);
67 bool GetStringProperty(ani_env *env, ani_object param, const char *name, std::string &value);
68 bool GetStringArrayProperty(ani_env *env, ani_object param, const char *name, std::vector<std::string> &value);
69 bool GetDoublePropertyObject(ani_env *env, ani_object param, const char *name, double &value);
70 bool GetDoublePropertyValue(ani_env *env, ani_object param, const char *name, double &value);
71 bool GetRefProperty(ani_env *env, ani_object param, const char *name, ani_ref &value);
72 
73 bool SetDoublePropertyObject(ani_env *env, ani_object param, const char *name, double value);
74 bool SetDoublePropertyValue(ani_env *env, ani_object param, const char *name, double value);
75 bool SetStringArrayProperty(ani_env *env, ani_object param, const char *name, const std::vector<std::string> &values);
76 bool SetRefProperty(ani_env *env, ani_object param, const char *name, ani_ref value);
77 
78 bool GetStaticFieldString(ani_env *env, ani_class classObj, const char *fieldName, std::string &value);
79 } // namespace AppExecFwk
80 } // namespace OHOS
81 #endif  // OHOS_ABILITY_RUNTIME_ANI_COMMON_UTIL_H
82