| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 library files_mojom; | 5 library files_mojom; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'package:mojo/bindings.dart' as bindings; | 7 import 'package:mojo/bindings.dart' as bindings; |
| 8 import 'package:mojo/core.dart' as core; | 8 import 'package:mojo/core.dart' as core; |
| 9 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' as servic
e_describer; | 9 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' as servic
e_describer; |
| 10 import 'package:mojo_services/mojo/files/directory.mojom.dart' as directory_mojo
m; | 10 import 'package:mojo_services/mojo/files/directory.mojom.dart' as directory_mojo
m; |
| 11 import 'package:mojo_services/mojo/files/types.mojom.dart' as types_mojom; | 11 import 'package:mojo_services/mojo/files/types.mojom.dart' as types_mojom; |
| 12 | 12 |
| 13 | 13 |
| 14 | 14 |
| 15 class _FilesOpenFileSystemParams extends bindings.Struct { | 15 class _FilesOpenFileSystemParams extends bindings.Struct { |
| 16 static const List<bindings.StructDataHeader> kVersions = const [ | 16 static const List<bindings.StructDataHeader> kVersions = const [ |
| 17 const bindings.StructDataHeader(24, 0) | 17 const bindings.StructDataHeader(24, 0) |
| 18 ]; | 18 ]; |
| 19 String fileSystem = null; | 19 String fileSystem = null; |
| 20 directory_mojom.DirectoryInterfaceRequest directory = null; | 20 directory_mojom.DirectoryInterfaceRequest directory = null; |
| 21 | 21 |
| 22 _FilesOpenFileSystemParams() : super(kVersions.last.size); | 22 _FilesOpenFileSystemParams() : super(kVersions.last.size); |
| 23 | 23 |
| 24 _FilesOpenFileSystemParams.init( |
| 25 String this.fileSystem, |
| 26 directory_mojom.DirectoryInterfaceRequest this.directory |
| 27 ) : super(kVersions.last.size); |
| 28 |
| 24 static _FilesOpenFileSystemParams deserialize(bindings.Message message) { | 29 static _FilesOpenFileSystemParams deserialize(bindings.Message message) { |
| 25 var decoder = new bindings.Decoder(message); | 30 var decoder = new bindings.Decoder(message); |
| 26 var result = decode(decoder); | 31 var result = decode(decoder); |
| 27 if (decoder.excessHandles != null) { | 32 if (decoder.excessHandles != null) { |
| 28 decoder.excessHandles.forEach((h) => h.close()); | 33 decoder.excessHandles.forEach((h) => h.close()); |
| 29 } | 34 } |
| 30 return result; | 35 return result; |
| 31 } | 36 } |
| 32 | 37 |
| 33 static _FilesOpenFileSystemParams decode(bindings.Decoder decoder0) { | 38 static _FilesOpenFileSystemParams decode(bindings.Decoder decoder0) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 102 |
| 98 | 103 |
| 99 class FilesOpenFileSystemResponseParams extends bindings.Struct { | 104 class FilesOpenFileSystemResponseParams extends bindings.Struct { |
| 100 static const List<bindings.StructDataHeader> kVersions = const [ | 105 static const List<bindings.StructDataHeader> kVersions = const [ |
| 101 const bindings.StructDataHeader(16, 0) | 106 const bindings.StructDataHeader(16, 0) |
| 102 ]; | 107 ]; |
| 103 types_mojom.Error error = null; | 108 types_mojom.Error error = null; |
| 104 | 109 |
| 105 FilesOpenFileSystemResponseParams() : super(kVersions.last.size); | 110 FilesOpenFileSystemResponseParams() : super(kVersions.last.size); |
| 106 | 111 |
| 112 FilesOpenFileSystemResponseParams.init( |
| 113 types_mojom.Error this.error |
| 114 ) : super(kVersions.last.size); |
| 115 |
| 107 static FilesOpenFileSystemResponseParams deserialize(bindings.Message message)
{ | 116 static FilesOpenFileSystemResponseParams deserialize(bindings.Message message)
{ |
| 108 var decoder = new bindings.Decoder(message); | 117 var decoder = new bindings.Decoder(message); |
| 109 var result = decode(decoder); | 118 var result = decode(decoder); |
| 110 if (decoder.excessHandles != null) { | 119 if (decoder.excessHandles != null) { |
| 111 decoder.excessHandles.forEach((h) => h.close()); | 120 decoder.excessHandles.forEach((h) => h.close()); |
| 112 } | 121 } |
| 113 return result; | 122 return result; |
| 114 } | 123 } |
| 115 | 124 |
| 116 static FilesOpenFileSystemResponseParams decode(bindings.Decoder decoder0) { | 125 static FilesOpenFileSystemResponseParams decode(bindings.Decoder decoder0) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 Map toJson() { | 176 Map toJson() { |
| 168 Map map = new Map(); | 177 Map map = new Map(); |
| 169 map["error"] = error; | 178 map["error"] = error; |
| 170 return map; | 179 return map; |
| 171 } | 180 } |
| 172 } | 181 } |
| 173 | 182 |
| 174 const int _filesMethodOpenFileSystemName = 0; | 183 const int _filesMethodOpenFileSystemName = 0; |
| 175 | 184 |
| 176 class _FilesServiceDescription implements service_describer.ServiceDescription { | 185 class _FilesServiceDescription implements service_describer.ServiceDescription { |
| 177 dynamic getTopLevelInterface([Function responseFactory]) => | 186 void getTopLevelInterface(Function responder) { |
| 178 responseFactory(null); | 187 responder(null); |
| 188 } |
| 179 | 189 |
| 180 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => | 190 void getTypeDefinition(String typeKey, Function responder) { |
| 181 responseFactory(null); | 191 responder(null); |
| 192 } |
| 182 | 193 |
| 183 dynamic getAllTypeDefinitions([Function responseFactory]) => | 194 void getAllTypeDefinitions(Function responder) { |
| 184 responseFactory(null); | 195 responder(null); |
| 196 } |
| 185 } | 197 } |
| 186 | 198 |
| 187 abstract class Files { | 199 abstract class Files { |
| 188 static const String serviceName = "mojo::files::Files"; | 200 static const String serviceName = "mojo::files::Files"; |
| 189 | 201 |
| 190 static service_describer.ServiceDescription _cachedServiceDescription; | 202 static service_describer.ServiceDescription _cachedServiceDescription; |
| 191 static service_describer.ServiceDescription get serviceDescription { | 203 static service_describer.ServiceDescription get serviceDescription { |
| 192 if (_cachedServiceDescription == null) { | 204 if (_cachedServiceDescription == null) { |
| 193 _cachedServiceDescription = new _FilesServiceDescription(); | 205 _cachedServiceDescription = new _FilesServiceDescription(); |
| 194 } | 206 } |
| 195 return _cachedServiceDescription; | 207 return _cachedServiceDescription; |
| 196 } | 208 } |
| 197 | 209 |
| 198 static FilesProxy connectToService( | 210 static FilesProxy connectToService( |
| 199 bindings.ServiceConnector s, String url, [String serviceName]) { | 211 bindings.ServiceConnector s, String url, [String serviceName]) { |
| 200 FilesProxy p = new FilesProxy.unbound(); | 212 FilesProxy p = new FilesProxy.unbound(); |
| 201 String name = serviceName ?? Files.serviceName; | 213 String name = serviceName ?? Files.serviceName; |
| 202 if ((name == null) || name.isEmpty) { | 214 if ((name == null) || name.isEmpty) { |
| 203 throw new core.MojoApiError( | 215 throw new core.MojoApiError( |
| 204 "If an interface has no ServiceName, then one must be provided."); | 216 "If an interface has no ServiceName, then one must be provided."); |
| 205 } | 217 } |
| 206 s.connectToService(url, p, name); | 218 s.connectToService(url, p, name); |
| 207 return p; | 219 return p; |
| 208 } | 220 } |
| 209 dynamic openFileSystem(String fileSystem,directory_mojom.DirectoryInterfaceReq
uest directory,[Function responseFactory = null]); | 221 void openFileSystem(String fileSystem,directory_mojom.DirectoryInterfaceReques
t directory,void callback(types_mojom.Error error)); |
| 210 } | 222 } |
| 211 | 223 |
| 212 abstract class FilesInterface | 224 abstract class FilesInterface |
| 213 implements bindings.MojoInterface<Files>, | 225 implements bindings.MojoInterface<Files>, |
| 214 Files { | 226 Files { |
| 215 factory FilesInterface([Files impl]) => | 227 factory FilesInterface([Files impl]) => |
| 216 new FilesStub.unbound(impl); | 228 new FilesStub.unbound(impl); |
| 217 | 229 |
| 218 factory FilesInterface.fromEndpoint( | 230 factory FilesInterface.fromEndpoint( |
| 219 core.MojoMessagePipeEndpoint endpoint, | 231 core.MojoMessagePipeEndpoint endpoint, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 249 | 261 |
| 250 void handleResponse(bindings.ServiceMessage message) { | 262 void handleResponse(bindings.ServiceMessage message) { |
| 251 switch (message.header.type) { | 263 switch (message.header.type) { |
| 252 case _filesMethodOpenFileSystemName: | 264 case _filesMethodOpenFileSystemName: |
| 253 var r = FilesOpenFileSystemResponseParams.deserialize( | 265 var r = FilesOpenFileSystemResponseParams.deserialize( |
| 254 message.payload); | 266 message.payload); |
| 255 if (!message.header.hasRequestId) { | 267 if (!message.header.hasRequestId) { |
| 256 proxyError("Expected a message with a valid request Id."); | 268 proxyError("Expected a message with a valid request Id."); |
| 257 return; | 269 return; |
| 258 } | 270 } |
| 259 Completer c = completerMap[message.header.requestId]; | 271 Function callback = callbackMap[message.header.requestId]; |
| 260 if (c == null) { | 272 if (callback == null) { |
| 261 proxyError( | 273 proxyError( |
| 262 "Message had unknown request Id: ${message.header.requestId}"); | 274 "Message had unknown request Id: ${message.header.requestId}"); |
| 263 return; | 275 return; |
| 264 } | 276 } |
| 265 completerMap.remove(message.header.requestId); | 277 callbackMap.remove(message.header.requestId); |
| 266 if (c.isCompleted) { | 278 callback(r.error ); |
| 267 proxyError("Response completer already completed"); | |
| 268 return; | |
| 269 } | |
| 270 c.complete(r); | |
| 271 break; | 279 break; |
| 272 default: | 280 default: |
| 273 proxyError("Unexpected message type: ${message.header.type}"); | 281 proxyError("Unexpected message type: ${message.header.type}"); |
| 274 close(immediate: true); | 282 close(immediate: true); |
| 275 break; | 283 break; |
| 276 } | 284 } |
| 277 } | 285 } |
| 278 | 286 |
| 279 @override | 287 @override |
| 280 String toString() { | 288 String toString() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 305 return newMockedProxy; | 313 return newMockedProxy; |
| 306 } | 314 } |
| 307 | 315 |
| 308 static FilesProxy newFromEndpoint( | 316 static FilesProxy newFromEndpoint( |
| 309 core.MojoMessagePipeEndpoint endpoint) { | 317 core.MojoMessagePipeEndpoint endpoint) { |
| 310 assert(endpoint.setDescription("For FilesProxy")); | 318 assert(endpoint.setDescription("For FilesProxy")); |
| 311 return new FilesProxy.fromEndpoint(endpoint); | 319 return new FilesProxy.fromEndpoint(endpoint); |
| 312 } | 320 } |
| 313 | 321 |
| 314 | 322 |
| 315 dynamic openFileSystem(String fileSystem,directory_mojom.DirectoryInterfaceReq
uest directory,[Function responseFactory = null]) { | 323 void openFileSystem(String fileSystem,directory_mojom.DirectoryInterfaceReques
t directory,void callback(types_mojom.Error error)) { |
| 316 if (impl != null) { | 324 if (impl != null) { |
| 317 return new Future(() => impl.openFileSystem(fileSystem,directory,_FilesStu
bControl._filesOpenFileSystemResponseParamsFactory)); | 325 impl.openFileSystem(fileSystem,directory,callback); |
| 326 return; |
| 318 } | 327 } |
| 319 var params = new _FilesOpenFileSystemParams(); | 328 var params = new _FilesOpenFileSystemParams(); |
| 320 params.fileSystem = fileSystem; | 329 params.fileSystem = fileSystem; |
| 321 params.directory = directory; | 330 params.directory = directory; |
| 322 return ctrl.sendMessageWithRequestId( | 331 ctrl.sendMessageWithRequestId( |
| 323 params, | 332 params, |
| 324 _filesMethodOpenFileSystemName, | 333 _filesMethodOpenFileSystemName, |
| 325 -1, | 334 -1, |
| 326 bindings.MessageHeader.kMessageExpectsResponse); | 335 bindings.MessageHeader.kMessageExpectsResponse, |
| 336 callback); |
| 327 } | 337 } |
| 328 } | 338 } |
| 329 | 339 |
| 330 class _FilesStubControl | 340 class _FilesStubControl |
| 331 extends bindings.StubMessageHandler | 341 extends bindings.StubMessageHandler |
| 332 implements bindings.StubControl<Files> { | 342 implements bindings.StubControl<Files> { |
| 333 Files _impl; | 343 Files _impl; |
| 334 | 344 |
| 335 _FilesStubControl.fromEndpoint( | 345 _FilesStubControl.fromEndpoint( |
| 336 core.MojoMessagePipeEndpoint endpoint, [Files impl]) | 346 core.MojoMessagePipeEndpoint endpoint, [Files impl]) |
| 337 : super.fromEndpoint(endpoint, autoBegin: impl != null) { | 347 : super.fromEndpoint(endpoint, autoBegin: impl != null) { |
| 338 _impl = impl; | 348 _impl = impl; |
| 339 } | 349 } |
| 340 | 350 |
| 341 _FilesStubControl.fromHandle( | 351 _FilesStubControl.fromHandle( |
| 342 core.MojoHandle handle, [Files impl]) | 352 core.MojoHandle handle, [Files impl]) |
| 343 : super.fromHandle(handle, autoBegin: impl != null) { | 353 : super.fromHandle(handle, autoBegin: impl != null) { |
| 344 _impl = impl; | 354 _impl = impl; |
| 345 } | 355 } |
| 346 | 356 |
| 347 _FilesStubControl.unbound([this._impl]) : super.unbound(); | 357 _FilesStubControl.unbound([this._impl]) : super.unbound(); |
| 348 | 358 |
| 349 String get serviceName => Files.serviceName; | 359 String get serviceName => Files.serviceName; |
| 350 | 360 |
| 351 | 361 |
| 352 static FilesOpenFileSystemResponseParams _filesOpenFileSystemResponseParamsFac
tory(types_mojom.Error error) { | 362 Function _filesOpenFileSystemResponseParamsResponder( |
| 353 var result = new FilesOpenFileSystemResponseParams(); | 363 int requestId) { |
| 354 result.error = error; | 364 return (types_mojom.Error error) { |
| 355 return result; | 365 var result = new FilesOpenFileSystemResponseParams(); |
| 366 result.error = error; |
| 367 sendResponse(buildResponseWithId( |
| 368 result, |
| 369 _filesMethodOpenFileSystemName, |
| 370 requestId, |
| 371 bindings.MessageHeader.kMessageIsResponse)); |
| 372 }; |
| 356 } | 373 } |
| 357 | 374 |
| 358 dynamic handleMessage(bindings.ServiceMessage message) { | 375 void handleMessage(bindings.ServiceMessage message) { |
| 359 if (bindings.ControlMessageHandler.isControlMessage(message)) { | 376 if (bindings.ControlMessageHandler.isControlMessage(message)) { |
| 360 return bindings.ControlMessageHandler.handleMessage(this, | 377 bindings.ControlMessageHandler.handleMessage( |
| 361 0, | 378 this, 0, message); |
| 362 message); | 379 return; |
| 363 } | 380 } |
| 364 if (_impl == null) { | 381 if (_impl == null) { |
| 365 throw new core.MojoApiError("$this has no implementation set"); | 382 throw new core.MojoApiError("$this has no implementation set"); |
| 366 } | 383 } |
| 367 switch (message.header.type) { | 384 switch (message.header.type) { |
| 368 case _filesMethodOpenFileSystemName: | 385 case _filesMethodOpenFileSystemName: |
| 369 var params = _FilesOpenFileSystemParams.deserialize( | 386 var params = _FilesOpenFileSystemParams.deserialize( |
| 370 message.payload); | 387 message.payload); |
| 371 var response = _impl.openFileSystem(params.fileSystem,params.directory,_
filesOpenFileSystemResponseParamsFactory); | 388 _impl.openFileSystem(params.fileSystem, params.directory, _filesOpenFile
SystemResponseParamsResponder(message.header.requestId)); |
| 372 if (response is Future) { | |
| 373 return response.then((response) { | |
| 374 if (response != null) { | |
| 375 return buildResponseWithId( | |
| 376 response, | |
| 377 _filesMethodOpenFileSystemName, | |
| 378 message.header.requestId, | |
| 379 bindings.MessageHeader.kMessageIsResponse); | |
| 380 } | |
| 381 }); | |
| 382 } else if (response != null) { | |
| 383 return buildResponseWithId( | |
| 384 response, | |
| 385 _filesMethodOpenFileSystemName, | |
| 386 message.header.requestId, | |
| 387 bindings.MessageHeader.kMessageIsResponse); | |
| 388 } | |
| 389 break; | 389 break; |
| 390 default: | 390 default: |
| 391 throw new bindings.MojoCodecError("Unexpected message name"); | 391 throw new bindings.MojoCodecError("Unexpected message name"); |
| 392 break; | 392 break; |
| 393 } | 393 } |
| 394 return null; | |
| 395 } | 394 } |
| 396 | 395 |
| 397 Files get impl => _impl; | 396 Files get impl => _impl; |
| 398 set impl(Files d) { | 397 set impl(Files d) { |
| 399 if (d == null) { | 398 if (d == null) { |
| 400 throw new core.MojoApiError("$this: Cannot set a null implementation"); | 399 throw new core.MojoApiError("$this: Cannot set a null implementation"); |
| 401 } | 400 } |
| 402 if (isBound && (_impl == null)) { | 401 if (isBound && (_impl == null)) { |
| 403 beginHandlingEvents(); | 402 beginHandlingEvents(); |
| 404 } | 403 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 core.MojoHandle handle, [Files impl]) | 437 core.MojoHandle handle, [Files impl]) |
| 439 : super(new _FilesStubControl.fromHandle(handle, impl)); | 438 : super(new _FilesStubControl.fromHandle(handle, impl)); |
| 440 | 439 |
| 441 static FilesStub newFromEndpoint( | 440 static FilesStub newFromEndpoint( |
| 442 core.MojoMessagePipeEndpoint endpoint) { | 441 core.MojoMessagePipeEndpoint endpoint) { |
| 443 assert(endpoint.setDescription("For FilesStub")); | 442 assert(endpoint.setDescription("For FilesStub")); |
| 444 return new FilesStub.fromEndpoint(endpoint); | 443 return new FilesStub.fromEndpoint(endpoint); |
| 445 } | 444 } |
| 446 | 445 |
| 447 | 446 |
| 448 dynamic openFileSystem(String fileSystem,directory_mojom.DirectoryInterfaceReq
uest directory,[Function responseFactory = null]) { | 447 void openFileSystem(String fileSystem,directory_mojom.DirectoryInterfaceReques
t directory,void callback(types_mojom.Error error)) { |
| 449 return impl.openFileSystem(fileSystem,directory,responseFactory); | 448 return impl.openFileSystem(fileSystem,directory,callback); |
| 450 } | 449 } |
| 451 } | 450 } |
| 452 | 451 |
| 453 | 452 |
| 454 | 453 |
| OLD | NEW |