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 #include "napi_bluetooth_base_profile.h"
16
17 #include "bluetooth_log.h"
18 #include "napi_bluetooth_utils.h"
19
20 namespace OHOS {
21 namespace Bluetooth {
DefineBaseProfileJSFunction(napi_env env,napi_value exports)22 napi_value NapiBaseProfile::DefineBaseProfileJSFunction(napi_env env, napi_value exports)
23 {
24 HILOGI("start");
25 BaseProfilePropertyValueInit(env, exports);
26 napi_property_descriptor desc[] = {};
27 napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
28 HILOGI("end");
29 return exports;
30 }
31
BaseProfilePropertyValueInit(napi_env env,napi_value exports)32 napi_value NapiBaseProfile::BaseProfilePropertyValueInit(napi_env env, napi_value exports)
33 {
34 HILOGI("start");
35 napi_value strategyObj = ConnectionStrategyInit(env);
36 napi_property_descriptor exportFuncs[] = {
37 DECLARE_NAPI_PROPERTY("ConnectionStrategy", strategyObj),
38 };
39 napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
40 HILOGI("end");
41 return exports;
42 }
43
ConnectionStrategyInit(napi_env env)44 napi_value NapiBaseProfile::ConnectionStrategyInit(napi_env env)
45 {
46 HILOGI("enter");
47 napi_value strategyObj = nullptr;
48 napi_create_object(env, &strategyObj);
49 SetNamedPropertyByInteger(env, strategyObj, ConnectionStrategy::CONNECTION_UNKNOWN,
50 "CONNECT_STRATEGY_UNSUPPORTED");
51 SetNamedPropertyByInteger(env, strategyObj, ConnectionStrategy::CONNECTION_ALLOWED,
52 "CONNECT_STRATEGY_ALLOWED");
53 SetNamedPropertyByInteger(env, strategyObj, ConnectionStrategy::CONNECTION_FORBIDDEN,
54 "CONNECT_STRATEGY_FORBIDDEN");
55 return strategyObj;
56 }
57 } // namespace Bluetooth
58 } // namespace OHOS