public class EventSerializer extends Object implements ConnectionListener, RemoteServiceListener, LocalServiceListener
Constructor and Description |
---|
EventSerializer(BluetoothController controller) |
Modifier and Type | Method and Description |
---|---|
void |
onAdvertisementCompleted()
Called when an ongoing advertisement is completed.
|
void |
onConnected(BluetoothConnection connection)
Called when a connection attempt is successful or when a remote device connects to the adapter.
|
void |
onConnectFailed(BluetoothAddress address)
Called when a connection attempt fails.
|
void |
onDisconnected(BluetoothConnection connection)
Called when the connection with a device is closed.
|
void |
onDiscoveryCompleted(BluetoothConnection connection)
Called when a service discovery is completed.
|
void |
onDiscoveryResult(BluetoothConnection connection,
BluetoothService service)
Called when a service provided by a device has been discovered.
|
void |
onExecuteWriteRequest(BluetoothConnection connection,
BluetoothAttribute attribute,
boolean execute)
Called when an execute write request is received.
|
void |
onNotificationReceived(BluetoothConnection connection,
BluetoothCharacteristic characteristic,
byte[] value)
Called when a characteristic notification or indication is received.
|
void |
onNotificationSent(BluetoothConnection connection,
BluetoothCharacteristic characteristic,
boolean success)
Called when a characteristic notification or indication is sent.
|
void |
onPairCompleted(BluetoothConnection connection,
boolean success)
Called when the pairing procedure with a device is completed.
|
void |
onPairRequest(BluetoothConnection connection)
Called when a pairing request from a device is received.
|
void |
onPasskeyGenerated(BluetoothConnection connection,
int passkey)
Called when a passkey is generated to be displayed to the user.
|
void |
onPasskeyRequest(BluetoothConnection connection)
Called when a passkey request from a device is received.
|
void |
onPrepareWriteRequest(BluetoothConnection connection,
BluetoothAttribute attribute,
byte[] value,
int offset)
Called when a prepare write request is received.
|
void |
onReadBlobRequest(BluetoothConnection connection,
BluetoothAttribute attribute,
int offset)
Called when a read blob request is received.
|
void |
onReadCompleted(BluetoothConnection connection,
BluetoothAttribute attribute,
byte status,
byte[] value)
Called when a response to a read request is received.
|
void |
onReadRequest(BluetoothConnection connection,
BluetoothAttribute attribute)
Called when a read request is received.
|
void |
onScanCompleted()
Called when an ongoing scan is completed.
|
void |
onScanResult(BluetoothAddress address,
byte[] advertisementData,
int rssi)
Called when a advertisement or a scan response is received.
|
void |
onWriteCompleted(BluetoothConnection connection,
BluetoothAttribute attribute,
byte status)
Called when a response to a write request is received.
|
void |
onWriteRequest(BluetoothConnection connection,
BluetoothAttribute attribute,
byte[] value)
Called when a write request is received.
|
public EventSerializer(BluetoothController controller)
public void onAdvertisementCompleted()
ConnectionListener
onAdvertisementCompleted
in interface ConnectionListener
BluetoothAdapter.startAdvertising(byte[])
,
BluetoothAdapter.stopAdvertising()
public void onConnected(BluetoothConnection connection)
ConnectionListener
onConnected
in interface ConnectionListener
connection
- the connection which was established.BluetoothAdapter.connect(BluetoothAddress)
,
BluetoothAdapter.startAdvertising(byte[])
public void onConnectFailed(BluetoothAddress address)
ConnectionListener
onConnectFailed
in interface ConnectionListener
address
- the address of the device to which the connection has failed.BluetoothAdapter.connect(BluetoothAddress)
public void onDisconnected(BluetoothConnection connection)
ConnectionListener
onDisconnected
in interface ConnectionListener
connection
- the connection which was closed.BluetoothConnection.disconnect()
public void onDiscoveryCompleted(BluetoothConnection connection)
ConnectionListener
onDiscoveryCompleted
in interface ConnectionListener
connection
- the connection with the device with which the discovery was initiated.BluetoothConnection.discoverServices()
,
BluetoothConnection.discoverService(ej.bluetooth.BluetoothUuid)
public void onDiscoveryResult(BluetoothConnection connection, BluetoothService service)
ConnectionListener
onDiscoveryResult
in interface ConnectionListener
connection
- the connection with the device which provides the service.service
- the service which has been discovered.BluetoothConnection.discoverServices()
,
BluetoothConnection.discoverService(ej.bluetooth.BluetoothUuid)
public void onExecuteWriteRequest(BluetoothConnection connection, BluetoothAttribute attribute, boolean execute)
LocalServiceListener
onExecuteWriteRequest
in interface LocalServiceListener
connection
- the connection with the device which has sent the request.attribute
- the attribute to write.execute
- true if the pending prepared writes should be executed, false if they should be cancelled.public void onNotificationReceived(BluetoothConnection connection, BluetoothCharacteristic characteristic, byte[] value)
RemoteServiceListener
onNotificationReceived
in interface RemoteServiceListener
connection
- the connection with the device which has sent the notification.characteristic
- the characteristic which has changed.value
- the value of the characteristic.public void onNotificationSent(BluetoothConnection connection, BluetoothCharacteristic characteristic, boolean success)
LocalServiceListener
If a notification was sent, this method is called as soon as the notification is sent to the device. If an indication was sent, this method is called when the device acknowledges the indication.
onNotificationSent
in interface LocalServiceListener
connection
- the connection with the device to which the notification was sent.characteristic
- the characteristic which has changed.success
- true if the notification was sent successfully, false otherwise.BluetoothConnection.sendNotification(BluetoothCharacteristic, byte[], boolean)
public void onPairCompleted(BluetoothConnection connection, boolean success)
ConnectionListener
onPairCompleted
in interface ConnectionListener
connection
- the connection with the device with which the pairing procedure was completed.success
- true if the pairing procedure was successful, false otherwise.BluetoothConnection.sendPairRequest()
,
BluetoothConnection.sendPairResponse(boolean)
public void onPairRequest(BluetoothConnection connection)
ConnectionListener
onPairRequest
in interface ConnectionListener
connection
- the connection with the device from which the pairing request was received.BluetoothConnection.sendPairResponse(boolean)
public void onPasskeyGenerated(BluetoothConnection connection, int passkey)
ConnectionListener
onPasskeyGenerated
in interface ConnectionListener
connection
- the connection with the device to which the passkey request was sent.passkey
- the passkey which was generated.BluetoothConnection.sendPasskeyResponse(boolean, int)
public void onPasskeyRequest(BluetoothConnection connection)
ConnectionListener
onPasskeyRequest
in interface ConnectionListener
connection
- the connection with the device from which the passkey request was received.BluetoothConnection.sendPasskeyResponse(boolean, int)
public void onPrepareWriteRequest(BluetoothConnection connection, BluetoothAttribute attribute, byte[] value, int offset)
LocalServiceListener
onPrepareWriteRequest
in interface LocalServiceListener
connection
- the connection with the device which has sent the request.attribute
- the attribute to write.value
- the value to write.offset
- the offset of the first octet to write.public void onReadBlobRequest(BluetoothConnection connection, BluetoothAttribute attribute, int offset)
LocalServiceListener
onReadBlobRequest
in interface LocalServiceListener
connection
- the connection with the device which has sent the request.attribute
- the attribute to read.offset
- the offset of the first octet to read.public void onReadCompleted(BluetoothConnection connection, BluetoothAttribute attribute, byte status, byte[] value)
RemoteServiceListener
onReadCompleted
in interface RemoteServiceListener
connection
- the connection with the device which has sent the response.attribute
- the attribute which was read.status
- the response status (see BluetoothStatus
).value
- the value of the attribute.BluetoothConnection.sendReadRequest(BluetoothAttribute)
public void onReadRequest(BluetoothConnection connection, BluetoothAttribute attribute)
LocalServiceListener
onReadRequest
in interface LocalServiceListener
connection
- the connection with the device which has sent the request.attribute
- the attribute to read.public void onScanCompleted()
ConnectionListener
onScanCompleted
in interface ConnectionListener
BluetoothAdapter.startScanning(ej.bluetooth.BluetoothScanFilter)
,
BluetoothAdapter.stopScanning()
public void onScanResult(BluetoothAddress address, byte[] advertisementData, int rssi)
ConnectionListener
onScanResult
in interface ConnectionListener
address
- the address of the device which has sent the advertisement.advertisementData
- the advertisement data.rssi
- the RSSI measurement.BluetoothAdapter.startScanning(ej.bluetooth.BluetoothScanFilter)
,
BluetoothAdapter.stopScanning()
public void onWriteCompleted(BluetoothConnection connection, BluetoothAttribute attribute, byte status)
RemoteServiceListener
onWriteCompleted
in interface RemoteServiceListener
connection
- the connection with the device which has sent the response.attribute
- the attribute which was written.status
- the response status (see BluetoothStatus
).BluetoothConnection.sendWriteRequest(BluetoothAttribute, byte[])
public void onWriteRequest(BluetoothConnection connection, BluetoothAttribute attribute, byte[] value)
LocalServiceListener
onWriteRequest
in interface LocalServiceListener
connection
- the connection with the device which has sent the request.attribute
- the attribute to write.value
- the value to write.