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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
ConnectionEventMonitor.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_CONNECTION_EVENT_MONITOR 00018 #define MBED_BLE_CONNECTION_EVENT_MONITOR 00019 00020 #include "ble/BLEProtocol.h" 00021 #include "ble/Gap.h" 00022 #include "ble/BLETypes.h" 00023 00024 namespace ble { 00025 namespace pal { 00026 00027 /** 00028 * Implemented by classes that are reacting to connection changes. 00029 * @see ConnectionEventMonitor 00030 */ 00031 template<class Impl> 00032 class ConnectionEventMonitorEventHandler { 00033 Impl* self() { 00034 return static_cast<Impl*>(this); 00035 } 00036 public: 00037 /** 00038 * Inform the Security manager of a new connection. This will create 00039 * or retrieve an existing security manager entry for the connected device. 00040 * Called by GAP. 00041 * 00042 * @param[in] connection Handle to identify the connection. 00043 * @param[in] role indicate if the device is central or peripheral. 00044 * @param[in] peer_address_type type of address. 00045 * @param[in] peer_address Address of the connected device. 00046 * @param[in] local_address_type type of address of the local device. 00047 * @param[in] local_address Address of the local device that was used during connection. 00048 * @param[in] connection_params connection parameters like interval, latency and timeout. 00049 * @param[in] resolved_peer_address resolved address of the peer; may 00050 * be NULL. 00051 */ 00052 void on_connected( 00053 connection_handle_t connection, 00054 ::Gap::Role_t role, 00055 ble::peer_address_type_t peer_address_type, 00056 const BLEProtocol::AddressBytes_t peer_address, 00057 BLEProtocol::AddressType_t local_address_type, 00058 const BLEProtocol::AddressBytes_t local_address, 00059 const ::Gap::ConnectionParams_t *connection_params 00060 ) { 00061 self()->on_connected_( 00062 connection, 00063 role, 00064 peer_address_type, 00065 peer_address, 00066 local_address_type, 00067 local_address, 00068 connection_params 00069 ); 00070 } 00071 00072 /** 00073 * Inform the monitor about a disconnection. 00074 * 00075 * @param[in] connectionHandle Handle to identify the connection. 00076 * @param[in] reason Reason for the disconnection. 00077 */ 00078 void on_disconnected( 00079 connection_handle_t connection, 00080 ::Gap::DisconnectionReason_t reason 00081 ) { 00082 self()->on_disconnected_(connection, reason); 00083 } 00084 }; 00085 00086 00087 /** 00088 * Implemented by classes that need to be notified of connection changes. 00089 * Notification is done by calling functions in the passed in event handler 00090 */ 00091 template<class EventHandler> 00092 class ConnectionEventMonitor { 00093 00094 protected: 00095 ConnectionEventMonitor() : _connection_event_handler(NULL) { } 00096 00097 EventHandler* _connection_event_handler; 00098 00099 public: 00100 /** 00101 * Register a handler for connection events to be used internally and serviced first. 00102 * 00103 * @param[in] connection_event_handler Event handler being registered. 00104 */ 00105 void set_connection_event_handler(EventHandler *connection_event_handler) { 00106 _connection_event_handler = connection_event_handler; 00107 } 00108 }; 00109 00110 } // namespace pal 00111 } // namespace ble 00112 00113 #endif /* MBED_BLE_CONNECTION_EVENT_MONITOR */
Generated on Tue Jul 12 2022 13:54:13 by
