OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium 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 |
| 5 library files_mojom; |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:mojo/bindings.dart' as bindings; |
| 10 import 'package:mojo/core.dart' as core; |
| 11 import 'package:mojo_services/mojo/files/directory.mojom.dart' as directory_mojo
m; |
| 12 import 'package:mojo_services/mojo/files/types.mojom.dart' as types_mojom; |
| 13 |
| 14 |
| 15 |
| 16 class FilesOpenFileSystemParams extends bindings.Struct { |
| 17 static const List<bindings.StructDataHeader> kVersions = const [ |
| 18 const bindings.StructDataHeader(24, 0) |
| 19 ]; |
| 20 String fileSystem = null; |
| 21 Object directory = null; |
| 22 |
| 23 FilesOpenFileSystemParams() : super(kVersions.last.size); |
| 24 |
| 25 static FilesOpenFileSystemParams deserialize(bindings.Message message) { |
| 26 var decoder = new bindings.Decoder(message); |
| 27 var result = decode(decoder); |
| 28 if (decoder.excessHandles != null) { |
| 29 decoder.excessHandles.forEach((h) => h.close()); |
| 30 } |
| 31 return result; |
| 32 } |
| 33 |
| 34 static FilesOpenFileSystemParams decode(bindings.Decoder decoder0) { |
| 35 if (decoder0 == null) { |
| 36 return null; |
| 37 } |
| 38 FilesOpenFileSystemParams result = new FilesOpenFileSystemParams(); |
| 39 |
| 40 var mainDataHeader = decoder0.decodeStructDataHeader(); |
| 41 if (mainDataHeader.version <= kVersions.last.version) { |
| 42 // Scan in reverse order to optimize for more recent versions. |
| 43 for (int i = kVersions.length - 1; i >= 0; --i) { |
| 44 if (mainDataHeader.version >= kVersions[i].version) { |
| 45 if (mainDataHeader.size == kVersions[i].size) { |
| 46 // Found a match. |
| 47 break; |
| 48 } |
| 49 throw new bindings.MojoCodecError( |
| 50 'Header size doesn\'t correspond to known version size.'); |
| 51 } |
| 52 } |
| 53 } else if (mainDataHeader.size < kVersions.last.size) { |
| 54 throw new bindings.MojoCodecError( |
| 55 'Message newer than the last known version cannot be shorter than ' |
| 56 'required by the last known version.'); |
| 57 } |
| 58 if (mainDataHeader.version >= 0) { |
| 59 |
| 60 result.fileSystem = decoder0.decodeString(8, true); |
| 61 } |
| 62 if (mainDataHeader.version >= 0) { |
| 63 |
| 64 result.directory = decoder0.decodeInterfaceRequest(16, false, directory_mo
jom.DirectoryStub.newFromEndpoint); |
| 65 } |
| 66 return result; |
| 67 } |
| 68 |
| 69 void encode(bindings.Encoder encoder) { |
| 70 var encoder0 = encoder.getStructEncoderAtOffset(kVersions.last); |
| 71 |
| 72 encoder0.encodeString(fileSystem, 8, true); |
| 73 |
| 74 encoder0.encodeInterfaceRequest(directory, 16, false); |
| 75 } |
| 76 |
| 77 String toString() { |
| 78 return "FilesOpenFileSystemParams(" |
| 79 "fileSystem: $fileSystem" ", " |
| 80 "directory: $directory" ")"; |
| 81 } |
| 82 |
| 83 Map toJson() { |
| 84 throw new bindings.MojoCodecError( |
| 85 'Object containing handles cannot be encoded to JSON.'); |
| 86 } |
| 87 } |
| 88 |
| 89 |
| 90 class FilesOpenFileSystemResponseParams extends bindings.Struct { |
| 91 static const List<bindings.StructDataHeader> kVersions = const [ |
| 92 const bindings.StructDataHeader(16, 0) |
| 93 ]; |
| 94 types_mojom.Error error = null; |
| 95 |
| 96 FilesOpenFileSystemResponseParams() : super(kVersions.last.size); |
| 97 |
| 98 static FilesOpenFileSystemResponseParams deserialize(bindings.Message message)
{ |
| 99 var decoder = new bindings.Decoder(message); |
| 100 var result = decode(decoder); |
| 101 if (decoder.excessHandles != null) { |
| 102 decoder.excessHandles.forEach((h) => h.close()); |
| 103 } |
| 104 return result; |
| 105 } |
| 106 |
| 107 static FilesOpenFileSystemResponseParams decode(bindings.Decoder decoder0) { |
| 108 if (decoder0 == null) { |
| 109 return null; |
| 110 } |
| 111 FilesOpenFileSystemResponseParams result = new FilesOpenFileSystemResponsePa
rams(); |
| 112 |
| 113 var mainDataHeader = decoder0.decodeStructDataHeader(); |
| 114 if (mainDataHeader.version <= kVersions.last.version) { |
| 115 // Scan in reverse order to optimize for more recent versions. |
| 116 for (int i = kVersions.length - 1; i >= 0; --i) { |
| 117 if (mainDataHeader.version >= kVersions[i].version) { |
| 118 if (mainDataHeader.size == kVersions[i].size) { |
| 119 // Found a match. |
| 120 break; |
| 121 } |
| 122 throw new bindings.MojoCodecError( |
| 123 'Header size doesn\'t correspond to known version size.'); |
| 124 } |
| 125 } |
| 126 } else if (mainDataHeader.size < kVersions.last.size) { |
| 127 throw new bindings.MojoCodecError( |
| 128 'Message newer than the last known version cannot be shorter than ' |
| 129 'required by the last known version.'); |
| 130 } |
| 131 if (mainDataHeader.version >= 0) { |
| 132 |
| 133 result.error = types_mojom.Error.decode(decoder0, 8); |
| 134 if (result.error == null) { |
| 135 throw new bindings.MojoCodecError( |
| 136 'Trying to decode null union for non-nullable types_mojom.Error.'); |
| 137 } |
| 138 } |
| 139 return result; |
| 140 } |
| 141 |
| 142 void encode(bindings.Encoder encoder) { |
| 143 var encoder0 = encoder.getStructEncoderAtOffset(kVersions.last); |
| 144 |
| 145 encoder0.encodeEnum(error, 8); |
| 146 } |
| 147 |
| 148 String toString() { |
| 149 return "FilesOpenFileSystemResponseParams(" |
| 150 "error: $error" ")"; |
| 151 } |
| 152 |
| 153 Map toJson() { |
| 154 Map map = new Map(); |
| 155 map["error"] = error; |
| 156 return map; |
| 157 } |
| 158 } |
| 159 |
| 160 const int kFiles_openFileSystem_name = 0; |
| 161 |
| 162 const String FilesName = |
| 163 'mojo::files::Files'; |
| 164 |
| 165 abstract class Files { |
| 166 dynamic openFileSystem(String fileSystem,Object directory,[Function responseFa
ctory = null]); |
| 167 |
| 168 } |
| 169 |
| 170 |
| 171 class FilesProxyImpl extends bindings.Proxy { |
| 172 FilesProxyImpl.fromEndpoint( |
| 173 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); |
| 174 |
| 175 FilesProxyImpl.fromHandle(core.MojoHandle handle) : |
| 176 super.fromHandle(handle); |
| 177 |
| 178 FilesProxyImpl.unbound() : super.unbound(); |
| 179 |
| 180 static FilesProxyImpl newFromEndpoint( |
| 181 core.MojoMessagePipeEndpoint endpoint) { |
| 182 assert(endpoint.setDescription("For FilesProxyImpl")); |
| 183 return new FilesProxyImpl.fromEndpoint(endpoint); |
| 184 } |
| 185 |
| 186 String get name => FilesName; |
| 187 |
| 188 void handleResponse(bindings.ServiceMessage message) { |
| 189 switch (message.header.type) { |
| 190 case kFiles_openFileSystem_name: |
| 191 var r = FilesOpenFileSystemResponseParams.deserialize( |
| 192 message.payload); |
| 193 if (!message.header.hasRequestId) { |
| 194 proxyError("Expected a message with a valid request Id."); |
| 195 return; |
| 196 } |
| 197 Completer c = completerMap[message.header.requestId]; |
| 198 if (c == null) { |
| 199 proxyError( |
| 200 "Message had unknown request Id: ${message.header.requestId}"); |
| 201 return; |
| 202 } |
| 203 completerMap.remove(message.header.requestId); |
| 204 if (c.isCompleted) { |
| 205 proxyError("Response completer already completed"); |
| 206 return; |
| 207 } |
| 208 c.complete(r); |
| 209 break; |
| 210 default: |
| 211 proxyError("Unexpected message type: ${message.header.type}"); |
| 212 close(immediate: true); |
| 213 break; |
| 214 } |
| 215 } |
| 216 |
| 217 String toString() { |
| 218 var superString = super.toString(); |
| 219 return "FilesProxyImpl($superString)"; |
| 220 } |
| 221 } |
| 222 |
| 223 |
| 224 class _FilesProxyCalls implements Files { |
| 225 FilesProxyImpl _proxyImpl; |
| 226 |
| 227 _FilesProxyCalls(this._proxyImpl); |
| 228 dynamic openFileSystem(String fileSystem,Object directory,[Function response
Factory = null]) { |
| 229 var params = new FilesOpenFileSystemParams(); |
| 230 params.fileSystem = fileSystem; |
| 231 params.directory = directory; |
| 232 return _proxyImpl.sendMessageWithRequestId( |
| 233 params, |
| 234 kFiles_openFileSystem_name, |
| 235 -1, |
| 236 bindings.MessageHeader.kMessageExpectsResponse); |
| 237 } |
| 238 } |
| 239 |
| 240 |
| 241 class FilesProxy implements bindings.ProxyBase { |
| 242 final bindings.Proxy impl; |
| 243 Files ptr; |
| 244 final String name = FilesName; |
| 245 |
| 246 FilesProxy(FilesProxyImpl proxyImpl) : |
| 247 impl = proxyImpl, |
| 248 ptr = new _FilesProxyCalls(proxyImpl); |
| 249 |
| 250 FilesProxy.fromEndpoint( |
| 251 core.MojoMessagePipeEndpoint endpoint) : |
| 252 impl = new FilesProxyImpl.fromEndpoint(endpoint) { |
| 253 ptr = new _FilesProxyCalls(impl); |
| 254 } |
| 255 |
| 256 FilesProxy.fromHandle(core.MojoHandle handle) : |
| 257 impl = new FilesProxyImpl.fromHandle(handle) { |
| 258 ptr = new _FilesProxyCalls(impl); |
| 259 } |
| 260 |
| 261 FilesProxy.unbound() : |
| 262 impl = new FilesProxyImpl.unbound() { |
| 263 ptr = new _FilesProxyCalls(impl); |
| 264 } |
| 265 |
| 266 factory FilesProxy.connectToService( |
| 267 bindings.ServiceConnector s, String url) { |
| 268 FilesProxy p = new FilesProxy.unbound(); |
| 269 s.connectToService(url, p); |
| 270 return p; |
| 271 } |
| 272 |
| 273 static FilesProxy newFromEndpoint( |
| 274 core.MojoMessagePipeEndpoint endpoint) { |
| 275 assert(endpoint.setDescription("For FilesProxy")); |
| 276 return new FilesProxy.fromEndpoint(endpoint); |
| 277 } |
| 278 |
| 279 Future close({bool immediate: false}) => impl.close(immediate: immediate); |
| 280 |
| 281 Future responseOrError(Future f) => impl.responseOrError(f); |
| 282 |
| 283 Future get errorFuture => impl.errorFuture; |
| 284 |
| 285 int get version => impl.version; |
| 286 |
| 287 Future<int> queryVersion() => impl.queryVersion(); |
| 288 |
| 289 void requireVersion(int requiredVersion) { |
| 290 impl.requireVersion(requiredVersion); |
| 291 } |
| 292 |
| 293 String toString() { |
| 294 return "FilesProxy($impl)"; |
| 295 } |
| 296 } |
| 297 |
| 298 |
| 299 class FilesStub extends bindings.Stub { |
| 300 Files _impl = null; |
| 301 |
| 302 FilesStub.fromEndpoint( |
| 303 core.MojoMessagePipeEndpoint endpoint, [this._impl]) |
| 304 : super.fromEndpoint(endpoint); |
| 305 |
| 306 FilesStub.fromHandle(core.MojoHandle handle, [this._impl]) |
| 307 : super.fromHandle(handle); |
| 308 |
| 309 FilesStub.unbound() : super.unbound(); |
| 310 |
| 311 static FilesStub newFromEndpoint( |
| 312 core.MojoMessagePipeEndpoint endpoint) { |
| 313 assert(endpoint.setDescription("For FilesStub")); |
| 314 return new FilesStub.fromEndpoint(endpoint); |
| 315 } |
| 316 |
| 317 static const String name = FilesName; |
| 318 |
| 319 |
| 320 FilesOpenFileSystemResponseParams _FilesOpenFileSystemResponseParamsFactory(ty
pes_mojom.Error error) { |
| 321 var result = new FilesOpenFileSystemResponseParams(); |
| 322 result.error = error; |
| 323 return result; |
| 324 } |
| 325 |
| 326 dynamic handleMessage(bindings.ServiceMessage message) { |
| 327 if (bindings.ControlMessageHandler.isControlMessage(message)) { |
| 328 return bindings.ControlMessageHandler.handleMessage(this, |
| 329 0, |
| 330 message); |
| 331 } |
| 332 assert(_impl != null); |
| 333 switch (message.header.type) { |
| 334 case kFiles_openFileSystem_name: |
| 335 var params = FilesOpenFileSystemParams.deserialize( |
| 336 message.payload); |
| 337 var response = _impl.openFileSystem(params.fileSystem,params.directory,_
FilesOpenFileSystemResponseParamsFactory); |
| 338 if (response is Future) { |
| 339 return response.then((response) { |
| 340 if (response != null) { |
| 341 return buildResponseWithId( |
| 342 response, |
| 343 kFiles_openFileSystem_name, |
| 344 message.header.requestId, |
| 345 bindings.MessageHeader.kMessageIsResponse); |
| 346 } |
| 347 }); |
| 348 } else if (response != null) { |
| 349 return buildResponseWithId( |
| 350 response, |
| 351 kFiles_openFileSystem_name, |
| 352 message.header.requestId, |
| 353 bindings.MessageHeader.kMessageIsResponse); |
| 354 } |
| 355 break; |
| 356 default: |
| 357 throw new bindings.MojoCodecError("Unexpected message name"); |
| 358 break; |
| 359 } |
| 360 return null; |
| 361 } |
| 362 |
| 363 Files get impl => _impl; |
| 364 set impl(Files d) { |
| 365 assert(_impl == null); |
| 366 _impl = d; |
| 367 } |
| 368 |
| 369 String toString() { |
| 370 var superString = super.toString(); |
| 371 return "FilesStub($superString)"; |
| 372 } |
| 373 |
| 374 int get version => 0; |
| 375 } |
| 376 |
| 377 |
OLD | NEW |