No changes

Fork of nRF51822 by Nordic Semiconductor

Revision:
286:042b01e59cf8
Parent:
284:29fb6af6671d
Child:
288:1d85c4a4d397
diff -r 55ac765bcc8d -r 042b01e59cf8 btle/btle_discovery.h
--- a/btle/btle_discovery.h	Fri Jun 19 15:55:27 2015 +0100
+++ b/btle/btle_discovery.h	Fri Jun 19 15:55:27 2015 +0100
@@ -41,9 +41,7 @@
 
     void terminateServiceDiscovery(void) {
         bool wasActive = isActive();
-
-        sDiscoveryActive = false;
-        cDiscoveryActive = false;
+        state = INACTIVE;
 
         if (wasActive && onTerminationCallback) {
             onTerminationCallback(connHandle);
@@ -51,13 +49,14 @@
     }
 
     void terminateCharacteristicDiscovery(void) {
-        cDiscoveryActive = false;
-        sDiscoveryActive = true;
+        if (state == CHARACTERISTIC_DISCOVERY_ACTIVE) {
+            state = SERVICE_DISCOVERY_ACTIVE;
+        }
         serviceIndex++; /* Progress service index to keep discovery alive. */
     }
 
     bool isActive(void) const {
-        return (sDiscoveryActive || cDiscoveryActive);
+        return state != INACTIVE;
     }
 
     void setOnTermination(TerminationCallback_t callback) {
@@ -81,16 +80,14 @@
     void serviceDiscoveryStarted(Gap::Handle_t connectionHandle) {
         connHandle       = connectionHandle;
         resetDiscoveredServices();
-        sDiscoveryActive = true;
-        cDiscoveryActive = false;
+        state = SERVICE_DISCOVERY_ACTIVE;
     }
 
 private:
     void characteristicDiscoveryStarted(Gap::Handle_t connectionHandle) {
         connHandle       = connectionHandle;
         resetDiscoveredCharacteristics();
-        cDiscoveryActive = true;
-        sDiscoveryActive = false;
+        state = CHARACTERISTIC_DISCOVERY_ACTIVE;
     }
 
 private:
@@ -104,8 +101,11 @@
     uint8_t  characteristicIndex; /**< Index of the current characteristic being discovered. This is intended for internal use during service discovery.*/
     uint8_t  numCharacteristics;  /**< Number of characteristics within the service.*/
 
-    bool     sDiscoveryActive;
-    bool     cDiscoveryActive;
+    enum State_t {
+        INACTIVE,
+        SERVICE_DISCOVERY_ACTIVE,
+        CHARACTERISTIC_DISCOVERY_ACTIVE,
+    } state;
 
     DiscoveredService        services[BLE_DB_DISCOVERY_MAX_SRV];  /**< Information related to the current service being discovered.
                                                                    *  This is intended for internal use during service discovery. */