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