Android Open Source - LeBlue Session Object






From Project

Back to project page LeBlue.

License

The source code is released under:

Apache License

If you think the Android project LeBlue listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package houtbecke.rs.le.session;
//from   w  ww. j a v  a 2 s  .c o m
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public class SessionObject implements Session {

    public static SessionObject newSession() {
        return new SessionObject();
    }

    public MockerObject withObjectMocker(int source) {
        return MockerObject.newMocker(this, source);
    }

    int defaultDelay = 0;

    public SessionObject setDefaultDelay(int defaultDelay) {
        this.defaultDelay=defaultDelay;
        return this;
    }

    public int getDefaultDelay() {
        return defaultDelay;
    }

    public SessionObject setDefaultSource(EventSource defaultSource) {
        this.defaultSource = defaultSource;
        return this;
    }

    public DeviceMockerObject withFakeDevice(int... remoteDevices) {
        return
            withDeviceMocker()
                .hasRemoteDevices(0, new byte[] {0}, remoteDevices)
                .withFakeDeviceListeners();


    }

    public DeviceMockerObject withFakeDevices(int[] remoteDevices, byte[]... scanRecords) {
        if (remoteDevices.length != scanRecords.length)
            throw new RuntimeException("scanRecords and remoteDevices differ in number");
        DeviceMockerObject ret = withDeviceMocker().withFakeDeviceListeners();
        for (int k=0; k < remoteDevices.length; k++)
            ret.hasRemoteDevice(scanRecords[k], remoteDevices[k]);

        return ret;
    }


    public DeviceMockerObject withDeviceMocker() {
        return withDeviceMocker(EventSinkFiller.DEFAULT_DEVICE_ID);
    }

    public DeviceMockerObject withDeviceMocker(int id) {
        DeviceMockerObject ret = new DeviceMockerObject(this, id);
        devices.put(id, ret);
        return ret;
    }

    public SessionObject withDeviceMocker(int id, Mocker device) {
        devices.put(id, device);
        return this;
    }

    public SessionObject withDeviceMocker(Mocker device) {
        devices.put(EventSinkFiller.DEFAULT_DEVICE_ID, device);
        return this;
    }


    public RemoteDeviceMockerObject withFakeRemoteDevice(int id, String address, String name, boolean connects, int... services) {
        return withRemoteDeviceMocker(id)
                .withFakeCharacteristicsListeners()
                .withFakeRemoteDeviceListeners()
                .mocksRemoteDevice(address, name, connects)
                .hasServices(services);
    }

    public RemoteDeviceMockerObject withRemoteDeviceMocker(int id) {
        RemoteDeviceMockerObject remoteDeviceMocker = new RemoteDeviceMockerObject(this, id);
        remoteDevices.put(id, remoteDeviceMocker);
        return remoteDeviceMocker;
    }

    public SessionObject withRemoteDeviceMocker(int id, Mocker remoteDevice) {
        remoteDevices.put(id, remoteDevice);
        return this;
    }

    public GattServiceMockerObject withFakeService(int id, UUID uuid) {
        return withGattServiceMocker(id).mocksService(uuid);
    }


    public GattServiceMockerObject withGattServiceMocker(int id) {
        GattServiceMockerObject service = new GattServiceMockerObject(this, id);
        gattServices.put(id, service);
        return service;
    }

    public SessionObject withGattServiceMocker(int id, Mocker service) {
        gattServices.put(id, service);
        return this;
    }

    public CharacteristicsMockerObject withGattCharacteristicsMocker(int id) {
        CharacteristicsMockerObject ret = new CharacteristicsMockerObject(this, id);
        gattCharacteristics.put(id, ret);
        return ret;
    }

    public SessionObject withGattCharacteristicsMocker(int id, Mocker characteristic) {
        gattCharacteristics.put(id, characteristic);
        return this;
    }

    public SessionObject withNamedEventSource(String name, EventSource eventSource) {
        eventSources.put(name, eventSource);
        return this;
    }

    public EventSinkFiller withNamedEventSourceFiller(String name) {
        ListEventSinkSource source = new ListEventSinkSource();
        EventSinkFiller filler = new EventSinkFiller(source, this);
        eventSources.put(name, source);
        return filler;
    }

    public SessionObject withDefaultEventSource(EventSource defaultSource) {
        this.defaultSource = defaultSource;
        return this;
    }

    public EventSinkFiller withDefaultEventSourceFiller() {
        ListEventSinkSource source = new ListEventSinkSource();
        EventSinkFiller filler = new EventSinkFiller(source, this);
        defaultSource = source;
        return filler;
    }

    public SessionObject withEndEvent() {
        ListEventSinkSource source = new ListEventSinkSource();
        EventSinkFiller filler = new EventSinkFiller(source, this);
        defaultSource = source;
        return filler.waitForPoint("end").and;
    }


    Map<Integer, Mocker> devices = new HashMap<>();
    Map<Integer, Mocker> remoteDevices = new HashMap<>();
    Map<Integer, Mocker> gattServices = new HashMap<>();
    Map<Integer, Mocker> gattCharacteristics = new HashMap<>();

    EventSource defaultSource;

    Map<String, EventSource> eventSources = new HashMap<>(0);

    @Override
    public Mocker getGattCharacteristicMocker(int id) {
        return gattCharacteristics.get(id);
    }

    @Override
    public Mocker getGattServiceMocker(int id) {
        return gattServices.get(id);
    }

    @Override
    public Mocker getDeviceMocker(int id) {
        return devices.get(id);
    }

    @Override
    public Mocker getRemoteDeviceMocker(int device) {
        return remoteDevices.get(device);
    }

    @Override
    public EventSource getDefaultSource() {
        return defaultSource;
    }

    @Override
    public EventSource getNamedEventSource(String source) {
        return eventSources.get(source);
    }

    @Override
    public String[] getEventSourceNames() {
        Set<String> strings = eventSources.keySet();
        return strings.toArray(new String[strings.size()]);
    }


    Map<Integer, String> sourceIdentifications = new HashMap<>();

    @Override
    public String getSourceIdentification(int source) {
        String ret = sourceIdentifications.get(source);
        if (ret == null) throw new RuntimeException("Trying to reference a mocked source by only it's id ("+source+"),  and it's identification string has not yet been specified");
        return ret;
    }

    @Override
    public void setSourceIdentification(int source, String identification) {
        sourceIdentifications.put(source, identification);
    }

}




