jgh

Dependents:   Migration

Fork of BLE_API by Bluetooth Low Energy

Revision:
811:059ed1c7b128
Parent:
810:c91bc1f5e035
Child:
817:7a23f308cfe1
diff -r c91bc1f5e035 -r 059ed1c7b128 ble/BLE.h
--- a/ble/BLE.h	Tue Sep 29 09:47:52 2015 +0100
+++ b/ble/BLE.h	Tue Sep 29 09:49:21 2015 +0100
@@ -154,6 +154,43 @@
         transport->waitForEvent();
     }
 
+public:
+    typedef unsigned InstanceID_t;
+    static const InstanceID_t DEFAULT_INSTANCE = 0;
+#ifndef YOTTA_CFG_BLE_INSTANCES_COUNT
+    static const InstanceID_t NUM_INSTANCES = 1;
+#else
+    static const InstanceID_t NUM_INSTANCES = YOTTA_CFG_BLE_INSTANCES_COUNT;
+#endif
+
+    /**
+     * Get a reference to the BLE singleton corresponding to a given interface.
+     * There is a static array of BLE singletons.
+     *
+     * @Note: Calling Instance() is preferred over constructing a BLE object
+     * directly, as it returns references to singletons.
+     *
+     * @param[in] id
+     *              Instance-ID. This should be less than NUM_INSTANCES in order
+     *              for the returned BLE singleton to be useful.
+     *
+     * @return a reference to a single object
+     */
+    static BLE &Instance(InstanceID_t id = DEFAULT_INSTANCE);
+
+    /**
+     * Constructor for a handle to a BLE instance (i.e. BLE stack). BLE handles
+     * are thin wrappers around a transport object (i.e. ptr. to
+     * BLEInstanceBase).
+     *
+     * BLE objects are are better created as singletons accessed through the
+     * Instance() method. If multiple BLE handles are constructed for the same
+     * interface (using this constructor), they will share the same underlying
+     * transport object.
+     */
+    BLE(InstanceID_t instanceID = DEFAULT_INSTANCE);
+
+
     /*
      * Deprecation alert!
      * All of the following are deprecated and may be dropped in a future
@@ -1362,17 +1399,12 @@
         return securityManager().onPasskeyDisplay(callback);
     }
 
-public:
-    BLE() : transport(createBLEInstance()) {
-        /* empty */
-    }
-
 private:
     BLE(const BLE&);
     BLE &operator=(const BLE &);
 
 private:
-    BLEInstanceBase *const transport; /* the device specific backend */
+    BLEInstanceBase *transport; /* the device specific backend */
 };
 
 typedef BLE BLEDevice; /* DEPRECATED. This type alias is retained for the sake of compatibility with older