|
| 1 | +/* mbed Microcontroller Library |
| 2 | + * Copyright (c) 2006-2020 ARM Limited |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +#ifndef MBED_CHAINABLEGATTSERVEREVENTHANDLER_H_ |
| 20 | +#define MBED_CHAINABLEGATTSERVEREVENTHANDLER_H_ |
| 21 | + |
| 22 | +#include "ble/GattServer.h" |
| 23 | +#include "ble/common/ChainableEventHandler.h" |
| 24 | + |
| 25 | +/** |
| 26 | + * GattServer::EventHandler implementation that allows the application |
| 27 | + * to register multiple separate EventHandlers to be called when |
| 28 | + * GattServer events happen. |
| 29 | + */ |
| 30 | +class ChainableGattServerEventHandler : public ble::GattServer::EventHandler, |
| 31 | + public ChainableEventHandler<ble::GattServer::EventHandler> |
| 32 | +{ |
| 33 | + |
| 34 | +public: |
| 35 | + |
| 36 | + ChainableGattServerEventHandler() { } |
| 37 | + |
| 38 | + virtual ~ChainableGattServerEventHandler() { } |
| 39 | + |
| 40 | + /** |
| 41 | + * Function invoked when the connections changes the ATT_MTU which controls |
| 42 | + * the maximum size of an attribute that can be read in a single L2CAP packet |
| 43 | + * which might be fragmented across multiple packets. |
| 44 | + * |
| 45 | + * @param connectionHandle The handle of the connection that changed the size. |
| 46 | + * @param attMtuSize |
| 47 | + */ |
| 48 | + void onAttMtuChange(ble::connection_handle_t connectionHandle, uint16_t attMtuSize) override { |
| 49 | + execute_on_all(&ble::GattServer::EventHandler::onAttMtuChange, |
| 50 | + connectionHandle, attMtuSize); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Function invoked when the server has sent data to a client as |
| 55 | + * part of a notification/indication. |
| 56 | + * |
| 57 | + * @note params has a temporary scope and should be copied by the |
| 58 | + * application if needed later |
| 59 | + */ |
| 60 | + void onDataSent(const GattDataSentCallbackParams* params) override { |
| 61 | + execute_on_all(&ble::GattServer::EventHandler::onDataSent, params); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Function invoked when a client writes an attribute |
| 66 | + * |
| 67 | + * @note params has a temporary scope and should be copied by the |
| 68 | + * application if needed later |
| 69 | + */ |
| 70 | + void onDataWritten(const GattWriteCallbackParams *params) override { |
| 71 | + execute_on_all(&ble::GattServer::EventHandler::onDataWritten, params); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Function invoked when a client reads an attribute |
| 76 | + * |
| 77 | + * @note This functionality may not be available on all underlying stacks. |
| 78 | + * Application code may work around that limitation by monitoring read |
| 79 | + * requests instead of read events. |
| 80 | + * |
| 81 | + * @note params has a temporary scope and should be copied by the |
| 82 | + * application if needed later |
| 83 | + * |
| 84 | + * @see GattCharacteristic::setReadAuthorizationCallback() |
| 85 | + * @see isOnDataReadAvailable(). |
| 86 | + */ |
| 87 | + void onDataRead(const GattReadCallbackParams *params) override { |
| 88 | + execute_on_all(&ble::GattServer::EventHandler::onDataRead, params); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Function invoked when the GattServer instance is about |
| 93 | + * to be shut down. This can result in a call to reset() or BLE::reset(). |
| 94 | + */ |
| 95 | + void onShutdown(const GattServer *server) override { |
| 96 | + execute_on_all(&ble::GattServer::EventHandler::onShutdown, server); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Function invoked when the client has subscribed to characteristic updates |
| 101 | + * |
| 102 | + * @note params has a temporary scope and should be copied by the |
| 103 | + * application if needed later |
| 104 | + */ |
| 105 | + void onUpdatesEnabled(const GattUpdatesEnabledCallbackParams* params) override { |
| 106 | + execute_on_all(&ble::GattServer::EventHandler::onUpdatesEnabled, params); |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Function invoked when the client has unsubscribed to characteristic updates |
| 111 | + * |
| 112 | + * @note params has a temporary scope and should be copied by the |
| 113 | + * application if needed later |
| 114 | + */ |
| 115 | + void onUpdatesDisabled(const GattUpdatesDisabledCallbackParams* params) override { |
| 116 | + execute_on_all(&ble::GattServer::EventHandler::onUpdatesDisabled, params); |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * Function invoked when an ACK has been received for an |
| 121 | + * indication sent to the client. |
| 122 | + * |
| 123 | + * @note params has a temporary scope and should be copied by the |
| 124 | + * application if needed later |
| 125 | + */ |
| 126 | + void onConfirmationReceived(const GattConfirmationReceivedCallbackParams* params) override { |
| 127 | + execute_on_all(&ble::GattServer::EventHandler::onConfirmationReceived, params); |
| 128 | + } |
| 129 | + |
| 130 | +}; |
| 131 | + |
| 132 | +#endif /* MBED_CHAINABLEGATTSERVEREVENTHANDLER_H_ */ |
0 commit comments