com.polidea.rxandroidble2.RxBleCustomOperation Java Examples

The following examples show how to use com.polidea.rxandroidble2.RxBleCustomOperation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RxBleConnectionImpl.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@Override
public <T> Observable<T> queue(@NonNull final RxBleCustomOperation<T> operation) {
    return queue(operation, Priority.NORMAL);
}
 
Example #2
Source File: RxBleConnectionImpl.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@Override
public <T> Observable<T> queue(@NonNull final RxBleCustomOperation<T> operation, @NonNull final Priority priority) {
    return operationQueue.queue(new QueueOperation<T>() {
        @Override
        @SuppressWarnings("ConstantConditions")
        protected void protectedRun(final ObservableEmitter<T> emitter, final QueueReleaseInterface queueReleaseInterface)
                throws Throwable {
            final Observable<T> operationObservable;

            try {
                operationObservable = operation.asObservable(bluetoothGatt, gattCallback, callbackScheduler);
            } catch (Throwable throwable) {
                queueReleaseInterface.release();
                throw throwable;
            }

            if (operationObservable == null) {
                queueReleaseInterface.release();
                throw new IllegalArgumentException("The custom operation asObservable method must return a non-null observable");
            }

            final QueueReleasingEmitterWrapper<T> emitterWrapper = new QueueReleasingEmitterWrapper<>(emitter, queueReleaseInterface);
            operationObservable
                    .doOnTerminate(clearNativeCallbackReferenceAction())
                    .subscribe(emitterWrapper);
        }

        /**
         * The Native Callback abstractions is intended to be used only in a custom operation, therefore, to make sure
         * that we won't leak any references it's a good idea to clean it.
         */
        private Action clearNativeCallbackReferenceAction() {
            return new Action() {
                @Override
                public void run() {
                    gattCallback.setNativeCallback(null);
                    gattCallback.setHiddenNativeCallback(null);
                }
            };
        }

        @Override
        protected BleException provideException(DeadObjectException deadObjectException) {
            return new BleDisconnectedException(deadObjectException, bluetoothGatt.getDevice().getAddress(),
                    BleDisconnectedException.UNKNOWN_STATUS);
        }

        @Override
        public Priority definedPriority() {
            return priority;
        }
    });
}
 
Example #3
Source File: RxBleConnectionMock.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@Override
public <T> Observable<T> queue(@NonNull RxBleCustomOperation<T> operation) {
    throw new UnsupportedOperationException("Mock does not support queuing custom operation.");
}
 
Example #4
Source File: RxBleConnectionMock.java    From RxAndroidBle with Apache License 2.0 4 votes vote down vote up
@Override
public <T> Observable<T> queue(@NonNull RxBleCustomOperation<T> operation, Priority priority) {
    throw new UnsupportedOperationException("Mock does not support queuing custom operation.");
}