-
Notifications
You must be signed in to change notification settings - Fork 574
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a way to execute custom RxBleRadioOperation
The RxBleConnection interface has now a new method named queue that enable library consumer to queue their own RxBleRadioOperation. The queue method receives in parameter a RxBleRadioOperationCustom implementation. This said implementation receives the underlying Android BLE API objects and is responsible of returning an Observable<T> that executes the operation asynchrounously. The Observable<T> returned is then executed as part of normal queue processing logic. The queue is released when the Observable<T> terminates either via an error or normally via complete. This feature shall be used only by people that studied the RxAndroidBLE source code and understand the implication of running their own operation.
- Loading branch information
1 parent
eb2eab4
commit fb2eccc
Showing
17 changed files
with
491 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
rxandroidble/src/main/java/com/polidea/rxandroidble/RxBleRadioOperationCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.polidea.rxandroidble; | ||
|
||
import android.bluetooth.BluetoothGatt; | ||
import android.support.annotation.NonNull; | ||
|
||
import com.polidea.rxandroidble.internal.RxBleRadio; | ||
import com.polidea.rxandroidble.internal.connection.RxBleGattCallback; | ||
|
||
import rx.Observable; | ||
import rx.Observer; | ||
import rx.Scheduler; | ||
import rx.android.schedulers.AndroidSchedulers; | ||
|
||
/** | ||
* Represents a custom operation that will be enqueued for future execution within the client instance. | ||
*/ | ||
public interface RxBleRadioOperationCustom<T> { | ||
|
||
/** | ||
* Return an observable that implement a custom radio operation using low-level Android BLE API. | ||
* <p> | ||
* The {@link Observable<T>} returned by this method will be subscribed to by the {@link RxBleRadio} | ||
* when it determines that the custom operation should be the next to be run. | ||
* <p> | ||
* The method receives everything needed to access the low-level Android BLE API objects mainly the | ||
* {@link BluetoothGatt} to interact with Android BLE GATT operations and {@link RxBleGattCallback} | ||
* to be notified when GATT operations completes. | ||
* <p> | ||
* Every event emitted by the returned {@link Observable<T>} will be forwarded to the observable | ||
* returned by {@link RxBleConnection#queue(RxBleRadioOperationCustom)} | ||
* <p> | ||
* As the implementer, your contract is to return an {@link Observable<T>} that completes at some | ||
* point in time. When the returned observable terminates, either via the {@link Observer#onCompleted()} or | ||
* {@link Observer#onError(Throwable)} callback, the {@link RxBleRadio} queue's lock is released so that | ||
* queue operations can continue. | ||
* <p> | ||
* You <b>must</b> ensure the returned {@link Observable<T>} do terminate either via {@code onCompleted} | ||
* or {@code onError(Throwable)}. Otherwise, the internal queue orchestrator will wait forever for | ||
* your {@link Observable<T>} to complete and the it will not continue to process queued operations. | ||
* | ||
* @param bluetoothGatt The Android API GATT instance | ||
* @param rxBleGattCallback The internal Rx ready bluetooth gatt callback to be notified of GATT operations | ||
* @param scheduler The RxBleRadio scheduler used to asObservable operation (currently {@link AndroidSchedulers#mainThread()} | ||
* @throws Throwable Any exception that your custom operation might throw | ||
*/ | ||
@NonNull | ||
Observable<T> asObservable(BluetoothGatt bluetoothGatt, | ||
RxBleGattCallback rxBleGattCallback, | ||
Scheduler scheduler) throws Throwable; | ||
} |
3 changes: 3 additions & 0 deletions
3
rxandroidble/src/main/java/com/polidea/rxandroidble/internal/RxBleRadio.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package com.polidea.rxandroidble.internal; | ||
|
||
import rx.Observable; | ||
import rx.Scheduler; | ||
|
||
public interface RxBleRadio { | ||
|
||
Scheduler scheduler(); | ||
|
||
<T> Observable<T> queue(RxBleRadioOperation<T> rxBleRadioOperation); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.