Class GattServer

java.lang.Object
com.codename1.bluetooth.le.server.GattServer

public abstract class GattServer extends Object

The local GATT server, opened via BluetoothLE.openGattServer when this device acts as a BLE peripheral. Add GattLocalService definitions, respond to central requests through the GattServerListener and push value changes with [#notifyValue(GattLocalCharacteristic, byte[])].

All listener callbacks are delivered on the EDT; the fire* methods ports call are safe from any thread.

  • Constructor Details

    • GattServer

      protected GattServer(GattServerListener listener)
      Ports construct subclasses with the listener the application passed to openGattServer.
  • Method Details

    • addService

      public final AsyncResource<Boolean> addService(GattLocalService service)
      Publishes a service definition. Resolves true once the platform registered the service.
    • removeService

      public abstract void removeService(GattLocalService service)
      Removes a previously added service.
    • close

      public abstract void close()
      Shuts the server down and disconnects its centrals.
    • getConnectedCentrals

      public abstract List<BleCentral> getConnectedCentrals()
      The centrals currently connected to this server.
    • notifyValue

      public final AsyncResource<Boolean> notifyValue(GattLocalCharacteristic characteristic, byte[] value)
      Notifies every subscribed central of a new characteristic value. Resolves once the controller accepted the notification(s).
    • notifyCentral

      public final AsyncResource<Boolean> notifyCentral(BleCentral central, GattLocalCharacteristic characteristic, byte[] value, boolean confirm)
      Notifies one central -- or all subscribed centrals when central is null. With confirm an indication is sent and the resource resolves on the central's acknowledgement.
    • doAddService

      protected abstract void doAddService(GattLocalService service, AsyncResource<Boolean> out)
      Registers the service with the platform stack and completes out. Ports must serialize consecutive service additions where the platform requires it (Android).
    • doNotify

      protected abstract void doNotify(BleCentral central, GattLocalCharacteristic characteristic, byte[] value, boolean confirm, AsyncResource<Boolean> out)
      Sends a notification/indication to central (or all subscribed centrals when null) and completes out. Ports must serialize notifications where the platform requires it (Android's onNotificationSent).
    • fireCharacteristicReadRequest

      protected final void fireCharacteristicReadRequest(GattReadRequest request)
      Routes a characteristic read request to the listener on the EDT.
    • fireCharacteristicWriteRequest

      protected final void fireCharacteristicWriteRequest(GattWriteRequest request)
      Routes a characteristic write request to the listener on the EDT.
    • fireDescriptorReadRequest

      protected final void fireDescriptorReadRequest(GattReadRequest request)
      Routes a descriptor read request to the listener on the EDT.
    • fireDescriptorWriteRequest

      protected final void fireDescriptorWriteRequest(GattWriteRequest request)
      Routes a descriptor write request to the listener on the EDT.
    • fireSubscriptionChanged

      protected final void fireSubscriptionChanged(BleCentral central, GattLocalCharacteristic characteristic, boolean subscribed)
      Reports a subscription change to the listener on the EDT.
    • fireCentralConnected

      protected final void fireCentralConnected(BleCentral central)
      Reports a central connection to the listener on the EDT.
    • fireCentralDisconnected

      protected final void fireCentralDisconnected(BleCentral central)
      Reports a central disconnection to the listener on the EDT.