1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "rust/topshim/gatt/gatt_shim.h"
18 
19 #include "base/functional/bind.h"
20 #include "src/profiles/gatt.rs.h"
21 
22 namespace bluetooth {
23 namespace topshim {
24 namespace rust {
25 
26 namespace internal {
27 
ReadPhyCallback(int client_if,RawAddress addr,uint8_t tx_phy,uint8_t rx_phy,uint8_t status)28 void ReadPhyCallback(int client_if, RawAddress addr, uint8_t tx_phy, uint8_t rx_phy, uint8_t status) {
29   bluetooth::topshim::rust::read_phy_callback(client_if, addr, tx_phy, rx_phy, status);
30 }
31 
ServerReadPhyCallback(int server_if,RawAddress addr,uint8_t tx_phy,uint8_t rx_phy,uint8_t status)32 void ServerReadPhyCallback(
33     int server_if, RawAddress addr, uint8_t tx_phy, uint8_t rx_phy, uint8_t status) {
34   bluetooth::topshim::rust::server_read_phy_callback(server_if, addr, tx_phy, rx_phy, status);
35 }
36 
37 }  // namespace internal
38 
read_phy(int client_if,RawAddress addr)39 int GattClientIntf::read_phy(int client_if, RawAddress addr) {
40   return client_intf_->read_phy(addr, base::Bind(&internal::ReadPhyCallback, client_if, addr));
41 }
42 
GetGattClientProfile(const unsigned char * gatt_intf)43 std::unique_ptr<GattClientIntf> GetGattClientProfile(const unsigned char* gatt_intf) {
44   return std::make_unique<GattClientIntf>(reinterpret_cast<const btgatt_interface_t*>(gatt_intf)->client);
45 }
46 
server_read_phy(int server_if,RawAddress addr)47 int GattServerIntf::server_read_phy(int server_if, RawAddress addr) {
48   return server_intf_->read_phy(
49       addr, base::Bind(&internal::ServerReadPhyCallback, server_if, addr));
50 }
51 
GetGattServerProfile(const unsigned char * gatt_intf)52 std::unique_ptr<GattServerIntf> GetGattServerProfile(const unsigned char* gatt_intf) {
53   return std::make_unique<GattServerIntf>(
54       reinterpret_cast<const btgatt_interface_t*>(gatt_intf)->server);
55 }
56 
57 }  // namespace rust
58 }  // namespace topshim
59 }  // namespace bluetooth
60