• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5part of zircon;
6
7// ignore_for_file: native_function_body_in_non_sdk_code
8// ignore_for_file: public_member_api_docs
9
10@pragma('vm:entry-point')
11class _Namespace { // ignore: unused_element
12  // No public constructor - this only has static methods.
13  _Namespace._();
14
15  // Library private variable set by the embedder used to cache the
16  // namespace (as an fdio_ns_t*).
17  @pragma('vm:entry-point')
18  static int _namespace; // ignore: unused_field
19}
20
21/// An exception representing an error returned as an zx_status_t.
22class ZxStatusException implements Exception {
23  final String message;
24  final int status;
25
26  ZxStatusException(this.status, [this.message]);
27
28  @override
29  String toString() {
30    if (message == null)
31      return 'ZxStatusException: status = $status';
32    else
33      return 'ZxStatusException: status = $status, "$message"';
34  }
35}
36
37class _Result {
38  final int status;
39  const _Result(this.status);
40}
41
42@pragma('vm:entry-point')
43class HandleResult extends _Result {
44  final Handle handle;
45  @pragma('vm:entry-point')
46  const HandleResult(final int status, [this.handle]) : super(status);
47  @override
48  String toString() => 'HandleResult(status=$status, handle=$handle)';
49}
50
51@pragma('vm:entry-point')
52class HandlePairResult extends _Result {
53  final Handle first;
54  final Handle second;
55  @pragma('vm:entry-point')
56  const HandlePairResult(final int status, [this.first, this.second])
57      : super(status);
58  @override
59  String toString() =>
60      'HandlePairResult(status=$status, first=$first, second=$second)';
61}
62
63@pragma('vm:entry-point')
64class ReadResult extends _Result {
65  final ByteData bytes;
66  final int numBytes;
67  final List<Handle> handles;
68  @pragma('vm:entry-point')
69  const ReadResult(final int status, [this.bytes, this.numBytes, this.handles])
70      : super(status);
71  Uint8List bytesAsUint8List() =>
72      bytes.buffer.asUint8List(bytes.offsetInBytes, numBytes);
73  String bytesAsUTF8String() => utf8.decode(bytesAsUint8List());
74  @override
75  String toString() =>
76      'ReadResult(status=$status, bytes=$bytes, numBytes=$numBytes, handles=$handles)';
77}
78
79@pragma('vm:entry-point')
80class WriteResult extends _Result {
81  final int numBytes;
82  @pragma('vm:entry-point')
83  const WriteResult(final int status, [this.numBytes]) : super(status);
84  @override
85  String toString() => 'WriteResult(status=$status, numBytes=$numBytes)';
86}
87
88@pragma('vm:entry-point')
89class GetSizeResult extends _Result {
90  final int size;
91  @pragma('vm:entry-point')
92  const GetSizeResult(final int status, [this.size]) : super(status);
93  @override
94  String toString() => 'GetSizeResult(status=$status, size=$size)';
95}
96
97@pragma('vm:entry-point')
98class FromFileResult extends _Result {
99  final Handle handle;
100  final int numBytes;
101  @pragma('vm:entry-point')
102  const FromFileResult(final int status, [this.handle, this.numBytes])
103      : super(status);
104  @override
105  String toString() =>
106      'FromFileResult(status=$status, handle=$handle, numBytes=$numBytes)';
107}
108
109@pragma('vm:entry-point')
110class MapResult extends _Result {
111  final Uint8List data;
112  @pragma('vm:entry-point')
113  const MapResult(final int status, [this.data]) : super(status);
114  @override
115  String toString() => 'MapResult(status=$status, data=$data)';
116}
117
118@pragma('vm:entry-point')
119class System extends NativeFieldWrapperClass2 {
120  // No public constructor - this only has static methods.
121  System._();
122
123  // Channel operations.
124  static HandlePairResult channelCreate([int options = 0])
125      native 'System_ChannelCreate';
126  static HandleResult channelFromFile(String path)
127      native 'System_ChannelFromFile';
128  static int connectToService(String path, Handle channel)
129    native 'System_ConnectToService';
130  static int channelWrite(Handle channel, ByteData data, List<Handle> handles)
131      native 'System_ChannelWrite';
132  static ReadResult channelQueryAndRead(Handle channel)
133      native 'System_ChannelQueryAndRead';
134
135  // Eventpair operations.
136  static HandlePairResult eventpairCreate([int options = 0])
137      native 'System_EventpairCreate';
138
139  // Socket operations.
140  static HandlePairResult socketCreate([int options = 0])
141      native 'System_SocketCreate';
142  static WriteResult socketWrite(Handle socket, ByteData data, int options)
143      native 'System_SocketWrite';
144  static ReadResult socketRead(Handle socket, int size)
145      native 'System_SocketRead';
146
147  // Vmo operations.
148  static HandleResult vmoCreate(int size, [int options = 0])
149      native 'System_VmoCreate';
150  static FromFileResult vmoFromFile(String path) native 'System_VmoFromFile';
151  static GetSizeResult vmoGetSize(Handle vmo) native 'System_VmoGetSize';
152  static int vmoSetSize(Handle vmo, int size) native 'System_VmoSetSize';
153  static int vmoWrite(Handle vmo, int offset, ByteData bytes)
154      native 'System_VmoWrite';
155  static ReadResult vmoRead(Handle vmo, int offset, int size)
156      native 'System_VmoRead';
157  static MapResult vmoMap(Handle vmo) native 'System_VmoMap';
158
159  // Time operations.
160  static int clockGet(int clockId) native 'System_ClockGet';
161
162  // TODO(edcoyne): Remove this, it is required to safely do an API transition across repos.
163  static int reboot() { return -2; /*ZX_ERR_NOT_SUPPORTED*/ }
164}
165