Class GattServer
java.lang.Object
com.codename1.bluetooth.le.server.GattServer
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 Summary
ConstructorsModifierConstructorDescriptionprotectedGattServer(GattServerListener listener) Ports construct subclasses with the listener the application passed toopenGattServer. -
Method Summary
Modifier and TypeMethodDescriptionfinal AsyncResource<Boolean> addService(GattLocalService service) Publishes a service definition.abstract voidclose()Shuts the server down and disconnects its centrals.protected abstract voiddoAddService(GattLocalService service, AsyncResource<Boolean> out) Registers the service with the platform stack and completesout.protected abstract voiddoNotify(BleCentral central, GattLocalCharacteristic characteristic, byte[] value, boolean confirm, AsyncResource<Boolean> out) Sends a notification/indication tocentral(or all subscribed centrals whennull) and completesout.protected final voidfireCentralConnected(BleCentral central) Reports a central connection to the listener on the EDT.protected final voidfireCentralDisconnected(BleCentral central) Reports a central disconnection to the listener on the EDT.protected final voidRoutes a characteristic read request to the listener on the EDT.protected final voidRoutes a characteristic write request to the listener on the EDT.protected final voidfireDescriptorReadRequest(GattReadRequest request) Routes a descriptor read request to the listener on the EDT.protected final voidRoutes a descriptor write request to the listener on the EDT.protected final voidfireSubscriptionChanged(BleCentral central, GattLocalCharacteristic characteristic, boolean subscribed) Reports a subscription change to the listener on the EDT.abstract List<BleCentral> The centrals currently connected to this server.final AsyncResource<Boolean> notifyCentral(BleCentral central, GattLocalCharacteristic characteristic, byte[] value, boolean confirm) Notifies one central -- or all subscribed centrals whencentralisnull.final AsyncResource<Boolean> notifyValue(GattLocalCharacteristic characteristic, byte[] value) Notifies every subscribed central of a new characteristic value.abstract voidremoveService(GattLocalService service) Removes a previously added service.
-
Constructor Details
-
GattServer
Ports construct subclasses with the listener the application passed toopenGattServer.
-
-
Method Details
-
addService
Publishes a service definition. Resolvestrueonce the platform registered the service. -
removeService
Removes a previously added service. -
close
public abstract void close()Shuts the server down and disconnects its centrals. -
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 whencentralisnull. Withconfirman indication is sent and the resource resolves on the central's acknowledgement. -
doAddService
Registers the service with the platform stack and completesout. 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 tocentral(or all subscribed centrals whennull) and completesout. Ports must serialize notifications where the platform requires it (Android'sonNotificationSent). -
fireCharacteristicReadRequest
Routes a characteristic read request to the listener on the EDT. -
fireCharacteristicWriteRequest
Routes a characteristic write request to the listener on the EDT. -
fireDescriptorReadRequest
Routes a descriptor read request to the listener on the EDT. -
fireDescriptorWriteRequest
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
Reports a central connection to the listener on the EDT. -
fireCentralDisconnected
Reports a central disconnection to the listener on the EDT.
-