• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 NAPI_NATIVE_OBJECT_H
17 #define NAPI_NATIVE_OBJECT_H
18 
19 #include "napi_bluetooth_utils.h"
20 
21 namespace OHOS {
22 namespace Bluetooth {
23 class NapiNativeObject {
24 public:
25     virtual ~NapiNativeObject() = default;
26     virtual napi_value ToNapiValue(napi_env env) const = 0;
27 };
28 
29 class NapiNativeEmpty : public NapiNativeObject {
30 public:
31     ~NapiNativeEmpty() override = default;
32 
ToNapiValue(napi_env env)33     napi_value ToNapiValue(napi_env env) const override
34     {
35         return NapiGetNull(env);
36     }
37 };
38 
39 class NapiNativeInt : public NapiNativeObject {
40 public:
NapiNativeInt(int value)41     explicit NapiNativeInt(int value) : value_(value) {}
42     ~NapiNativeInt() override = default;
43 
44     napi_value ToNapiValue(napi_env env) const override;
45 private:
46     int value_;
47 };
48 
49 class NapiNativeString : public NapiNativeObject {
50 public:
NapiNativeString(std::string value)51     explicit NapiNativeString(std::string value) : value_(std::move(value)) {}
52     ~NapiNativeString() override = default;
53 
54     napi_value ToNapiValue(napi_env env) const override;
55 private:
56     std::string value_;
57 };
58 
59 class NapiNativeUuidsArray : public NapiNativeObject {
60 public:
NapiNativeUuidsArray(const std::vector<std::string> uuids)61     NapiNativeUuidsArray(const std::vector<std::string> uuids) : uuids_(uuids) {}
62     ~NapiNativeUuidsArray() override = default;
63 
64     napi_value ToNapiValue(napi_env env) const override;
65 private:
66     std::vector<std::string> uuids_;
67 };
68 }  // namespace Bluetooth
69 }  // namespace OHOS
70 #endif  // NAPI_NATIVE_OBJECT_H