• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gd/rust/topshim/gatt/gatt_shim.h"
18 
19 #include "base/functional/bind.h"
20 #include "base/functional/callback.h"
21 #include "rust/cxx.h"
22 #include "src/profiles/gatt.rs.h"
23 #include "types/raw_address.h"
24 
25 namespace bluetooth {
26 namespace topshim {
27 namespace rust {
28 
29 namespace internal {
30 
ReadPhyCallback(int client_if,RawAddress addr,uint8_t tx_phy,uint8_t rx_phy,uint8_t status)31 void ReadPhyCallback(int client_if, RawAddress addr, uint8_t tx_phy, uint8_t rx_phy, uint8_t status) {
32   bluetooth::topshim::rust::read_phy_callback(client_if, addr, tx_phy, rx_phy, status);
33 }
34 
ServerReadPhyCallback(int server_if,RawAddress addr,uint8_t tx_phy,uint8_t rx_phy,uint8_t status)35 void ServerReadPhyCallback(
36     int server_if, RawAddress addr, uint8_t tx_phy, uint8_t rx_phy, uint8_t status) {
37   bluetooth::topshim::rust::server_read_phy_callback(server_if, addr, tx_phy, rx_phy, status);
38 }
39 
40 }  // namespace internal
41 
read_phy(int client_if,RawAddress addr)42 int GattClientIntf::read_phy(int client_if, RawAddress addr) {
43   return client_intf_->read_phy(addr, base::Bind(&internal::ReadPhyCallback, client_if, addr));
44 }
45 
GetGattClientProfile(const unsigned char * gatt_intf)46 std::unique_ptr<GattClientIntf> GetGattClientProfile(const unsigned char* gatt_intf) {
47   return std::make_unique<GattClientIntf>(reinterpret_cast<const btgatt_interface_t*>(gatt_intf)->client);
48 }
49 
server_read_phy(int server_if,RawAddress addr)50 int GattServerIntf::server_read_phy(int server_if, RawAddress addr) {
51   return server_intf_->read_phy(
52       addr, base::Bind(&internal::ServerReadPhyCallback, server_if, addr));
53 }
54 
GetGattServerProfile(const unsigned char * gatt_intf)55 std::unique_ptr<GattServerIntf> GetGattServerProfile(const unsigned char* gatt_intf) {
56   return std::make_unique<GattServerIntf>(
57       reinterpret_cast<const btgatt_interface_t*>(gatt_intf)->server);
58 }
59 
60 }  // namespace rust
61 }  // namespace topshim
62 }  // namespace bluetooth
63