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