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 scheduling_mojom; | 5 library scheduling_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 | 10 |
11 | 11 |
12 | 12 |
13 class FrameInfo extends bindings.Struct { | 13 class FrameInfo extends bindings.Struct { |
14 static const List<bindings.StructDataHeader> kVersions = const [ | 14 static const List<bindings.StructDataHeader> kVersions = const [ |
15 const bindings.StructDataHeader(40, 0) | 15 const bindings.StructDataHeader(40, 0) |
16 ]; | 16 ]; |
17 int frameTime = 0; | 17 int frameTime = 0; |
18 int frameInterval = 0; | 18 int frameInterval = 0; |
19 int frameDeadline = 0; | 19 int frameDeadline = 0; |
20 int presentationTime = 0; | 20 int presentationTime = 0; |
21 | 21 |
22 FrameInfo() : super(kVersions.last.size); | 22 FrameInfo() : super(kVersions.last.size); |
23 | 23 |
| 24 FrameInfo.init( |
| 25 int this.frameTime, |
| 26 int this.frameInterval, |
| 27 int this.frameDeadline, |
| 28 int this.presentationTime |
| 29 ) : super(kVersions.last.size); |
| 30 |
24 static FrameInfo deserialize(bindings.Message message) { | 31 static FrameInfo deserialize(bindings.Message message) { |
25 var decoder = new bindings.Decoder(message); | 32 var decoder = new bindings.Decoder(message); |
26 var result = decode(decoder); | 33 var result = decode(decoder); |
27 if (decoder.excessHandles != null) { | 34 if (decoder.excessHandles != null) { |
28 decoder.excessHandles.forEach((h) => h.close()); | 35 decoder.excessHandles.forEach((h) => h.close()); |
29 } | 36 } |
30 return result; | 37 return result; |
31 } | 38 } |
32 | 39 |
33 static FrameInfo decode(bindings.Decoder decoder0) { | 40 static FrameInfo decode(bindings.Decoder decoder0) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 131 } |
125 | 132 |
126 | 133 |
127 class _FrameSchedulerScheduleFrameParams extends bindings.Struct { | 134 class _FrameSchedulerScheduleFrameParams extends bindings.Struct { |
128 static const List<bindings.StructDataHeader> kVersions = const [ | 135 static const List<bindings.StructDataHeader> kVersions = const [ |
129 const bindings.StructDataHeader(8, 0) | 136 const bindings.StructDataHeader(8, 0) |
130 ]; | 137 ]; |
131 | 138 |
132 _FrameSchedulerScheduleFrameParams() : super(kVersions.last.size); | 139 _FrameSchedulerScheduleFrameParams() : super(kVersions.last.size); |
133 | 140 |
| 141 _FrameSchedulerScheduleFrameParams.init( |
| 142 ) : super(kVersions.last.size); |
| 143 |
134 static _FrameSchedulerScheduleFrameParams deserialize(bindings.Message message
) { | 144 static _FrameSchedulerScheduleFrameParams deserialize(bindings.Message message
) { |
135 var decoder = new bindings.Decoder(message); | 145 var decoder = new bindings.Decoder(message); |
136 var result = decode(decoder); | 146 var result = decode(decoder); |
137 if (decoder.excessHandles != null) { | 147 if (decoder.excessHandles != null) { |
138 decoder.excessHandles.forEach((h) => h.close()); | 148 decoder.excessHandles.forEach((h) => h.close()); |
139 } | 149 } |
140 return result; | 150 return result; |
141 } | 151 } |
142 | 152 |
143 static _FrameSchedulerScheduleFrameParams decode(bindings.Decoder decoder0) { | 153 static _FrameSchedulerScheduleFrameParams decode(bindings.Decoder decoder0) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 193 |
184 | 194 |
185 class FrameSchedulerScheduleFrameResponseParams extends bindings.Struct { | 195 class FrameSchedulerScheduleFrameResponseParams extends bindings.Struct { |
186 static const List<bindings.StructDataHeader> kVersions = const [ | 196 static const List<bindings.StructDataHeader> kVersions = const [ |
187 const bindings.StructDataHeader(16, 0) | 197 const bindings.StructDataHeader(16, 0) |
188 ]; | 198 ]; |
189 FrameInfo frameInfo = null; | 199 FrameInfo frameInfo = null; |
190 | 200 |
191 FrameSchedulerScheduleFrameResponseParams() : super(kVersions.last.size); | 201 FrameSchedulerScheduleFrameResponseParams() : super(kVersions.last.size); |
192 | 202 |
| 203 FrameSchedulerScheduleFrameResponseParams.init( |
| 204 FrameInfo this.frameInfo |
| 205 ) : super(kVersions.last.size); |
| 206 |
193 static FrameSchedulerScheduleFrameResponseParams deserialize(bindings.Message
message) { | 207 static FrameSchedulerScheduleFrameResponseParams deserialize(bindings.Message
message) { |
194 var decoder = new bindings.Decoder(message); | 208 var decoder = new bindings.Decoder(message); |
195 var result = decode(decoder); | 209 var result = decode(decoder); |
196 if (decoder.excessHandles != null) { | 210 if (decoder.excessHandles != null) { |
197 decoder.excessHandles.forEach((h) => h.close()); | 211 decoder.excessHandles.forEach((h) => h.close()); |
198 } | 212 } |
199 return result; | 213 return result; |
200 } | 214 } |
201 | 215 |
202 static FrameSchedulerScheduleFrameResponseParams decode(bindings.Decoder decod
er0) { | 216 static FrameSchedulerScheduleFrameResponseParams decode(bindings.Decoder decod
er0) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 Map toJson() { | 264 Map toJson() { |
251 Map map = new Map(); | 265 Map map = new Map(); |
252 map["frameInfo"] = frameInfo; | 266 map["frameInfo"] = frameInfo; |
253 return map; | 267 return map; |
254 } | 268 } |
255 } | 269 } |
256 | 270 |
257 const int _frameSchedulerMethodScheduleFrameName = 0; | 271 const int _frameSchedulerMethodScheduleFrameName = 0; |
258 | 272 |
259 class _FrameSchedulerServiceDescription implements service_describer.ServiceDesc
ription { | 273 class _FrameSchedulerServiceDescription implements service_describer.ServiceDesc
ription { |
260 dynamic getTopLevelInterface([Function responseFactory]) => | 274 void getTopLevelInterface(Function responder) { |
261 responseFactory(null); | 275 responder(null); |
| 276 } |
262 | 277 |
263 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => | 278 void getTypeDefinition(String typeKey, Function responder) { |
264 responseFactory(null); | 279 responder(null); |
| 280 } |
265 | 281 |
266 dynamic getAllTypeDefinitions([Function responseFactory]) => | 282 void getAllTypeDefinitions(Function responder) { |
267 responseFactory(null); | 283 responder(null); |
| 284 } |
268 } | 285 } |
269 | 286 |
270 abstract class FrameScheduler { | 287 abstract class FrameScheduler { |
271 static const String serviceName = null; | 288 static const String serviceName = null; |
272 | 289 |
273 static service_describer.ServiceDescription _cachedServiceDescription; | 290 static service_describer.ServiceDescription _cachedServiceDescription; |
274 static service_describer.ServiceDescription get serviceDescription { | 291 static service_describer.ServiceDescription get serviceDescription { |
275 if (_cachedServiceDescription == null) { | 292 if (_cachedServiceDescription == null) { |
276 _cachedServiceDescription = new _FrameSchedulerServiceDescription(); | 293 _cachedServiceDescription = new _FrameSchedulerServiceDescription(); |
277 } | 294 } |
278 return _cachedServiceDescription; | 295 return _cachedServiceDescription; |
279 } | 296 } |
280 | 297 |
281 static FrameSchedulerProxy connectToService( | 298 static FrameSchedulerProxy connectToService( |
282 bindings.ServiceConnector s, String url, [String serviceName]) { | 299 bindings.ServiceConnector s, String url, [String serviceName]) { |
283 FrameSchedulerProxy p = new FrameSchedulerProxy.unbound(); | 300 FrameSchedulerProxy p = new FrameSchedulerProxy.unbound(); |
284 String name = serviceName ?? FrameScheduler.serviceName; | 301 String name = serviceName ?? FrameScheduler.serviceName; |
285 if ((name == null) || name.isEmpty) { | 302 if ((name == null) || name.isEmpty) { |
286 throw new core.MojoApiError( | 303 throw new core.MojoApiError( |
287 "If an interface has no ServiceName, then one must be provided."); | 304 "If an interface has no ServiceName, then one must be provided."); |
288 } | 305 } |
289 s.connectToService(url, p, name); | 306 s.connectToService(url, p, name); |
290 return p; | 307 return p; |
291 } | 308 } |
292 dynamic scheduleFrame([Function responseFactory = null]); | 309 void scheduleFrame(void callback(FrameInfo frameInfo)); |
293 } | 310 } |
294 | 311 |
295 abstract class FrameSchedulerInterface | 312 abstract class FrameSchedulerInterface |
296 implements bindings.MojoInterface<FrameScheduler>, | 313 implements bindings.MojoInterface<FrameScheduler>, |
297 FrameScheduler { | 314 FrameScheduler { |
298 factory FrameSchedulerInterface([FrameScheduler impl]) => | 315 factory FrameSchedulerInterface([FrameScheduler impl]) => |
299 new FrameSchedulerStub.unbound(impl); | 316 new FrameSchedulerStub.unbound(impl); |
300 | 317 |
301 factory FrameSchedulerInterface.fromEndpoint( | 318 factory FrameSchedulerInterface.fromEndpoint( |
302 core.MojoMessagePipeEndpoint endpoint, | 319 core.MojoMessagePipeEndpoint endpoint, |
(...skipping 29 matching lines...) Expand all Loading... |
332 | 349 |
333 void handleResponse(bindings.ServiceMessage message) { | 350 void handleResponse(bindings.ServiceMessage message) { |
334 switch (message.header.type) { | 351 switch (message.header.type) { |
335 case _frameSchedulerMethodScheduleFrameName: | 352 case _frameSchedulerMethodScheduleFrameName: |
336 var r = FrameSchedulerScheduleFrameResponseParams.deserialize( | 353 var r = FrameSchedulerScheduleFrameResponseParams.deserialize( |
337 message.payload); | 354 message.payload); |
338 if (!message.header.hasRequestId) { | 355 if (!message.header.hasRequestId) { |
339 proxyError("Expected a message with a valid request Id."); | 356 proxyError("Expected a message with a valid request Id."); |
340 return; | 357 return; |
341 } | 358 } |
342 Completer c = completerMap[message.header.requestId]; | 359 Function callback = callbackMap[message.header.requestId]; |
343 if (c == null) { | 360 if (callback == null) { |
344 proxyError( | 361 proxyError( |
345 "Message had unknown request Id: ${message.header.requestId}"); | 362 "Message had unknown request Id: ${message.header.requestId}"); |
346 return; | 363 return; |
347 } | 364 } |
348 completerMap.remove(message.header.requestId); | 365 callbackMap.remove(message.header.requestId); |
349 if (c.isCompleted) { | 366 callback(r.frameInfo ); |
350 proxyError("Response completer already completed"); | |
351 return; | |
352 } | |
353 c.complete(r); | |
354 break; | 367 break; |
355 default: | 368 default: |
356 proxyError("Unexpected message type: ${message.header.type}"); | 369 proxyError("Unexpected message type: ${message.header.type}"); |
357 close(immediate: true); | 370 close(immediate: true); |
358 break; | 371 break; |
359 } | 372 } |
360 } | 373 } |
361 | 374 |
362 @override | 375 @override |
363 String toString() { | 376 String toString() { |
(...skipping 24 matching lines...) Expand all Loading... |
388 return newMockedProxy; | 401 return newMockedProxy; |
389 } | 402 } |
390 | 403 |
391 static FrameSchedulerProxy newFromEndpoint( | 404 static FrameSchedulerProxy newFromEndpoint( |
392 core.MojoMessagePipeEndpoint endpoint) { | 405 core.MojoMessagePipeEndpoint endpoint) { |
393 assert(endpoint.setDescription("For FrameSchedulerProxy")); | 406 assert(endpoint.setDescription("For FrameSchedulerProxy")); |
394 return new FrameSchedulerProxy.fromEndpoint(endpoint); | 407 return new FrameSchedulerProxy.fromEndpoint(endpoint); |
395 } | 408 } |
396 | 409 |
397 | 410 |
398 dynamic scheduleFrame([Function responseFactory = null]) { | 411 void scheduleFrame(void callback(FrameInfo frameInfo)) { |
399 if (impl != null) { | 412 if (impl != null) { |
400 return new Future(() => impl.scheduleFrame(_FrameSchedulerStubControl._fra
meSchedulerScheduleFrameResponseParamsFactory)); | 413 impl.scheduleFrame(callback); |
| 414 return; |
401 } | 415 } |
402 var params = new _FrameSchedulerScheduleFrameParams(); | 416 var params = new _FrameSchedulerScheduleFrameParams(); |
403 return ctrl.sendMessageWithRequestId( | 417 ctrl.sendMessageWithRequestId( |
404 params, | 418 params, |
405 _frameSchedulerMethodScheduleFrameName, | 419 _frameSchedulerMethodScheduleFrameName, |
406 -1, | 420 -1, |
407 bindings.MessageHeader.kMessageExpectsResponse); | 421 bindings.MessageHeader.kMessageExpectsResponse, |
| 422 callback); |
408 } | 423 } |
409 } | 424 } |
410 | 425 |
411 class _FrameSchedulerStubControl | 426 class _FrameSchedulerStubControl |
412 extends bindings.StubMessageHandler | 427 extends bindings.StubMessageHandler |
413 implements bindings.StubControl<FrameScheduler> { | 428 implements bindings.StubControl<FrameScheduler> { |
414 FrameScheduler _impl; | 429 FrameScheduler _impl; |
415 | 430 |
416 _FrameSchedulerStubControl.fromEndpoint( | 431 _FrameSchedulerStubControl.fromEndpoint( |
417 core.MojoMessagePipeEndpoint endpoint, [FrameScheduler impl]) | 432 core.MojoMessagePipeEndpoint endpoint, [FrameScheduler impl]) |
418 : super.fromEndpoint(endpoint, autoBegin: impl != null) { | 433 : super.fromEndpoint(endpoint, autoBegin: impl != null) { |
419 _impl = impl; | 434 _impl = impl; |
420 } | 435 } |
421 | 436 |
422 _FrameSchedulerStubControl.fromHandle( | 437 _FrameSchedulerStubControl.fromHandle( |
423 core.MojoHandle handle, [FrameScheduler impl]) | 438 core.MojoHandle handle, [FrameScheduler impl]) |
424 : super.fromHandle(handle, autoBegin: impl != null) { | 439 : super.fromHandle(handle, autoBegin: impl != null) { |
425 _impl = impl; | 440 _impl = impl; |
426 } | 441 } |
427 | 442 |
428 _FrameSchedulerStubControl.unbound([this._impl]) : super.unbound(); | 443 _FrameSchedulerStubControl.unbound([this._impl]) : super.unbound(); |
429 | 444 |
430 String get serviceName => FrameScheduler.serviceName; | 445 String get serviceName => FrameScheduler.serviceName; |
431 | 446 |
432 | 447 |
433 static FrameSchedulerScheduleFrameResponseParams _frameSchedulerScheduleFrameR
esponseParamsFactory(FrameInfo frameInfo) { | 448 Function _frameSchedulerScheduleFrameResponseParamsResponder( |
434 var result = new FrameSchedulerScheduleFrameResponseParams(); | 449 int requestId) { |
435 result.frameInfo = frameInfo; | 450 return (FrameInfo frameInfo) { |
436 return result; | 451 var result = new FrameSchedulerScheduleFrameResponseParams(); |
| 452 result.frameInfo = frameInfo; |
| 453 sendResponse(buildResponseWithId( |
| 454 result, |
| 455 _frameSchedulerMethodScheduleFrameName, |
| 456 requestId, |
| 457 bindings.MessageHeader.kMessageIsResponse)); |
| 458 }; |
437 } | 459 } |
438 | 460 |
439 dynamic handleMessage(bindings.ServiceMessage message) { | 461 void handleMessage(bindings.ServiceMessage message) { |
440 if (bindings.ControlMessageHandler.isControlMessage(message)) { | 462 if (bindings.ControlMessageHandler.isControlMessage(message)) { |
441 return bindings.ControlMessageHandler.handleMessage(this, | 463 bindings.ControlMessageHandler.handleMessage( |
442 0, | 464 this, 0, message); |
443 message); | 465 return; |
444 } | 466 } |
445 if (_impl == null) { | 467 if (_impl == null) { |
446 throw new core.MojoApiError("$this has no implementation set"); | 468 throw new core.MojoApiError("$this has no implementation set"); |
447 } | 469 } |
448 switch (message.header.type) { | 470 switch (message.header.type) { |
449 case _frameSchedulerMethodScheduleFrameName: | 471 case _frameSchedulerMethodScheduleFrameName: |
450 var response = _impl.scheduleFrame(_frameSchedulerScheduleFrameResponseP
aramsFactory); | 472 _impl.scheduleFrame(_frameSchedulerScheduleFrameResponseParamsResponder(
message.header.requestId)); |
451 if (response is Future) { | |
452 return response.then((response) { | |
453 if (response != null) { | |
454 return buildResponseWithId( | |
455 response, | |
456 _frameSchedulerMethodScheduleFrameName, | |
457 message.header.requestId, | |
458 bindings.MessageHeader.kMessageIsResponse); | |
459 } | |
460 }); | |
461 } else if (response != null) { | |
462 return buildResponseWithId( | |
463 response, | |
464 _frameSchedulerMethodScheduleFrameName, | |
465 message.header.requestId, | |
466 bindings.MessageHeader.kMessageIsResponse); | |
467 } | |
468 break; | 473 break; |
469 default: | 474 default: |
470 throw new bindings.MojoCodecError("Unexpected message name"); | 475 throw new bindings.MojoCodecError("Unexpected message name"); |
471 break; | 476 break; |
472 } | 477 } |
473 return null; | |
474 } | 478 } |
475 | 479 |
476 FrameScheduler get impl => _impl; | 480 FrameScheduler get impl => _impl; |
477 set impl(FrameScheduler d) { | 481 set impl(FrameScheduler d) { |
478 if (d == null) { | 482 if (d == null) { |
479 throw new core.MojoApiError("$this: Cannot set a null implementation"); | 483 throw new core.MojoApiError("$this: Cannot set a null implementation"); |
480 } | 484 } |
481 if (isBound && (_impl == null)) { | 485 if (isBound && (_impl == null)) { |
482 beginHandlingEvents(); | 486 beginHandlingEvents(); |
483 } | 487 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 core.MojoHandle handle, [FrameScheduler impl]) | 521 core.MojoHandle handle, [FrameScheduler impl]) |
518 : super(new _FrameSchedulerStubControl.fromHandle(handle, impl)); | 522 : super(new _FrameSchedulerStubControl.fromHandle(handle, impl)); |
519 | 523 |
520 static FrameSchedulerStub newFromEndpoint( | 524 static FrameSchedulerStub newFromEndpoint( |
521 core.MojoMessagePipeEndpoint endpoint) { | 525 core.MojoMessagePipeEndpoint endpoint) { |
522 assert(endpoint.setDescription("For FrameSchedulerStub")); | 526 assert(endpoint.setDescription("For FrameSchedulerStub")); |
523 return new FrameSchedulerStub.fromEndpoint(endpoint); | 527 return new FrameSchedulerStub.fromEndpoint(endpoint); |
524 } | 528 } |
525 | 529 |
526 | 530 |
527 dynamic scheduleFrame([Function responseFactory = null]) { | 531 void scheduleFrame(void callback(FrameInfo frameInfo)) { |
528 return impl.scheduleFrame(responseFactory); | 532 return impl.scheduleFrame(callback); |
529 } | 533 } |
530 } | 534 } |
531 | 535 |
532 | 536 |
533 | 537 |
OLD | NEW |