1 /* 2 * Copyright (c) 2023 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 #ifndef UTIL_NAPI_VALUE_H 16 #define UTIL_NAPI_VALUE_H 17 18 #include "key_event.h" 19 #include "mmi_log.h" 20 #include "napi/native_api.h" 21 #include "napi/native_node_api.h" 22 #include "utils/log.h" 23 24 namespace OHOS { 25 namespace MMI { 26 /* set property */ 27 napi_status SetNameProperty(const napi_env &env, napi_value &object, const std::string &name, bool value); 28 napi_status SetNameProperty(const napi_env &env, napi_value &object, const std::string &name, uint16_t value); 29 napi_status SetNameProperty(const napi_env &env, napi_value &object, const std::string &name, int32_t value); 30 napi_status SetNameProperty(const napi_env &env, napi_value &object, const std::string &name, uint32_t value); 31 napi_status SetNameProperty(const napi_env &env, napi_value &object, const std::string &name, float value); 32 napi_status SetNameProperty(const napi_env &env, napi_value &object, const std::string &name, double value); 33 napi_status SetNameProperty(const napi_env &env, napi_value &object, const std::string &name, int64_t value); 34 napi_status SetNameProperty(const napi_env &env, napi_value &object, const std::string &name, std::string value); 35 napi_status SetNameProperty( 36 const napi_env &env, napi_value &object, const std::string &name, std::optional<KeyEvent::KeyItem> &value); 37 napi_status SetNameProperty( 38 const napi_env &env, napi_value &object, const std::string &name, std::vector<KeyEvent::KeyItem> &value); 39 napi_status SetNameProperty(const napi_env &env, napi_value &object, const std::string &name, napi_value value); 40 41 /* get property */ 42 bool GetNamePropertyBool(const napi_env &env, const napi_value &object, const std::string &name); 43 std::string GetNamePropertyString(const napi_env &env, const napi_value &object, const std::string &name); 44 int32_t GetNamePropertyInt32(const napi_env &env, const napi_value &object, const std::string &name); 45 int64_t GetNamePropertyInt64(const napi_env &env, const napi_value &object, const std::string &name); 46 uint32_t GetNamePropertyUint32(const napi_env &env, const napi_value &object, const std::string &name); 47 KeyEvent::KeyItem GetNamePropertyKeyItem(const napi_env &env, const napi_value &object, const std::string &name); 48 std::vector<KeyEvent::KeyItem> GetNamePropertyKeyItems( 49 const napi_env &env, const napi_value &object, const std::string &name); 50 } // namespace MMI 51 } // namespace OHOS 52 53 #endif // UTIL_NAPI_VALUE_H 54