Java Source Code List

houtbecke.rs.le.BleException.java
houtbecke.rs.le.LeCharacteristicListener.java
houtbecke.rs.le.LeDefinedUUIDs.java
houtbecke.rs.le.LeDeviceListener.java
houtbecke.rs.le.LeDeviceState.java
houtbecke.rs.le.LeDevice.java
houtbecke.rs.le.LeFormat.java
houtbecke.rs.le.LeGattCharacteristic.java
houtbecke.rs.le.LeGattDescriptorValue.java
houtbecke.rs.le.LeGattDescriptor.java
houtbecke.rs.le.LeGattService.java
houtbecke.rs.le.LeGattStatus.java
houtbecke.rs.le.LeRecord.java
houtbecke.rs.le.LeRemoteDeviceListener.java
houtbecke.rs.le.LeRemoteDevice.java
houtbecke.rs.le.LeScanRecordImpl.java
houtbecke.rs.le.LeScanRecord.java
houtbecke.rs.le.LeUtil.java
houtbecke.rs.le.dummy.DummyLeRemoteDevice.java
houtbecke.rs.le.example.MainActivity.java
houtbecke.rs.le.fourdotthree.LeDevice43.java
houtbecke.rs.le.fourdotthree.LeGattCharacteristic43.java
houtbecke.rs.le.fourdotthree.LeGattService43.java
houtbecke.rs.le.fourdotthree.LeRemoteDevice43.java
houtbecke.rs.le.interceptor.AndroidEventSinkUtil.java
houtbecke.rs.le.interceptor.BaseIntercepting.java
houtbecke.rs.le.interceptor.EventSinkUtil.java
houtbecke.rs.le.interceptor.InterceptingLeCharacteristicListener.java
houtbecke.rs.le.interceptor.InterceptingLeDeviceListener.java
houtbecke.rs.le.interceptor.InterceptingLeDevice.java
houtbecke.rs.le.interceptor.InterceptingLeGattCharacteristic.java
houtbecke.rs.le.interceptor.InterceptingLeGattService.java
houtbecke.rs.le.interceptor.InterceptingLeRemoteDeviceListener.java
houtbecke.rs.le.interceptor.InterceptingLeRemoteDevice.java
houtbecke.rs.le.interceptor.LeInterceptor.java
houtbecke.rs.le.interceptor.LeLogCatInterceptor.java
houtbecke.rs.le.interceptor.LeSessionInterceptor.java
houtbecke.rs.le.mock.LeDeviceMock.java
houtbecke.rs.le.mock.LeGattCharacteristicMock.java
houtbecke.rs.le.mock.LeGattServiceMock.java
houtbecke.rs.le.mock.LeMockController.java
houtbecke.rs.le.mock.LeRemoteDeviceMock.java
houtbecke.rs.le.mock.LeSessionController.java
houtbecke.rs.le.mock.NativeWaitNotify.java
houtbecke.rs.le.mock.SimpleWaitNotify.java
houtbecke.rs.le.mock.WaitNotify.java
houtbecke.rs.le.session.CharacteristicsMockerObject.java
houtbecke.rs.le.session.DeviceMockerObject.java
houtbecke.rs.le.session.EventSinkFiller.java
houtbecke.rs.le.session.EventSink.java
houtbecke.rs.le.session.EventSource.java
houtbecke.rs.le.session.EventType.java
houtbecke.rs.le.session.Event.java
houtbecke.rs.le.session.GattServiceMockerObject.java
houtbecke.rs.le.session.ListEventSinkSource.java
houtbecke.rs.le.session.MockedResponseObject.java
houtbecke.rs.le.session.MockedResponse.java
houtbecke.rs.le.session.MockerObject.java
houtbecke.rs.le.session.Mocker.java
houtbecke.rs.le.session.RemoteDeviceMockerObject.java
houtbecke.rs.le.session.SessionObject.java
houtbecke.rs.le.session.Session.java