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_EVENTS_JSON_COMMON_H 17 #define OHOS_EVENTS_JSON_COMMON_H 18 19 #include <string> 20 #include "ani.h" 21 22 namespace OHOS { 23 namespace AppExecFwk { 24 25 bool GetDoubleOrUndefined(ani_env *env, ani_object param, const char *name, ani_double &value); 26 bool GetBoolOrUndefined(ani_env *env, ani_object param, const char *name); 27 bool GetStringOrUndefined(ani_env *env, ani_object param, const char *name, std::string &res); 28 bool GetIntByName(ani_env *env, ani_object param, const char *name, int &value); 29 bool GetStringArrayOrUndefined(ani_env *env, ani_object param, const char *name, std::vector<std::string> &res); 30 31 bool GetStdString(ani_env *env, ani_string str, std::string &res); 32 33 ani_string GetAniString(ani_env *env, const std::string &str); 34 ani_array_ref GetAniArrayString(ani_env *env, const std::vector<std::string> &values); 35 bool GetRefPropertyByName(ani_env *env, ani_object param, const char *name, ani_ref &ref); 36 37 ani_object createDouble(ani_env *env, ani_double value); 38 ani_object createBoolean(ani_env *env, ani_boolean value); 39 40 bool SetFieldString(ani_env *env, ani_class cls, ani_object object, 41 const std::string &fieldName, const std::string &value); 42 bool SetFieldDouble(ani_env *env, ani_class cls, ani_object object, const std::string &fieldName, double value); 43 bool SetFieldBoolean(ani_env *env, ani_class cls, ani_object object, const std::string &fieldName, bool value); 44 bool SetFieldInt(ani_env *env, ani_class cls, ani_object object, const std::string &fieldName, int value); 45 bool SetFieldArrayString(ani_env *env, ani_class cls, ani_object object, const std::string &fieldName, 46 const std::vector<std::string> &values); 47 bool SetFieldRef(ani_env *env, ani_class cls, ani_object object, const std::string &fieldName, ani_ref value); 48 } // namespace AppExecFwk 49 } // namespace OHOS 50 #endif // OHOS_EVENTS_JSON_COMMON_H