No changes
Fork of nRF51822 by
source/nRF5xn.h@565:cf03471a4ec4, 2016-01-11 (annotated)
- Committer:
- vcoubard
- Date:
- Mon Jan 11 10:19:18 2016 +0000
- Revision:
- 565:cf03471a4ec4
- Parent:
- 463:b869f947a37a
- Child:
- 566:e425ad9e5d6e
Synchronized with git rev 0bcc2e96
Author: Andres Amaya Garcia
Modify shutdown due to BLE API change
The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:
* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
getGattClient, etc.
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vcoubard | 565:cf03471a4ec4 | 1 | /* mbed Microcontroller Library |
vcoubard | 565:cf03471a4ec4 | 2 | * Copyright (c) 2006-2013 ARM Limited |
vcoubard | 565:cf03471a4ec4 | 3 | * |
vcoubard | 565:cf03471a4ec4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
vcoubard | 565:cf03471a4ec4 | 5 | * you may not use this file except in compliance with the License. |
vcoubard | 565:cf03471a4ec4 | 6 | * You may obtain a copy of the License at |
vcoubard | 565:cf03471a4ec4 | 7 | * |
vcoubard | 565:cf03471a4ec4 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
vcoubard | 565:cf03471a4ec4 | 9 | * |
vcoubard | 565:cf03471a4ec4 | 10 | * Unless required by applicable law or agreed to in writing, software |
vcoubard | 565:cf03471a4ec4 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
vcoubard | 565:cf03471a4ec4 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
vcoubard | 565:cf03471a4ec4 | 13 | * See the License for the specific language governing permissions and |
vcoubard | 565:cf03471a4ec4 | 14 | * limitations under the License. |
vcoubard | 565:cf03471a4ec4 | 15 | */ |
vcoubard | 565:cf03471a4ec4 | 16 | |
vcoubard | 565:cf03471a4ec4 | 17 | #ifndef __NRF51822_H__ |
vcoubard | 565:cf03471a4ec4 | 18 | #define __NRF51822_H__ |
vcoubard | 565:cf03471a4ec4 | 19 | |
vcoubard | 565:cf03471a4ec4 | 20 | #include "ble/BLE.h" |
vcoubard | 565:cf03471a4ec4 | 21 | #include "ble/blecommon.h" |
vcoubard | 565:cf03471a4ec4 | 22 | #include "ble/BLEInstanceBase.h" |
vcoubard | 565:cf03471a4ec4 | 23 | |
vcoubard | 565:cf03471a4ec4 | 24 | #include "nRF5xGap.h" |
vcoubard | 565:cf03471a4ec4 | 25 | #include "nRF5xGattServer.h" |
vcoubard | 565:cf03471a4ec4 | 26 | #include "nRF5xGattClient.h" |
vcoubard | 565:cf03471a4ec4 | 27 | #include "nRF5xSecurityManager.h" |
vcoubard | 565:cf03471a4ec4 | 28 | |
vcoubard | 565:cf03471a4ec4 | 29 | #include "btle.h" |
vcoubard | 565:cf03471a4ec4 | 30 | |
vcoubard | 565:cf03471a4ec4 | 31 | class nRF5xn : public BLEInstanceBase |
vcoubard | 565:cf03471a4ec4 | 32 | { |
vcoubard | 565:cf03471a4ec4 | 33 | public: |
vcoubard | 565:cf03471a4ec4 | 34 | nRF5xn(void); |
vcoubard | 565:cf03471a4ec4 | 35 | virtual ~nRF5xn(void); |
vcoubard | 565:cf03471a4ec4 | 36 | |
vcoubard | 565:cf03471a4ec4 | 37 | virtual ble_error_t init(BLE::InstanceID_t instanceID, FunctionPointerWithContext<BLE::InitializationCompleteCallbackContext *> callback); |
vcoubard | 565:cf03471a4ec4 | 38 | virtual bool hasInitialized(void) const { |
vcoubard | 565:cf03471a4ec4 | 39 | return initialized; |
vcoubard | 565:cf03471a4ec4 | 40 | } |
vcoubard | 565:cf03471a4ec4 | 41 | virtual ble_error_t shutdown(void); |
vcoubard | 565:cf03471a4ec4 | 42 | virtual const char *getVersion(void); |
vcoubard | 565:cf03471a4ec4 | 43 | |
vcoubard | 565:cf03471a4ec4 | 44 | /** |
vcoubard | 565:cf03471a4ec4 | 45 | * Accessors to GAP. This function checks whether gapInstance points to an |
vcoubard | 565:cf03471a4ec4 | 46 | * object. If if does not, then the gapInstance is updated to |
vcoubard | 565:cf03471a4ec4 | 47 | * &_getInstance before returning. |
vcoubard | 565:cf03471a4ec4 | 48 | * |
vcoubard | 565:cf03471a4ec4 | 49 | * @return A reference to GattServer. |
vcoubard | 565:cf03471a4ec4 | 50 | * |
vcoubard | 565:cf03471a4ec4 | 51 | * @note Unlike the GattClient, GattServer and SecurityManager, Gap is |
vcoubard | 565:cf03471a4ec4 | 52 | * always needed in a BLE application. Therefore it is allocated |
vcoubard | 565:cf03471a4ec4 | 53 | * statically. |
vcoubard | 565:cf03471a4ec4 | 54 | */ |
vcoubard | 565:cf03471a4ec4 | 55 | virtual Gap &getGap() { |
vcoubard | 565:cf03471a4ec4 | 56 | if (gapInstance == NULL) { |
vcoubard | 565:cf03471a4ec4 | 57 | gapInstance = &_gapInstance; |
vcoubard | 565:cf03471a4ec4 | 58 | } |
vcoubard | 565:cf03471a4ec4 | 59 | return *gapInstance; |
vcoubard | 565:cf03471a4ec4 | 60 | }; |
vcoubard | 565:cf03471a4ec4 | 61 | |
vcoubard | 565:cf03471a4ec4 | 62 | /** |
vcoubard | 565:cf03471a4ec4 | 63 | * Accessors to GATT Server. This function checks whether a GattServer |
vcoubard | 565:cf03471a4ec4 | 64 | * object was previously instantiated. If such object does not exist, then |
vcoubard | 565:cf03471a4ec4 | 65 | * it is created before returning. |
vcoubard | 565:cf03471a4ec4 | 66 | * |
vcoubard | 565:cf03471a4ec4 | 67 | * @return A reference to GattServer. |
vcoubard | 565:cf03471a4ec4 | 68 | */ |
vcoubard | 565:cf03471a4ec4 | 69 | virtual GattServer &getGattServer() { |
vcoubard | 565:cf03471a4ec4 | 70 | if (gattServerInstance == NULL) { |
vcoubard | 565:cf03471a4ec4 | 71 | gattServerInstance = new nRF5xGattServer(); |
vcoubard | 565:cf03471a4ec4 | 72 | } |
vcoubard | 565:cf03471a4ec4 | 73 | return *gattServerInstance; |
vcoubard | 565:cf03471a4ec4 | 74 | }; |
vcoubard | 565:cf03471a4ec4 | 75 | |
vcoubard | 565:cf03471a4ec4 | 76 | /** |
vcoubard | 565:cf03471a4ec4 | 77 | * Accessors to GATT Client. This function checks whether a GattClient |
vcoubard | 565:cf03471a4ec4 | 78 | * object was previously instantiated. If such object does not exist, then |
vcoubard | 565:cf03471a4ec4 | 79 | * it is created before returning. |
vcoubard | 565:cf03471a4ec4 | 80 | * |
vcoubard | 565:cf03471a4ec4 | 81 | * @return A reference to GattClient. |
vcoubard | 565:cf03471a4ec4 | 82 | */ |
vcoubard | 565:cf03471a4ec4 | 83 | virtual GattClient &getGattClient() { |
vcoubard | 565:cf03471a4ec4 | 84 | if (gattClientInstance == NULL) { |
vcoubard | 565:cf03471a4ec4 | 85 | gattClientInstance = new nRF5xGattClient(); |
vcoubard | 565:cf03471a4ec4 | 86 | } |
vcoubard | 565:cf03471a4ec4 | 87 | return *gattClientInstance; |
vcoubard | 565:cf03471a4ec4 | 88 | } |
vcoubard | 565:cf03471a4ec4 | 89 | |
vcoubard | 565:cf03471a4ec4 | 90 | /** |
vcoubard | 565:cf03471a4ec4 | 91 | * Accessors to Security Manager. This function checks whether a SecurityManager |
vcoubard | 565:cf03471a4ec4 | 92 | * object was previously instantiated. If such object does not exist, then |
vcoubard | 565:cf03471a4ec4 | 93 | * it is created before returning. |
vcoubard | 565:cf03471a4ec4 | 94 | * |
vcoubard | 565:cf03471a4ec4 | 95 | * @return A reference to GattServer. |
vcoubard | 565:cf03471a4ec4 | 96 | */ |
vcoubard | 565:cf03471a4ec4 | 97 | virtual SecurityManager &getSecurityManager() { |
vcoubard | 565:cf03471a4ec4 | 98 | if (securityManagerInstance == NULL) { |
vcoubard | 565:cf03471a4ec4 | 99 | securityManagerInstance = new nRF5xSecurityManager(); |
vcoubard | 565:cf03471a4ec4 | 100 | } |
vcoubard | 565:cf03471a4ec4 | 101 | return *securityManagerInstance; |
vcoubard | 565:cf03471a4ec4 | 102 | } |
vcoubard | 565:cf03471a4ec4 | 103 | |
vcoubard | 565:cf03471a4ec4 | 104 | /** |
vcoubard | 565:cf03471a4ec4 | 105 | * Accessors to GAP. This function checks whether gapInstance points to an |
vcoubard | 565:cf03471a4ec4 | 106 | * object. If if does not, then the gapInstance is updated to |
vcoubard | 565:cf03471a4ec4 | 107 | * &_getInstance before returning. |
vcoubard | 565:cf03471a4ec4 | 108 | * |
vcoubard | 565:cf03471a4ec4 | 109 | * @return A const reference to GattServer. |
vcoubard | 565:cf03471a4ec4 | 110 | * |
vcoubard | 565:cf03471a4ec4 | 111 | * @note Unlike the GattClient, GattServer and SecurityManager, Gap is |
vcoubard | 565:cf03471a4ec4 | 112 | * always needed in a BLE application. Therefore it is allocated |
vcoubard | 565:cf03471a4ec4 | 113 | * statically. |
vcoubard | 565:cf03471a4ec4 | 114 | * |
vcoubard | 565:cf03471a4ec4 | 115 | * @note The accessor is able to modify the object's state because the |
vcoubard | 565:cf03471a4ec4 | 116 | * internal pointer has been declared mutable. |
vcoubard | 565:cf03471a4ec4 | 117 | */ |
vcoubard | 565:cf03471a4ec4 | 118 | virtual const Gap &getGap() const { |
vcoubard | 565:cf03471a4ec4 | 119 | if (gapInstance == NULL) { |
vcoubard | 565:cf03471a4ec4 | 120 | gapInstance = &_gapInstance; |
vcoubard | 565:cf03471a4ec4 | 121 | } |
vcoubard | 565:cf03471a4ec4 | 122 | return *gapInstance; |
vcoubard | 565:cf03471a4ec4 | 123 | }; |
vcoubard | 565:cf03471a4ec4 | 124 | |
vcoubard | 565:cf03471a4ec4 | 125 | /** |
vcoubard | 565:cf03471a4ec4 | 126 | * Accessors to GATT Server. This function checks whether a GattServer |
vcoubard | 565:cf03471a4ec4 | 127 | * object was previously instantiated. If such object does not exist, then |
vcoubard | 565:cf03471a4ec4 | 128 | * it is created before returning. |
vcoubard | 565:cf03471a4ec4 | 129 | * |
vcoubard | 565:cf03471a4ec4 | 130 | * @return A const reference to GattServer. |
vcoubard | 565:cf03471a4ec4 | 131 | * |
vcoubard | 565:cf03471a4ec4 | 132 | * @note The accessor is able to modify the object's state because the |
vcoubard | 565:cf03471a4ec4 | 133 | * internal pointer has been declared mutable. |
vcoubard | 565:cf03471a4ec4 | 134 | */ |
vcoubard | 565:cf03471a4ec4 | 135 | virtual const GattServer &getGattServer() const { |
vcoubard | 565:cf03471a4ec4 | 136 | if (gattServerInstance == NULL) { |
vcoubard | 565:cf03471a4ec4 | 137 | gattServerInstance = new nRF5xGattServer(); |
vcoubard | 565:cf03471a4ec4 | 138 | } |
vcoubard | 565:cf03471a4ec4 | 139 | return *gattServerInstance; |
vcoubard | 565:cf03471a4ec4 | 140 | }; |
vcoubard | 565:cf03471a4ec4 | 141 | |
vcoubard | 565:cf03471a4ec4 | 142 | /** |
vcoubard | 565:cf03471a4ec4 | 143 | * Accessors to Security Manager. This function checks whether a SecurityManager |
vcoubard | 565:cf03471a4ec4 | 144 | * object was previously instantiated. If such object does not exist, then |
vcoubard | 565:cf03471a4ec4 | 145 | * it is created before returning. |
vcoubard | 565:cf03471a4ec4 | 146 | * |
vcoubard | 565:cf03471a4ec4 | 147 | * @return A const reference to GattServer. |
vcoubard | 565:cf03471a4ec4 | 148 | * |
vcoubard | 565:cf03471a4ec4 | 149 | * @note The accessor is able to modify the object's state because the |
vcoubard | 565:cf03471a4ec4 | 150 | * internal pointer has been declared mutable. |
vcoubard | 565:cf03471a4ec4 | 151 | */ |
vcoubard | 565:cf03471a4ec4 | 152 | virtual const SecurityManager &getSecurityManager() const { |
vcoubard | 565:cf03471a4ec4 | 153 | if (securityManagerInstance == NULL) { |
vcoubard | 565:cf03471a4ec4 | 154 | securityManagerInstance = new nRF5xSecurityManager(); |
vcoubard | 565:cf03471a4ec4 | 155 | } |
vcoubard | 565:cf03471a4ec4 | 156 | return *securityManagerInstance; |
vcoubard | 565:cf03471a4ec4 | 157 | } |
vcoubard | 565:cf03471a4ec4 | 158 | |
vcoubard | 565:cf03471a4ec4 | 159 | virtual void waitForEvent(void); |
vcoubard | 565:cf03471a4ec4 | 160 | |
vcoubard | 565:cf03471a4ec4 | 161 | public: |
vcoubard | 565:cf03471a4ec4 | 162 | static nRF5xn& Instance(BLE::InstanceID_t instanceId); |
vcoubard | 565:cf03471a4ec4 | 163 | |
vcoubard | 565:cf03471a4ec4 | 164 | private: |
vcoubard | 565:cf03471a4ec4 | 165 | bool initialized; |
vcoubard | 565:cf03471a4ec4 | 166 | BLE::InstanceID_t instanceID; |
vcoubard | 565:cf03471a4ec4 | 167 | |
vcoubard | 565:cf03471a4ec4 | 168 | private: |
vcoubard | 565:cf03471a4ec4 | 169 | static nRF5xGap _gapInstance; /**< Gap instance whose reference is returned from a call to |
vcoubard | 565:cf03471a4ec4 | 170 | * getGap(). Unlike the GattClient, GattServer and |
vcoubard | 565:cf03471a4ec4 | 171 | * SecurityManager, Gap is always needed in a BLE application. |
vcoubard | 565:cf03471a4ec4 | 172 | * Therefore it is allocated statically. */ |
vcoubard | 565:cf03471a4ec4 | 173 | |
vcoubard | 565:cf03471a4ec4 | 174 | private: |
vcoubard | 565:cf03471a4ec4 | 175 | mutable nRF5xGap *gapInstance; /**< Pointer to the Gap object instance. |
vcoubard | 565:cf03471a4ec4 | 176 | * If NULL, then Gap has not been initialized. |
vcoubard | 565:cf03471a4ec4 | 177 | * The pointer has been declared as 'mutable' so that |
vcoubard | 565:cf03471a4ec4 | 178 | * it can be assigned inside a 'const' function. */ |
vcoubard | 565:cf03471a4ec4 | 179 | mutable nRF5xGattServer *gattServerInstance; /**< Pointer to the GattServer object instance. |
vcoubard | 565:cf03471a4ec4 | 180 | * If NULL, then GattServer has not been initialized. |
vcoubard | 565:cf03471a4ec4 | 181 | * The pointer has been declared as 'mutable' so that |
vcoubard | 565:cf03471a4ec4 | 182 | * it can be assigned inside a 'const' function. */ |
vcoubard | 565:cf03471a4ec4 | 183 | mutable nRF5xGattClient *gattClientInstance; /**< Pointer to the GattClient object instance. |
vcoubard | 565:cf03471a4ec4 | 184 | * If NULL, then GattClient has not been initialized. |
vcoubard | 565:cf03471a4ec4 | 185 | * The pointer has been declared as 'mutable' so that |
vcoubard | 565:cf03471a4ec4 | 186 | * it can be assigned inside a 'const' function. */ |
vcoubard | 565:cf03471a4ec4 | 187 | mutable nRF5xSecurityManager *securityManagerInstance; /**< Pointer to the SecurityManager object instance. |
vcoubard | 565:cf03471a4ec4 | 188 | * If NULL, then SecurityManager has not been initialized. |
vcoubard | 565:cf03471a4ec4 | 189 | * The pointer has been declared as 'mutable' so that |
vcoubard | 565:cf03471a4ec4 | 190 | * it can be assigned inside a 'const' function. */ |
vcoubard | 565:cf03471a4ec4 | 191 | }; |
vcoubard | 565:cf03471a4ec4 | 192 | |
rgrover1 | 388:db85a09c27ef | 193 | #endif |