Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
GenericGattClient.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2017-2017 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef MBED_BLE_GENERIC_GATT_CLIENT 00018 #define MBED_BLE_GENERIC_GATT_CLIENT 00019 00020 #include <algorithm> 00021 #include "ble/GattClient.h" 00022 #include "ble/pal/PalGattClient.h" 00023 00024 // IMPORTANT: private header. Not part of the public interface. 00025 00026 namespace ble { 00027 namespace generic { 00028 00029 // forward declarations 00030 struct procedure_control_block_t; 00031 struct discovery_control_block_t; 00032 struct read_control_block_t; 00033 struct write_control_block_t; 00034 struct descriptor_discovery_control_block_t; 00035 00036 /** 00037 * Generic implementation of the GattClient. 00038 * It requires a pal::GattClient injected at construction site. 00039 * @important: Not part of the public interface of BLE API. 00040 */ 00041 class GenericGattClient : public GattClient { 00042 00043 // give access to control block classes 00044 friend struct procedure_control_block_t; 00045 friend struct discovery_control_block_t; 00046 friend struct read_control_block_t; 00047 friend struct write_control_block_t; 00048 friend struct descriptor_discovery_control_block_t; 00049 00050 public: 00051 /** 00052 * Create a GenericGattClient from a pal::GattClient 00053 */ 00054 GenericGattClient(pal::GattClient* pal_client); 00055 00056 /** 00057 * @see GattClient::launchServiceDiscovery 00058 */ 00059 virtual ble_error_t launchServiceDiscovery ( 00060 Gap::Handle_t connection_handle, 00061 ServiceDiscovery::ServiceCallback_t service_callback, 00062 ServiceDiscovery::CharacteristicCallback_t characteristic_callback, 00063 const UUID& matching_service_uuid, 00064 const UUID& matching_characteristic_uuid 00065 ); 00066 00067 /** 00068 * @see GattClient::isServiceDiscoveryActive 00069 */ 00070 virtual bool isServiceDiscoveryActive () const; 00071 00072 /** 00073 * @see GattClient::terminateServiceDiscovery 00074 */ 00075 virtual void terminateServiceDiscovery (); 00076 00077 /** 00078 * @see GattClient::read 00079 */ 00080 virtual ble_error_t read ( 00081 Gap::Handle_t connection_handle, 00082 GattAttribute::Handle_t attribute_handle, 00083 uint16_t offset 00084 ) const; 00085 00086 /** 00087 * @see GattClient::write 00088 */ 00089 virtual ble_error_t write ( 00090 GattClient::WriteOp_t cmd, 00091 Gap::Handle_t connection_handle, 00092 GattAttribute::Handle_t attribute_handle, 00093 size_t length, 00094 const uint8_t* value 00095 ) const; 00096 00097 /** 00098 * @see GattClient::onServiceDiscoveryTermination 00099 */ 00100 virtual void onServiceDiscoveryTermination ( 00101 ServiceDiscovery::TerminationCallback_t callback 00102 ); 00103 00104 /** 00105 * @see GattClient::discoverCharacteristicDescriptors 00106 */ 00107 virtual ble_error_t discoverCharacteristicDescriptors ( 00108 const DiscoveredCharacteristic& characteristic, 00109 const CharacteristicDescriptorDiscovery::DiscoveryCallback_t & discoveryCallback, 00110 const CharacteristicDescriptorDiscovery::TerminationCallback_t & terminationCallback 00111 ); 00112 00113 /** 00114 * @see GattClient::isCharacteristicDescriptorDiscoveryActive 00115 */ 00116 virtual bool isCharacteristicDescriptorDiscoveryActive ( 00117 const DiscoveredCharacteristic& characteristic 00118 ) const; 00119 00120 /** 00121 * @see GattClient::terminateCharacteristicDescriptorDiscovery 00122 */ 00123 virtual void terminateCharacteristicDescriptorDiscovery ( 00124 const DiscoveredCharacteristic& characteristic 00125 ); 00126 00127 /** 00128 * @see GattClient::reset 00129 */ 00130 virtual ble_error_t reset (void); 00131 00132 private: 00133 procedure_control_block_t* get_control_block(Gap::Handle_t connection); 00134 const procedure_control_block_t* get_control_block(Gap::Handle_t connection) const; 00135 void insert_control_block(procedure_control_block_t* cb) const; 00136 void remove_control_block(procedure_control_block_t* cb) const; 00137 00138 void on_termination(Gap::Handle_t connection_handle); 00139 void on_server_message_received(connection_handle_t, const pal::AttServerMessage&); 00140 void on_server_response(connection_handle_t, const pal::AttServerMessage&); 00141 void on_server_event(connection_handle_t, const pal::AttServerMessage&); 00142 void on_transaction_timeout(connection_handle_t); 00143 00144 uint16_t get_mtu(Gap::Handle_t connection) const; 00145 00146 pal::GattClient* const _pal_client; 00147 ServiceDiscovery::TerminationCallback_t _termination_callback; 00148 mutable procedure_control_block_t* control_blocks; 00149 }; 00150 00151 } 00152 } 00153 00154 #endif /* MBED_BLE_GENERIC_GATT_CLIENT */
Generated on Thu Jul 14 2022 14:36:16 by
