1 // Copyright 2022, 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 <bluetooth/log.h> 18 19 #include <cstdint> 20 21 #include "include/hardware/bluetooth.h" 22 #include "include/hardware/bt_common_types.h" 23 #include "include/hardware/bt_gatt_client.h" 24 #include "include/hardware/bt_gatt_server.h" 25 #include "rust/cxx.h" 26 27 namespace bluetooth { 28 namespace gatt { 29 30 /// The GATT entity backing the value of a user-controlled 31 /// attribute 32 enum class AttributeBackingType { 33 /// A GATT characteristic 34 CHARACTERISTIC, 35 /// A GATT descriptor 36 DESCRIPTOR, 37 }; 38 39 class GattServerCallbacks { 40 public: GattServerCallbacks(const btgatt_server_callbacks_t & callbacks)41 GattServerCallbacks(const btgatt_server_callbacks_t& callbacks) : callbacks(callbacks) {} 42 43 void OnServerRead(uint16_t conn_id, uint32_t trans_id, uint16_t attr_handle, 44 AttributeBackingType attr_type, uint32_t offset, bool is_long) const; 45 46 void OnServerWrite(uint16_t conn_id, uint32_t trans_id, uint16_t attr_handle, 47 AttributeBackingType attr_type, uint32_t offset, bool need_response, 48 bool is_prepare, ::rust::Slice<const uint8_t> value) const; 49 50 void OnIndicationSentConfirmation(uint16_t conn_id, int status) const; 51 52 void OnExecute(uint16_t conn_id, uint32_t trans_id, bool execute) const; 53 54 private: 55 const btgatt_server_callbacks_t& callbacks; 56 }; 57 58 } // namespace gatt 59 } // namespace bluetooth 60 61 namespace std { 62 template <> 63 struct formatter<bluetooth::gatt::AttributeBackingType> 64 : enum_formatter<bluetooth::gatt::AttributeBackingType> {}; 65 } // namespace std 66