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