supportedComputers property

List<Computer> get supportedComputers

Implementation

static List<Computer> get supportedComputers {
  if (_computerDescriptorCache.isNotEmpty) {
    return _computerDescriptorCache.keys.toList();
  }

  final iterator = calloc<ffi.Pointer<dc_iterator_t>>();

  handleResult(
    _bindings.dc_descriptor_iterator(iterator),
    'iterator creation',
  );

  final computers = <Computer>[];

  int result;
  final desc = calloc<ffi.Pointer<dc_descriptor_t>>();
  while ((result = _bindings.dc_iterator_next(iterator.value, desc.cast())) ==
      dc_status_t.DC_STATUS_SUCCESS) {
    final ffi.Pointer<Utf8> vendor =
        _bindings.dc_descriptor_get_vendor(desc.value).cast();
    final ffi.Pointer<Utf8> product =
        _bindings.dc_descriptor_get_product(desc.value).cast();
    final transports = parseTransportsBitmask(
        _bindings.dc_descriptor_get_transports(desc.value));

    final computer = Computer(
      vendor.toDartString(),
      product.toDartString(),
      transports: transports,
    );
    computers.add(computer);
    _computerDescriptorCache.addEntries([MapEntry(computer, desc.value)]);
  }
  handleResult(result, 'iterator next');

  handleResult(
    _bindings.dc_iterator_free(iterator.value),
    'iterator freeing',
  );

  return computers;
}