1 /*
2  * Copyright (c) 2024 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 "bluetooth_connection_ffi.h"
17 
18 #include "bluetooth_connection_impl.h"
19 #include "bluetooth_log.h"
20 
21 using namespace OHOS::FFI;
22 
23 namespace OHOS {
24 namespace CJSystemapi {
25 namespace CJBluetoothConnection {
26 
27 extern "C" {
FfiBluetoothConPairDevice(const char* deviceId, int32_t* errCode)28 void FfiBluetoothConPairDevice(const char* deviceId, int32_t* errCode)
29 {
30     return ConnectionImpl::PairDevice(deviceId, errCode);
31 }
32 
FfiBluetoothConGetRemoteDeviceName(const char* deviceId, int32_t* errCode)33 char* FfiBluetoothConGetRemoteDeviceName(const char* deviceId, int32_t* errCode)
34 {
35     return ConnectionImpl::GetRemoteDeviceName(deviceId, errCode);
36 }
37 
FfiBluetoothConGetRemoteDeviceClass(const char* deviceId, int32_t* errCode)38 DeviceClass FfiBluetoothConGetRemoteDeviceClass(const char* deviceId, int32_t* errCode)
39 {
40     return ConnectionImpl::GetRemoteDeviceClass(deviceId, errCode);
41 }
42 
FfiBluetoothConGetRemoteProfileUuids(const char* deviceId, int32_t* errCode)43 CArrString FfiBluetoothConGetRemoteProfileUuids(const char* deviceId, int32_t* errCode)
44 {
45     return ConnectionImpl::GetRemoteProfileUuids(deviceId, errCode);
46 }
47 
FfiBluetoothConGetLocalName(int32_t* errCode)48 char* FfiBluetoothConGetLocalName(int32_t* errCode)
49 {
50     return ConnectionImpl::GetLocalName(errCode);
51 }
52 
FfiBluetoothConGetPairedDevices(int32_t* errCode)53 CArrString FfiBluetoothConGetPairedDevices(int32_t* errCode)
54 {
55     return ConnectionImpl::GetPairedDevices(errCode);
56 }
57 
FfiBluetoothConGetPairState(const char* deviceId, int32_t* errCode)58 int32_t FfiBluetoothConGetPairState(const char* deviceId, int32_t* errCode)
59 {
60     return ConnectionImpl::GetPairState(deviceId, errCode);
61 }
62 
FfiBluetoothConGetProfileConnectionState(int32_t profileId, int32_t* errCode)63 int32_t FfiBluetoothConGetProfileConnectionState(int32_t profileId, int32_t* errCode)
64 {
65     return ConnectionImpl::GetProfileConnectionState(profileId, errCode);
66 }
67 
FfiBluetoothConSetDevicePairingConfirmation(const char* deviceId, bool accept, int32_t* errCode)68 void FfiBluetoothConSetDevicePairingConfirmation(const char* deviceId, bool accept, int32_t* errCode)
69 {
70     return ConnectionImpl::SetDevicePairingConfirmation(deviceId, accept, errCode);
71 }
72 
FfiBluetoothConSetDevicePinCode(const char* deviceId, const char* code, int32_t* errCode)73 void FfiBluetoothConSetDevicePinCode(const char* deviceId, const char* code, int32_t* errCode)
74 {
75     return ConnectionImpl::SetDevicePinCode(deviceId, code, errCode);
76 }
77 
FfiBluetoothConSetLocalName(const char* localName, int32_t* errCode)78 void FfiBluetoothConSetLocalName(const char* localName, int32_t* errCode)
79 {
80     return ConnectionImpl::SetLocalName(localName, errCode);
81 }
82 
FfiBluetoothConSetBluetoothScanMode(int32_t mode, int32_t duration, int32_t* errCode)83 void FfiBluetoothConSetBluetoothScanMode(int32_t mode, int32_t duration, int32_t* errCode)
84 {
85     return ConnectionImpl::SetBluetoothScanMode(mode, duration, errCode);
86 }
87 
FfiBluetoothConGetBluetoothScanMode(int32_t* errCode)88 int32_t FfiBluetoothConGetBluetoothScanMode(int32_t* errCode)
89 {
90     return ConnectionImpl::GetBluetoothScanMode(errCode);
91 }
92 
FfiBluetoothConStartBluetoothDiscovery(int32_t* errCode)93 void FfiBluetoothConStartBluetoothDiscovery(int32_t* errCode)
94 {
95     return ConnectionImpl::StartBluetoothDiscovery(errCode);
96 }
97 
FfiBluetoothConStopBluetoothDiscovery(int32_t* errCode)98 void FfiBluetoothConStopBluetoothDiscovery(int32_t* errCode)
99 {
100     return ConnectionImpl::StoptBluetoothDiscovery(errCode);
101 }
102 
FfiBluetoothConIsBluetoothDiscovering(int32_t* errCode)103 bool FfiBluetoothConIsBluetoothDiscovering(int32_t* errCode)
104 {
105     return ConnectionImpl::IsBluetoothDiscovering(errCode);
106 }
107 
FfiBluetoothConSetRemoteDeviceName(const char* deviceId, const char* name, int32_t* errCode)108 void FfiBluetoothConSetRemoteDeviceName(const char* deviceId, const char* name, int32_t* errCode)
109 {
110     return ConnectionImpl::SetRemoteDeviceName(deviceId, name, errCode);
111 }
112 
FfiBluetoothConGetRemoteDeviceBatteryInfo(const char* deviceId, int32_t* errCode)113 CBatteryInfo FfiBluetoothConGetRemoteDeviceBatteryInfo(const char* deviceId, int32_t* errCode)
114 {
115     return ConnectionImpl::GetRemoteDeviceBatteryInfo(deviceId, errCode);
116 }
117 
FfiBluetoothConOn(int32_t callbackType, void (*callback)(), int32_t* errCode)118 void FfiBluetoothConOn(int32_t callbackType, void (*callback)(), int32_t* errCode)
119 {
120     return ConnectionImpl::RegisterConnectionObserver(callbackType, callback, errCode);
121 }
122 }
123 } // namespace BluetoothConnection
124 } // namespace CJSystemapi
125 } // namespace OHOS