Gleb Klochkov / Mbed OS Climatcontroll_Main

Dependencies:   esp8266-driver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GenericGattClient.h Source File

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 /**
00030  * Generic implementation of the GattClient.
00031  * It requires a pal::GattClient injected at construction site.
00032  * @attention: Not part of the public interface of BLE API.
00033  */
00034 class GenericGattClient : public GattClient {
00035 public:
00036     /**
00037      * Create a GenericGattClient from a pal::GattClient
00038      */
00039     GenericGattClient(pal::GattClient* pal_client);
00040 
00041     /**
00042      * @see GattClient::launchServiceDiscovery
00043      */
00044     virtual ble_error_t launchServiceDiscovery (
00045         Gap::Handle_t connection_handle,
00046         ServiceDiscovery::ServiceCallback_t  service_callback,
00047         ServiceDiscovery::CharacteristicCallback_t  characteristic_callback,
00048         const UUID& matching_service_uuid,
00049         const UUID& matching_characteristic_uuid
00050     );
00051 
00052     /**
00053      * @see GattClient::isServiceDiscoveryActive
00054      */
00055     virtual bool isServiceDiscoveryActive () const;
00056 
00057     /**
00058      * @see GattClient::terminateServiceDiscovery
00059      */
00060     virtual void terminateServiceDiscovery ();
00061 
00062     /**
00063      * @see GattClient::read
00064      */
00065     virtual ble_error_t read (
00066         Gap::Handle_t connection_handle,
00067         GattAttribute::Handle_t attribute_handle,
00068         uint16_t offset
00069     ) const;
00070 
00071     /**
00072      * @see GattClient::write
00073      */
00074     virtual ble_error_t write (
00075         GattClient::WriteOp_t cmd,
00076         Gap::Handle_t connection_handle,
00077         GattAttribute::Handle_t attribute_handle,
00078         size_t length,
00079         const uint8_t* value
00080     ) const;
00081 
00082     /**
00083      * @see GattClient::onServiceDiscoveryTermination
00084      */
00085     virtual void onServiceDiscoveryTermination (
00086         ServiceDiscovery::TerminationCallback_t  callback
00087     );
00088 
00089     /**
00090      * @see GattClient::discoverCharacteristicDescriptors
00091      */
00092     virtual ble_error_t discoverCharacteristicDescriptors (
00093         const DiscoveredCharacteristic& characteristic,
00094         const CharacteristicDescriptorDiscovery::DiscoveryCallback_t & discoveryCallback,
00095         const CharacteristicDescriptorDiscovery::TerminationCallback_t & terminationCallback
00096     );
00097 
00098     /**
00099      * @see GattClient::isCharacteristicDescriptorDiscoveryActive
00100      */
00101     virtual bool isCharacteristicDescriptorDiscoveryActive (
00102         const DiscoveredCharacteristic& characteristic
00103     ) const;
00104 
00105     /**
00106      * @see GattClient::terminateCharacteristicDescriptorDiscovery
00107      */
00108     virtual void terminateCharacteristicDescriptorDiscovery (
00109         const DiscoveredCharacteristic& characteristic
00110     );
00111 
00112     /**
00113      * @see GattClient::reset
00114      */
00115     virtual ble_error_t reset (void);
00116 
00117 private:
00118     struct ProcedureControlBlock;
00119     struct DiscoveryControlBlock;
00120     struct ReadControlBlock;
00121     struct WriteControlBlock;
00122     struct DescriptorDiscoveryControlBlock;
00123 
00124     ProcedureControlBlock* get_control_block(Gap::Handle_t connection);
00125     const ProcedureControlBlock* get_control_block(Gap::Handle_t connection) const;
00126     void insert_control_block(ProcedureControlBlock* cb) const;
00127     void remove_control_block(ProcedureControlBlock* cb) const;
00128 
00129     void on_termination(Gap::Handle_t connection_handle);
00130     void on_server_message_received(connection_handle_t, const pal::AttServerMessage&);
00131     void on_server_response(connection_handle_t, const pal::AttServerMessage&);
00132     void on_server_event(connection_handle_t, const pal::AttServerMessage&);
00133     void on_transaction_timeout(connection_handle_t);
00134 
00135     uint16_t get_mtu(Gap::Handle_t connection) const;
00136 
00137     pal::GattClient* const _pal_client;
00138     ServiceDiscovery::TerminationCallback_t  _termination_callback;
00139     mutable ProcedureControlBlock* control_blocks;
00140     bool _is_reseting;
00141 };
00142 
00143 }
00144 }
00145 
00146 #endif /* MBED_BLE_GENERIC_GATT_CLIENT */