• 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 <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)
42       : callbacks(callbacks){};
43 
44   void OnServerRead(uint16_t conn_id, uint32_t trans_id, uint16_t attr_handle,
45                     AttributeBackingType attr_type, uint32_t offset,
46                     bool is_long) const;
47 
48   void OnServerWrite(uint16_t conn_id, uint32_t trans_id, uint16_t attr_handle,
49                      AttributeBackingType attr_type, uint32_t offset,
50                      bool need_response, bool is_prepare,
51                      ::rust::Slice<const uint8_t> value) const;
52 
53   void OnIndicationSentConfirmation(uint16_t conn_id, int status) const;
54 
55   void OnExecute(uint16_t conn_id, uint32_t trans_id, bool execute) const;
56 
57  private:
58   const btgatt_server_callbacks_t& callbacks;
59 };
60 
61 }  // namespace gatt
62 }  // namespace bluetooth
63 
64 namespace fmt {
65 template <>
66 struct formatter<bluetooth::gatt::AttributeBackingType>
67     : enum_formatter<bluetooth::gatt::AttributeBackingType> {};
68 }  // namespace fmt
69