struct Core::Bluetooth::IGattCentralObserver

Overview

#include <coregattcentral.h>

struct IGattCentralObserver
{
    // methods

    virtual void onStateChanged (GattCentralState state) = 0;
    virtual void onDeviceAdded (IGattCentralDevice* device) = 0;
    virtual void onDeviceRemoved (IGattCentralDevice* device) = 0;
    virtual void onDeviceUpdated (IGattCentralDevice* device) = 0;

    virtual void onConnectCompleted (
        IGattCentralDevice* device,
        ErrorCode errorCode
    ) = 0;

    virtual void onDisconnectCompleted (
        IGattCentralDevice* device,
        ErrorCode errorCode
    ) = 0;

    virtual void onConnectionRestored (IGattCentralDevice* device) = 0;
    virtual void onScanningStarted () = 0;
    virtual void onScanningStopped () = 0;
};

Detailed Documentation

Methods

virtual void onStateChanged (GattCentralState state) = 0

This function is called unsolicitedly whenever the global state of the IGattCentral interface changes.

Scan and connect methods may only be called when the state is kPoweredOn.

virtual void onDeviceAdded (IGattCentralDevice* device) = 0

While scanning for devices, an advertisement for a previously undiscovered device has been received.

This GattCentral instance has not yet communicated with the device or attempted to connect to it. This callback creates a new device instance. The lifetime of this instance ends with either onDeviceRemoved() or close()

virtual void onDeviceRemoved (IGattCentralDevice* device) = 0

While scanning for devices, no advertisements for a previously discovered device have been received for at least kAdvertisementTimeout milliseconds and no connection to this device has been attempted or established.

The lifetime of the device ends after this function returns.

virtual void onDeviceUpdated (IGattCentralDevice* device) = 0

While scanning for device, a previously discovered (but not connected) device changed its name or manufacturer data.

virtual void onConnectCompleted (
    IGattCentralDevice* device,
    ErrorCode errorCode
) = 0

When connecting to a device using connectAsync(), a connection attempt has either failed or been successful.

This method is never called unsolicitedly. If a device connected automatically (for example because of the autoReconnect flag), it responds with onConnectionEstablished() instead.

virtual void onDisconnectCompleted (
    IGattCentralDevice* device,
    ErrorCode errorCode
) = 0

When disconnecting from a device using disconnectAsync(), an existing connection has been terminated.

This method is never called unsolicitedly.

virtual void onConnectionRestored (IGattCentralDevice* device) = 0

A connection to a device has been automatically reestablished after a short while without a previous call to connectAsync().

If the connection can’t be restored automatically, it will be removed entirely with onDeviceRemoved() instead.

virtual void onScanningStarted () = 0

The GattCentral has started listening for advertisements.

This callback may be called significantly later than the startScanning() function that triggered it, or not at all in case of an error.

virtual void onScanningStopped () = 0

The GattCentral has stopped listening for advertisements.