1 // Copyright 2023, The Android Open Source Project 2 // 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 #pragma once 16 17 #include <cstdint> 18 #include <memory> 19 20 #include "rust/cxx.h" 21 #include "rust/src/core/ffi/types.h" 22 #include "types/ble_address_with_type.h" 23 24 namespace bluetooth { 25 26 namespace connection { 27 28 struct LeAclManagerCallbackShim; 29 30 class LeAclManagerShim { 31 public: 32 LeAclManagerShim(); 33 ~LeAclManagerShim(); 34 35 void CreateLeConnection(core::AddressWithType address, bool is_direct) const; 36 37 void CancelLeConnect(core::AddressWithType address) const; 38 39 #ifndef TARGET_FLOSS 40 void RegisterRustCallbacks(::rust::Box<LeAclManagerCallbackShim> callbacks); 41 #endif 42 43 private: 44 struct impl; 45 std::unique_ptr<impl> pimpl_; 46 }; 47 48 void RegisterRustApis( 49 ::rust::Fn<void(uint8_t client_id, core::AddressWithType address)> 50 start_direct_connection, 51 ::rust::Fn<void(uint8_t client_id, core::AddressWithType address)> 52 stop_direct_connection, 53 ::rust::Fn<void(uint8_t client_id, core::AddressWithType address)> 54 add_background_connection, 55 ::rust::Fn<void(uint8_t client_id, core::AddressWithType address)> 56 remove_background_connection, 57 ::rust::Fn<void(uint8_t client_id)> remove_client, 58 ::rust::Fn<void(core::AddressWithType address)> 59 stop_all_connections_to_device); 60 61 struct RustConnectionManager { 62 ::rust::Fn<void(uint8_t client_id, core::AddressWithType address)> 63 start_direct_connection; 64 ::rust::Fn<void(uint8_t client_id, core::AddressWithType address)> 65 stop_direct_connection; 66 ::rust::Fn<void(uint8_t client_id, core::AddressWithType address)> 67 add_background_connection; 68 ::rust::Fn<void(uint8_t client_id, core::AddressWithType address)> 69 remove_background_connection; 70 ::rust::Fn<void(uint8_t client_id)> remove_client; 71 ::rust::Fn<void(core::AddressWithType address)> 72 stop_all_connections_to_device; 73 }; 74 75 RustConnectionManager& GetConnectionManager(); 76 77 core::AddressWithType ResolveRawAddress(RawAddress bd_addr); 78 79 } // namespace connection 80 } // namespace bluetooth 81