blob: 37d188352e0fac1e5201ce011fbee5006156db6a [file] [log] [blame]
// WARNING: This file is machine generated by fidlgen.
library fidl_test_name_async;
import 'dart:async' as $async;
import 'dart:core' hide Set;
import 'dart:developer';
import 'dart:typed_data';
import 'package:fidl/fidl.dart' as $fidl;
import 'package:meta/meta.dart';
import 'package:zircon/zircon.dart' as $zx;
// ignore_for_file: always_specify_types
// ignore_for_file: avoid_positional_boolean_parameters
// ignore_for_file: avoid_returning_null
// ignore_for_file: cascade_invocations
// ignore_for_file: constant_identifier_names
// ignore_for_file: one_member_abstracts
// ignore_for_file: prefer_constructors_over_static_methods
// ignore_for_file: prefer_single_quotes
// ignore_for_file: public_member_api_docs
// ignore_for_file: unused_import
// ignore_for_file: unused_local_variable
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: library_prefixes
// ignore_for_file: prefer_typing_uninitialized_variables
// ignore_for_file: avoid_js_rounded_ints
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: prefer_generic_function_type_aliases
// ignore_for_file: prefer_equal_for_default_values
// ignore_for_file: avoid_catches_without_on_clauses
// ignore_for_file: unused_shown_name
// ignore_for_file: unnecessary_lambdas
// ignore_for_file: comment_references
// ignore_for_file: avoid_unused_constructor_parameters
/// const comment #1
///
/// const comment #3
const int c = 0x4;
/// enum comment #1.
///
/// enum comment #2.
class MyEnum extends $fidl.Enum {
factory MyEnum(int _v) {
switch (_v) {
case 0x1:
return foo;
case 0x2:
return bar;
default:
return null;
}
}
/// enum Member comment 1.
static const MyEnum foo = MyEnum._(0x1);
static const MyEnum bar = MyEnum._(0x2);
const MyEnum._(this.$value);
@override
final int $value;
static const Map<String, MyEnum> $valuesMap = {
r'foo': foo,
r'bar': bar,
};
static const List<MyEnum> $values = [
foo,
bar,
];
// TODO: remove, see: FIDL-587
static const List<MyEnum> values = MyEnum.$values;
static MyEnum $valueOf(String name) => $valuesMap[name];
@override
String toString() {
switch ($value) {
case 0x1:
return r'MyEnum.foo';
case 0x2:
return r'MyEnum.bar';
default:
return null;
}
}
static MyEnum _ctor(int v) => MyEnum(v);
}
const $fidl.EnumType<MyEnum> kMyEnum_Type =
$fidl.EnumType<MyEnum>(type: $fidl.Uint32Type(), ctor: MyEnum._ctor);
/// bits comment #1
///
/// bits comment #2
class MyBits extends $fidl.Bits {
/// bits member comment #1
///
/// bits member comment #3
static const MyBits myFirstBit = MyBits._(0x1);
static const MyBits myOtherBit = MyBits._(0x2);
static const MyBits $none = MyBits._(0);
const MyBits._(this.$value);
MyBits operator |(MyBits other) {
return MyBits._($value | other.$value);
}
MyBits operator &(MyBits other) {
return MyBits._($value & other.$value);
}
@override
final int $value;
@override
String toString() {
if ($value == null) {
return null;
}
List<String> parts = [];
if ($value & 0x1 != 0) {
parts.add(r'MyBits.myFirstBit');
}
if ($value & 0x2 != 0) {
parts.add(r'MyBits.myOtherBit');
}
if (parts.isEmpty) {
return r'MyBits.$none';
} else {
return parts.join(" | ");
}
}
static MyBits _ctor(int v) => MyBits._(v);
}
const $fidl.BitsType<MyBits> kMyBits_Type =
$fidl.BitsType<MyBits>(type: $fidl.Uint32Type(), ctor: MyBits._ctor);
enum UnionTag {
field, // 0x1
}
const Map<int, UnionTag> _UnionTag_map = {
1: UnionTag.field,
};
/// union comment #1
///
/// union comment #3
class Union extends $fidl.XUnion {
const Union.withField(int value)
: _ordinal = 1,
_data = value;
Union._(int ordinal, Object data)
: _ordinal = ordinal,
_data = data;
final int _ordinal;
final _data;
UnionTag get $tag => _UnionTag_map[_ordinal];
int get field {
if (_ordinal != 1) {
return null;
}
return _data;
}
@override
String toString() {
switch (_ordinal) {
case 1:
return 'Union.field($field)';
default:
return null;
}
}
@override
int get $ordinal => _ordinal;
@override
Object get $data => _data;
static Union _ctor(int ordinal, Object data) {
return Union._(ordinal, data);
}
}
// See FIDL-308:
// ignore: recursive_compile_time_constant
const $fidl.XUnionType<Union> kUnion_Type = $fidl.XUnionType<Union>(
members: <int, $fidl.FidlType>{
1: $fidl.Int32Type(),
},
readToWriteOrdinals: <int, int>{
1: 1,
},
ctor: Union._ctor,
nullable: false,
flexible: false,
);
// See FIDL-308:
// ignore: recursive_compile_time_constant
const $fidl.XUnionType<Union> kUnion_OptType = $fidl.XUnionType<Union>(
members: <int, $fidl.FidlType>{
1: $fidl.Int32Type(),
},
readToWriteOrdinals: <int, int>{
1: 1,
},
ctor: Union._ctor,
nullable: true,
flexible: false,
);
/// struct comment #1
///
/// struct comment #3
class Struct extends $fidl.Struct {
const Struct({
@required this.field,
});
Struct.clone(
Struct $orig, {
int field,
}) : this(
field: field ?? $orig.field,
);
Struct._(List<Object> argv) : field = argv[0];
/// struct member comment #1
///
/// struct member comment #3
final int field;
@override
List<Object> get $fields {
return <Object>[
field,
];
}
@override
String toString() {
// ignore: prefer_interpolation_to_compose_strings
return r'Struct' r'(field: ' + field.toString() + r')';
}
static Struct _ctor(List<Object> argv) => Struct._(argv);
}
// See FIDL-308:
// ignore: recursive_compile_time_constant
const $fidl.StructType<Struct> kStruct_Type = $fidl.StructType<Struct>(
inlineSize: 4,
members: <$fidl.MemberType>[
$fidl.MemberType<int>(type: $fidl.Int32Type(), offset: 0),
],
ctor: Struct._ctor,
);
/// table comment #1
///
/// table comment #3
class Table extends $fidl.Table {
const Table({
this.field,
});
Table._(Map<int, dynamic> argv) : field = argv[1];
/// table field comment #1
///
/// table field comment #3
final int field;
@override
Map<int, dynamic> get $fields {
return {
1: field,
};
}
static Table _ctor(Map<int, dynamic> argv) => Table._(argv);
}
// See FIDL-308:
// ignore: recursive_compile_time_constant
const $fidl.TableType<Table> kTable_Type = $fidl.TableType<Table>(
inlineSize: 16,
members: <int, $fidl.FidlType>{
1: $fidl.Int32Type(),
},
ctor: Table._ctor,
);
// ignore: unused_element, avoid_private_typedef_functions
typedef _VoidCallback = void Function();
// method: ()
const int _kInterface_Method_Ordinal = 0x3f43684c00000000;
const int _kInterface_Method_GenOrdinal = 0x60e700e002995ef8;
const $fidl.MethodType _kInterface_Method_Type = $fidl.MethodType(
request: null,
response: null,
name: r"Interface.Method",
requestInlineSize: 16,
responseInlineSize: 0,
);
// onEvent: -> ()
const int _kInterface_OnEvent_Ordinal = 0x136d200d00000000;
const int _kInterface_OnEvent_GenOrdinal = 0x914c226136244ed;
const $fidl.MethodType _kInterface_OnEvent_Type = $fidl.MethodType(
request: null,
response: null,
name: r"Interface.OnEvent",
requestInlineSize: 0,
responseInlineSize: 16,
);
/// interface comment #1
///
/// interface comment #3
abstract class Interface extends $fidl.Service {
static const String $serviceName = null;
@override
$fidl.ServiceData get $serviceData => InterfaceData();
/// method comment #1
///
/// method comment #3
$async.Future<void> method();
/// event comment #1
///
/// event comment #3
$async.Stream<void> get onEvent;
}
class InterfaceData implements $fidl.ServiceData<Interface> {
const InterfaceData();
@override
String getName() {
return Interface.$serviceName;
}
@override
$fidl.AsyncBinding getBinding() {
return InterfaceBinding();
}
}
/// interface comment #1
///
/// interface comment #3
class InterfaceProxy extends $fidl.AsyncProxy<Interface> implements Interface {
InterfaceProxy()
: super($fidl.AsyncProxyController<Interface>(
$serviceName: null, $interfaceName: r'Interface')) {
ctrl.onResponse = _handleResponse;
ctrl.whenClosed.then((_) {
_onEventEventStreamController.close();
}, onError: (_) {});
}
@override
$fidl.ServiceData get $serviceData => InterfaceData();
void _handleEvent($fidl.Message $message) {
final $fidl.Decoder $decoder = $fidl.Decoder($message);
switch ($message.ordinal) {
case _kInterface_OnEvent_Ordinal:
case _kInterface_OnEvent_GenOrdinal:
final String _name = _kInterface_OnEvent_Type.name;
try {
Timeline.startSync(_name);
final List<$fidl.MemberType> $types =
_kInterface_OnEvent_Type.response;
$decoder.claimMemory(
_kInterface_OnEvent_Type.decodeResponseInlineSize($decoder));
_onEventEventStreamController.add(null);
// ignore: avoid_catches_without_on_clauses
} catch (_e) {
ctrl.proxyError(
$fidl.FidlError('Exception handling event $_name: $_e'));
ctrl.close();
rethrow;
} finally {
Timeline.finishSync();
}
break;
default:
ctrl.proxyError(
$fidl.FidlError('Unexpected message ordinal: ${$message.ordinal}'));
ctrl.close();
break;
}
}
void _handleResponse($fidl.Message $message) {
final int $txid = $message.txid;
if ($txid == 0) {
_handleEvent($message);
return;
}
final $async.Completer $completer = ctrl.getCompleter($txid);
if ($completer == null) {
$message.closeHandles();
return;
}
final $fidl.Decoder $decoder = $fidl.Decoder($message);
switch ($message.ordinal) {
default:
ctrl.proxyError(
$fidl.FidlError('Unexpected message ordinal: ${$message.ordinal}'));
ctrl.close();
break;
}
}
/// method comment #1
///
/// method comment #3
@override
$async.Future<void> method() async {
if (!ctrl.isBound) {
return $async.Future.error(
$fidl.FidlStateException('Proxy<${ctrl.$interfaceName}> is closed.'),
StackTrace.current);
}
final $fidl.Encoder $encoder = $fidl.Encoder();
$encoder.encodeMessageHeader(_kInterface_Method_GenOrdinal, 0);
return $async.Future.sync(() {
ctrl.sendMessage($encoder.message);
});
}
final _onEventEventStreamController =
$async.StreamController<void>.broadcast();
/// event comment #1
///
/// event comment #3
@override
$async.Stream<void> get onEvent => _onEventEventStreamController.stream;
}
class InterfaceBinding extends $fidl.AsyncBinding<Interface> {
InterfaceBinding() : super(r"Interface") {
final List<$async.StreamSubscription<dynamic>> $subscriptions = [];
void $unsubscribe() {
for (final $sub in $subscriptions) {
$sub.cancel();
}
$subscriptions.clear();
}
whenBound.then((_) {
if (impl.onEvent != null) {
$subscriptions.add(impl.onEvent.listen(($response) {
final $fidl.Encoder $encoder = $fidl.Encoder();
$encoder.encodeMessageHeader(_kInterface_OnEvent_GenOrdinal, 0);
$encoder.alloc(
_kInterface_OnEvent_Type.encodingResponseInlineSize($encoder) -
$fidl.kMessageHeaderSize);
final List<$fidl.MemberType> $types =
_kInterface_OnEvent_Type.response;
sendMessage($encoder.message);
}));
}
});
whenClosed.then((_) => $unsubscribe());
}
@override
void handleMessage($fidl.Message $message, $fidl.MessageSink $respond) {
final $fidl.Decoder $decoder = $fidl.Decoder($message);
switch ($message.ordinal) {
case _kInterface_Method_Ordinal:
case _kInterface_Method_GenOrdinal:
final String _name = _kInterface_Method_Type.name;
try {
Timeline.startSync(_name);
final List<$fidl.MemberType> $types = _kInterface_Method_Type.request;
$decoder.claimMemory(
_kInterface_Method_Type.decodeRequestInlineSize($decoder));
final $async.Future<void> $future = impl.method();
// ignore: avoid_catches_without_on_clauses
} catch (_e) {
close();
print('Exception handling method call $_name: $_e');
rethrow;
} finally {
Timeline.finishSync();
}
break;
default:
throw $fidl.FidlError(r'Unexpected message name for InterfaceBinding');
}
}
}