registerAdvertisement method

Future<BlueZAdvertisement> registerAdvertisement({
  1. required BlueZAdvertisementType type,
  2. Map<BlueZManufacturerId, DBusValue> manufacturerData = const {},
  3. List<String> serviceUuids = const [],
  4. Map<BlueZUUID, DBusValue> serviceData = const {},
  5. bool includeTxPower = false,
  6. List<String> solicitUuids = const [],
  7. List<String> includes = const [],
  8. int appearance = 0,
  9. int duration = 2,
  10. int timeout = 0,
  11. String localName = '',
  12. Future<void> onRelease()?,
})

Registers an advertisement object to be sent over the LE advertising channel.

InvalidArguments error indicates that the object has invalid or conflicting properties.

InvalidLength error indicates that the data provided generates a data packet which is too long.

The properties of this object are parsed when it is registered, and any changes are ignored.

If the same object is registered twice it will result in an AlreadyExists error.

If the maximum number of advertisement instances is reached it will result in NotPermitted error.

Implementation

Future<BlueZAdvertisement> registerAdvertisement({
  required BlueZAdvertisementType type,
  Map<BlueZManufacturerId, DBusValue> manufacturerData = const {},
  List<String> serviceUuids = const [],
  Map<BlueZUUID, DBusValue> serviceData = const {},
  bool includeTxPower = false,
  List<String> solicitUuids = const [],
  List<String> includes = const [],
  int appearance = 0,
  int duration = 2,
  int timeout = 0,
  String localName = '',
  Future<void> Function()? onRelease,
}) async {
  final advert = BlueZAdvertisement(
    DBusObjectPath('/org/bluez/advertisement/advert$_nextAdvertId'),
    type: type,
    manufacturerData: manufacturerData,
    serviceUuids: serviceUuids,
    serviceData: serviceData,
    includeTxPower: includeTxPower,
    solicitUuids: solicitUuids,
    includes: includes,
    appearance: appearance,
    duration: duration,
    timeout: timeout,
    localName: localName,
    onRelease: onRelease,
  );

  _nextAdvertId += 1;

  await _client.registerObject(advert);

  await _object.callMethod(_advertInterfaceName, 'RegisterAdvertisement',
      [advert.path, DBusDict.stringVariant({})],
      replySignature: DBusSignature(''));

  return advert;
}