• 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 "rust/topshim/gatt/gatt_shim.h"
18 
19 #include <base/functional/bind.h>
20 #include <base/functional/callback.h>
21 
22 #include "src/profiles/gatt.rs.h"
23 
24 namespace bluetooth {
25 namespace topshim {
26 namespace rust {
27 
28 namespace internal {
29 
ReadPhyCallback(int client_if,RawAddress addr,uint8_t tx_phy,uint8_t rx_phy,uint8_t status)30 void ReadPhyCallback(int client_if, RawAddress addr, uint8_t tx_phy, uint8_t rx_phy,
31                      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(int server_if, RawAddress addr, uint8_t tx_phy, uint8_t rx_phy,
36                            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>(
48           reinterpret_cast<const btgatt_interface_t*>(gatt_intf)->client);
49 }
50 
server_read_phy(int server_if,RawAddress addr)51 int GattServerIntf::server_read_phy(int server_if, RawAddress addr) {
52   return server_intf_->read_phy(addr,
53                                 base::Bind(&internal::ServerReadPhyCallback, server_if, addr));
54 }
55 
GetGattServerProfile(const unsigned char * gatt_intf)56 std::unique_ptr<GattServerIntf> GetGattServerProfile(const unsigned char* gatt_intf) {
57   return std::make_unique<GattServerIntf>(
58           reinterpret_cast<const btgatt_interface_t*>(gatt_intf)->server);
59 }
60 
61 }  // namespace rust
62 }  // namespace topshim
63 }  // namespace bluetooth
64