• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 #include "ohos.bluetooth.access.proj.hpp"
17 #include "ohos.bluetooth.access.impl.hpp"
18 #include "taihe/runtime.hpp"
19 #include "stdexcept"
20 #include "bluetooth_remote_device.h"
21 #include "bluetooth_host.h"
22 #include "bluetooth_log.h"
23 #include "bluetooth_errorcode.h"
24 
25 using namespace taihe;
26 using namespace ohos::bluetooth::access;
27 
28 namespace {
29 // To be implemented.
30 
RestrictBluetoothSync()31 void RestrictBluetoothSync()
32 {
33     HILOGI("enter");
34     int32_t ret = OHOS::Bluetooth::BluetoothHost::GetDefaultHost().RestrictBluetooth();
35     if (ret == OHOS::Bluetooth::BT_ERR_INTERNAL_ERROR) {
36         set_business_error(ret, "RestrictBluetoothSync return error");
37     }
38 }
39 
GetState()40 BluetoothState GetState()
41 {
42     HILOGI("enter");
43     int32_t state = static_cast<int>(OHOS::Bluetooth::BluetoothHost::GetDefaultHost().GetBluetoothState());
44     return BluetoothState::from_value(state);
45 }
46 
EnableBluetooth()47 void EnableBluetooth()
48 {
49     HILOGI("enter");
50     OHOS::Bluetooth::BluetoothHost *host = &OHOS::Bluetooth::BluetoothHost::GetDefaultHost();
51     int32_t ret = host->EnableBle();
52     if (ret != OHOS::Bluetooth::BT_NO_ERROR) {
53         set_business_error(ret, "EnableBluetooth return error");
54     }
55 }
56 
DisableBluetooth()57 void DisableBluetooth()
58 {
59     HILOGI("enter");
60     OHOS::Bluetooth::BluetoothHost *host = &OHOS::Bluetooth::BluetoothHost::GetDefaultHost();
61     int32_t ret = host->DisableBt();
62     if (ret != OHOS::Bluetooth::BT_NO_ERROR) {
63         set_business_error(ret, "DisableBluetooth return error");
64     }
65 }
66 }  // namespace
67 
68 // Since these macros are auto-generate, lint will cause false positive.
69 // NOLINTBEGIN
70 TH_EXPORT_CPP_API_RestrictBluetoothSync(RestrictBluetoothSync);
71 TH_EXPORT_CPP_API_GetState(GetState);
72 TH_EXPORT_CPP_API_EnableBluetooth(EnableBluetooth);
73 TH_EXPORT_CPP_API_DisableBluetooth(DisableBluetooth);
74 // NOLINTEND
75