High level Bluetooth Low Energy API and radio abstraction layer
Fork of BLE_API by
public/ServiceDiscovery.h@501:ff6801633d2c, 2015-06-19 (annotated)
- Committer:
- rgrover1
- Date:
- Fri Jun 19 15:52:03 2015 +0100
- Revision:
- 501:ff6801633d2c
- Parent:
- 497:926d444599e8
Synchronized with git rev 1a9e68e1
Author: Rohit Grover
ReadCallback_t moves into GattClient.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 431:1c8c592430ec | 1 | /* mbed Microcontroller Library |
rgrover1 | 431:1c8c592430ec | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 431:1c8c592430ec | 3 | * |
rgrover1 | 431:1c8c592430ec | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 431:1c8c592430ec | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 431:1c8c592430ec | 6 | * You may obtain a copy of the License at |
rgrover1 | 431:1c8c592430ec | 7 | * |
rgrover1 | 431:1c8c592430ec | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 431:1c8c592430ec | 9 | * |
rgrover1 | 431:1c8c592430ec | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 431:1c8c592430ec | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 431:1c8c592430ec | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 431:1c8c592430ec | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 431:1c8c592430ec | 14 | * limitations under the License. |
rgrover1 | 431:1c8c592430ec | 15 | */ |
rgrover1 | 431:1c8c592430ec | 16 | |
rgrover1 | 431:1c8c592430ec | 17 | #ifndef __SERVICE_DISOVERY_H__ |
rgrover1 | 431:1c8c592430ec | 18 | #define __SERVICE_DISOVERY_H__ |
rgrover1 | 431:1c8c592430ec | 19 | |
rgrover1 | 431:1c8c592430ec | 20 | #include "UUID.h" |
rgrover1 | 431:1c8c592430ec | 21 | #include "Gap.h" |
rgrover1 | 438:b55ce5f5715d | 22 | #include "GattAttribute.h" |
rgrover1 | 501:ff6801633d2c | 23 | |
rgrover1 | 501:ff6801633d2c | 24 | class DiscoveredService; |
rgrover1 | 501:ff6801633d2c | 25 | class DiscoveredCharacteristic; |
rgrover1 | 431:1c8c592430ec | 26 | |
rgrover1 | 431:1c8c592430ec | 27 | class ServiceDiscovery { |
rgrover1 | 431:1c8c592430ec | 28 | public: |
rgrover1 | 479:dbcb964cc288 | 29 | /* |
rgrover1 | 479:dbcb964cc288 | 30 | * Exposed application callback types. |
rgrover1 | 479:dbcb964cc288 | 31 | */ |
rgrover1 | 487:07d4423e442b | 32 | |
rgrover1 | 487:07d4423e442b | 33 | /** |
rgrover1 | 487:07d4423e442b | 34 | * Callback type for when a matching Service is found during service- |
rgrover1 | 487:07d4423e442b | 35 | * discovery. The receiving function is passed in a pointer to a |
rgrover1 | 487:07d4423e442b | 36 | * DiscoveredService object which will remain valid for the lifetime of the |
rgrover1 | 487:07d4423e442b | 37 | * callback. Memory for this object is owned by the BLE_API eventing |
rgrover1 | 487:07d4423e442b | 38 | * framework. The application can safely make a persistent shallow-copy of |
rgrover1 | 487:07d4423e442b | 39 | * this object in order to work with the service beyond the callback. |
rgrover1 | 487:07d4423e442b | 40 | */ |
rgrover1 | 478:230cd5e207ba | 41 | typedef void (*ServiceCallback_t)(const DiscoveredService *); |
rgrover1 | 487:07d4423e442b | 42 | |
rgrover1 | 487:07d4423e442b | 43 | /** |
rgrover1 | 487:07d4423e442b | 44 | * Callback type for when a matching Characteristic is found during service- |
rgrover1 | 487:07d4423e442b | 45 | * discovery. The receiving function is passed in a pointer to a |
rgrover1 | 487:07d4423e442b | 46 | * DiscoveredCharacteristic object which will remain valid for the lifetime |
rgrover1 | 487:07d4423e442b | 47 | * of the callback. Memory for this object is owned by the BLE_API eventing |
rgrover1 | 487:07d4423e442b | 48 | * framework. The application can safely make a persistent shallow-copy of |
rgrover1 | 487:07d4423e442b | 49 | * this object in order to work with the characteristic beyond the callback. |
rgrover1 | 487:07d4423e442b | 50 | */ |
rgrover1 | 476:122bcbdadb56 | 51 | typedef void (*CharacteristicCallback_t)(const DiscoveredCharacteristic *); |
rgrover1 | 487:07d4423e442b | 52 | |
rgrover1 | 487:07d4423e442b | 53 | /** |
rgrover1 | 487:07d4423e442b | 54 | * Callback type for when serviceDiscovery terminates. |
rgrover1 | 487:07d4423e442b | 55 | */ |
rgrover1 | 457:6ebc9bbde90b | 56 | typedef void (*TerminationCallback_t)(Gap::Handle_t connectionHandle); |
rgrover1 | 431:1c8c592430ec | 57 | |
rgrover1 | 431:1c8c592430ec | 58 | public: |
rgrover1 | 479:dbcb964cc288 | 59 | /** |
rgrover1 | 479:dbcb964cc288 | 60 | * Launch service discovery. Once launched, service discovery will remain |
rgrover1 | 479:dbcb964cc288 | 61 | * active with callbacks being issued back into the application for matching |
rgrover1 | 479:dbcb964cc288 | 62 | * services/characteristics. isActive() can be used to determine status; and |
rgrover1 | 479:dbcb964cc288 | 63 | * a termination callback (if setup) will be invoked at the end. Service |
rgrover1 | 479:dbcb964cc288 | 64 | * discovery can be terminated prematurely if needed using terminate(). |
rgrover1 | 479:dbcb964cc288 | 65 | * |
rgrover1 | 479:dbcb964cc288 | 66 | * @param connectionHandle |
rgrover1 | 479:dbcb964cc288 | 67 | * Handle for the connection with the peer. |
rgrover1 | 479:dbcb964cc288 | 68 | * @param sc |
rgrover1 | 479:dbcb964cc288 | 69 | * This is the application callback for matching service. Taken as |
rgrover1 | 479:dbcb964cc288 | 70 | * NULL by default. Note: service discovery may still be active |
rgrover1 | 479:dbcb964cc288 | 71 | * when this callback is issued; calling asynchronous BLE-stack |
rgrover1 | 479:dbcb964cc288 | 72 | * APIs from within this application callback might cause the |
rgrover1 | 479:dbcb964cc288 | 73 | * stack to abort service discovery. If this becomes an issue, it |
rgrover1 | 479:dbcb964cc288 | 74 | * may be better to make local copy of the discoveredService and |
rgrover1 | 479:dbcb964cc288 | 75 | * wait for service discovery to terminate before operating on the |
rgrover1 | 479:dbcb964cc288 | 76 | * service. |
rgrover1 | 479:dbcb964cc288 | 77 | * @param cc |
rgrover1 | 479:dbcb964cc288 | 78 | * This is the application callback for matching characteristic. |
rgrover1 | 479:dbcb964cc288 | 79 | * Taken as NULL by default. Note: service discovery may still be |
rgrover1 | 479:dbcb964cc288 | 80 | * active when this callback is issued; calling asynchronous |
rgrover1 | 479:dbcb964cc288 | 81 | * BLE-stack APIs from within this application callback might cause |
rgrover1 | 479:dbcb964cc288 | 82 | * the stack to abort service discovery. If this becomes an issue, |
rgrover1 | 479:dbcb964cc288 | 83 | * it may be better to make local copy of the discoveredCharacteristic |
rgrover1 | 479:dbcb964cc288 | 84 | * and wait for service discovery to terminate before operating on the |
rgrover1 | 479:dbcb964cc288 | 85 | * characteristic. |
rgrover1 | 479:dbcb964cc288 | 86 | * @param matchingServiceUUID |
rgrover1 | 479:dbcb964cc288 | 87 | * UUID based filter for specifying a service in which the application is |
rgrover1 | 479:dbcb964cc288 | 88 | * interested. By default it is set as the wildcard UUID_UNKNOWN, |
rgrover1 | 479:dbcb964cc288 | 89 | * in which case it matches all services. If characteristic-UUID |
rgrover1 | 479:dbcb964cc288 | 90 | * filter (below) is set to the wildcard value, then a service |
rgrover1 | 479:dbcb964cc288 | 91 | * callback will be invoked for the matching service (or for every |
rgrover1 | 479:dbcb964cc288 | 92 | * service if the service filter is a wildcard). |
rgrover1 | 479:dbcb964cc288 | 93 | * @param matchingCharacteristicUUIDIn |
rgrover1 | 479:dbcb964cc288 | 94 | * UUID based filter for specifying characteristic in which the application |
rgrover1 | 479:dbcb964cc288 | 95 | * is interested. By default it is set as the wildcard UUID_UKNOWN |
rgrover1 | 479:dbcb964cc288 | 96 | * to match against any characteristic. If both service-UUID |
rgrover1 | 479:dbcb964cc288 | 97 | * filter and characteristic-UUID filter are used with non- wildcard |
rgrover1 | 479:dbcb964cc288 | 98 | * values, then only a single characteristic callback is |
rgrover1 | 479:dbcb964cc288 | 99 | * invoked for the matching characteristic. |
rgrover1 | 479:dbcb964cc288 | 100 | * |
rgrover1 | 482:a4c6ac278fd4 | 101 | * @Note Using wildcard values for both service-UUID and characteristic- |
rgrover1 | 482:a4c6ac278fd4 | 102 | * UUID will result in complete service discovery--callbacks being |
rgrover1 | 482:a4c6ac278fd4 | 103 | * called for every service and characteristic. |
rgrover1 | 482:a4c6ac278fd4 | 104 | * |
rgrover1 | 479:dbcb964cc288 | 105 | * @return |
rgrover1 | 479:dbcb964cc288 | 106 | * BLE_ERROR_NONE if service discovery is launched successfully; else an appropriate error. |
rgrover1 | 479:dbcb964cc288 | 107 | */ |
rgrover1 | 497:926d444599e8 | 108 | virtual ble_error_t launch(Gap::Handle_t connectionHandle, |
rgrover1 | 497:926d444599e8 | 109 | ServiceCallback_t sc = NULL, |
rgrover1 | 497:926d444599e8 | 110 | CharacteristicCallback_t cc = NULL, |
rgrover1 | 497:926d444599e8 | 111 | const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN), |
rgrover1 | 497:926d444599e8 | 112 | const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) = 0; |
rgrover1 | 497:926d444599e8 | 113 | |
rgrover1 | 497:926d444599e8 | 114 | /** |
rgrover1 | 497:926d444599e8 | 115 | * Is service-discovery currently active? |
rgrover1 | 497:926d444599e8 | 116 | */ |
rgrover1 | 497:926d444599e8 | 117 | virtual bool isActive(void) const = 0; |
rgrover1 | 431:1c8c592430ec | 118 | |
rgrover1 | 474:2a8a453ecd7e | 119 | /** |
rgrover1 | 474:2a8a453ecd7e | 120 | * Terminate an ongoing service-discovery. This should result in an |
rgrover1 | 474:2a8a453ecd7e | 121 | * invocation of the TerminationCallback if service-discovery is active. |
rgrover1 | 474:2a8a453ecd7e | 122 | */ |
rgrover1 | 497:926d444599e8 | 123 | virtual void terminate(void) = 0; |
rgrover1 | 474:2a8a453ecd7e | 124 | |
rgrover1 | 474:2a8a453ecd7e | 125 | /** |
rgrover1 | 474:2a8a453ecd7e | 126 | * Setup callback to be invoked when service discovery is terminated. |
rgrover1 | 474:2a8a453ecd7e | 127 | */ |
rgrover1 | 497:926d444599e8 | 128 | virtual void onTermination(TerminationCallback_t callback) = 0; |
rgrover1 | 457:6ebc9bbde90b | 129 | |
rgrover1 | 431:1c8c592430ec | 130 | protected: |
rgrover1 | 431:1c8c592430ec | 131 | Gap::Handle_t connHandle; /**< Connection handle as provided by the SoftDevice. */ |
rgrover1 | 431:1c8c592430ec | 132 | UUID matchingServiceUUID; |
rgrover1 | 431:1c8c592430ec | 133 | ServiceCallback_t serviceCallback; |
rgrover1 | 431:1c8c592430ec | 134 | UUID matchingCharacteristicUUID; |
rgrover1 | 431:1c8c592430ec | 135 | CharacteristicCallback_t characteristicCallback; |
rgrover1 | 431:1c8c592430ec | 136 | }; |
rgrover1 | 431:1c8c592430ec | 137 | |
rgrover1 | 431:1c8c592430ec | 138 | #endif // ifndef __SERVICE_DISOVERY_H__ |