Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: mojo/dart/packages/mojo_services/lib/vsync/vsync.mojom.dart

Issue 2006093002: Dart: Futures -> Callbacks. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Cleanup Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 vsync_mojom; 5 library vsync_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 _VSyncProviderAwaitVSyncParams extends bindings.Struct { 13 class _VSyncProviderAwaitVSyncParams extends bindings.Struct {
14 static const List<bindings.StructDataHeader> kVersions = const [ 14 static const List<bindings.StructDataHeader> kVersions = const [
15 const bindings.StructDataHeader(8, 0) 15 const bindings.StructDataHeader(8, 0)
16 ]; 16 ];
17 17
18 _VSyncProviderAwaitVSyncParams() : super(kVersions.last.size); 18 _VSyncProviderAwaitVSyncParams() : super(kVersions.last.size);
19 19
20 _VSyncProviderAwaitVSyncParams.init(
21 ) : super(kVersions.last.size);
22
20 static _VSyncProviderAwaitVSyncParams deserialize(bindings.Message message) { 23 static _VSyncProviderAwaitVSyncParams deserialize(bindings.Message message) {
21 var decoder = new bindings.Decoder(message); 24 var decoder = new bindings.Decoder(message);
22 var result = decode(decoder); 25 var result = decode(decoder);
23 if (decoder.excessHandles != null) { 26 if (decoder.excessHandles != null) {
24 decoder.excessHandles.forEach((h) => h.close()); 27 decoder.excessHandles.forEach((h) => h.close());
25 } 28 }
26 return result; 29 return result;
27 } 30 }
28 31
29 static _VSyncProviderAwaitVSyncParams decode(bindings.Decoder decoder0) { 32 static _VSyncProviderAwaitVSyncParams decode(bindings.Decoder decoder0) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 72
70 73
71 class VSyncProviderAwaitVSyncResponseParams extends bindings.Struct { 74 class VSyncProviderAwaitVSyncResponseParams extends bindings.Struct {
72 static const List<bindings.StructDataHeader> kVersions = const [ 75 static const List<bindings.StructDataHeader> kVersions = const [
73 const bindings.StructDataHeader(16, 0) 76 const bindings.StructDataHeader(16, 0)
74 ]; 77 ];
75 int timeStamp = 0; 78 int timeStamp = 0;
76 79
77 VSyncProviderAwaitVSyncResponseParams() : super(kVersions.last.size); 80 VSyncProviderAwaitVSyncResponseParams() : super(kVersions.last.size);
78 81
82 VSyncProviderAwaitVSyncResponseParams.init(
83 int this.timeStamp
84 ) : super(kVersions.last.size);
85
79 static VSyncProviderAwaitVSyncResponseParams deserialize(bindings.Message mess age) { 86 static VSyncProviderAwaitVSyncResponseParams deserialize(bindings.Message mess age) {
80 var decoder = new bindings.Decoder(message); 87 var decoder = new bindings.Decoder(message);
81 var result = decode(decoder); 88 var result = decode(decoder);
82 if (decoder.excessHandles != null) { 89 if (decoder.excessHandles != null) {
83 decoder.excessHandles.forEach((h) => h.close()); 90 decoder.excessHandles.forEach((h) => h.close());
84 } 91 }
85 return result; 92 return result;
86 } 93 }
87 94
88 static VSyncProviderAwaitVSyncResponseParams decode(bindings.Decoder decoder0) { 95 static VSyncProviderAwaitVSyncResponseParams decode(bindings.Decoder decoder0) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 Map toJson() { 142 Map toJson() {
136 Map map = new Map(); 143 Map map = new Map();
137 map["timeStamp"] = timeStamp; 144 map["timeStamp"] = timeStamp;
138 return map; 145 return map;
139 } 146 }
140 } 147 }
141 148
142 const int _vSyncProviderMethodAwaitVSyncName = 0; 149 const int _vSyncProviderMethodAwaitVSyncName = 0;
143 150
144 class _VSyncProviderServiceDescription implements service_describer.ServiceDescr iption { 151 class _VSyncProviderServiceDescription implements service_describer.ServiceDescr iption {
145 dynamic getTopLevelInterface([Function responseFactory]) => 152 void getTopLevelInterface(Function responder) {
146 responseFactory(null); 153 responder(null);
154 }
147 155
148 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => 156 void getTypeDefinition(String typeKey, Function responder) {
149 responseFactory(null); 157 responder(null);
158 }
150 159
151 dynamic getAllTypeDefinitions([Function responseFactory]) => 160 void getAllTypeDefinitions(Function responder) {
152 responseFactory(null); 161 responder(null);
162 }
153 } 163 }
154 164
155 abstract class VSyncProvider { 165 abstract class VSyncProvider {
156 static const String serviceName = "vsync::VSyncProvider"; 166 static const String serviceName = "vsync::VSyncProvider";
157 167
158 static service_describer.ServiceDescription _cachedServiceDescription; 168 static service_describer.ServiceDescription _cachedServiceDescription;
159 static service_describer.ServiceDescription get serviceDescription { 169 static service_describer.ServiceDescription get serviceDescription {
160 if (_cachedServiceDescription == null) { 170 if (_cachedServiceDescription == null) {
161 _cachedServiceDescription = new _VSyncProviderServiceDescription(); 171 _cachedServiceDescription = new _VSyncProviderServiceDescription();
162 } 172 }
163 return _cachedServiceDescription; 173 return _cachedServiceDescription;
164 } 174 }
165 175
166 static VSyncProviderProxy connectToService( 176 static VSyncProviderProxy connectToService(
167 bindings.ServiceConnector s, String url, [String serviceName]) { 177 bindings.ServiceConnector s, String url, [String serviceName]) {
168 VSyncProviderProxy p = new VSyncProviderProxy.unbound(); 178 VSyncProviderProxy p = new VSyncProviderProxy.unbound();
169 String name = serviceName ?? VSyncProvider.serviceName; 179 String name = serviceName ?? VSyncProvider.serviceName;
170 if ((name == null) || name.isEmpty) { 180 if ((name == null) || name.isEmpty) {
171 throw new core.MojoApiError( 181 throw new core.MojoApiError(
172 "If an interface has no ServiceName, then one must be provided."); 182 "If an interface has no ServiceName, then one must be provided.");
173 } 183 }
174 s.connectToService(url, p, name); 184 s.connectToService(url, p, name);
175 return p; 185 return p;
176 } 186 }
177 dynamic awaitVSync([Function responseFactory = null]); 187 void awaitVSync(void callback(int timeStamp));
178 } 188 }
179 189
180 abstract class VSyncProviderInterface 190 abstract class VSyncProviderInterface
181 implements bindings.MojoInterface<VSyncProvider>, 191 implements bindings.MojoInterface<VSyncProvider>,
182 VSyncProvider { 192 VSyncProvider {
183 factory VSyncProviderInterface([VSyncProvider impl]) => 193 factory VSyncProviderInterface([VSyncProvider impl]) =>
184 new VSyncProviderStub.unbound(impl); 194 new VSyncProviderStub.unbound(impl);
185 195
186 factory VSyncProviderInterface.fromEndpoint( 196 factory VSyncProviderInterface.fromEndpoint(
187 core.MojoMessagePipeEndpoint endpoint, 197 core.MojoMessagePipeEndpoint endpoint,
(...skipping 29 matching lines...) Expand all
217 227
218 void handleResponse(bindings.ServiceMessage message) { 228 void handleResponse(bindings.ServiceMessage message) {
219 switch (message.header.type) { 229 switch (message.header.type) {
220 case _vSyncProviderMethodAwaitVSyncName: 230 case _vSyncProviderMethodAwaitVSyncName:
221 var r = VSyncProviderAwaitVSyncResponseParams.deserialize( 231 var r = VSyncProviderAwaitVSyncResponseParams.deserialize(
222 message.payload); 232 message.payload);
223 if (!message.header.hasRequestId) { 233 if (!message.header.hasRequestId) {
224 proxyError("Expected a message with a valid request Id."); 234 proxyError("Expected a message with a valid request Id.");
225 return; 235 return;
226 } 236 }
227 Completer c = completerMap[message.header.requestId]; 237 Function callback = callbackMap[message.header.requestId];
228 if (c == null) { 238 if (callback == null) {
229 proxyError( 239 proxyError(
230 "Message had unknown request Id: ${message.header.requestId}"); 240 "Message had unknown request Id: ${message.header.requestId}");
231 return; 241 return;
232 } 242 }
233 completerMap.remove(message.header.requestId); 243 callbackMap.remove(message.header.requestId);
234 if (c.isCompleted) { 244 callback(r.timeStamp );
235 proxyError("Response completer already completed");
236 return;
237 }
238 c.complete(r);
239 break; 245 break;
240 default: 246 default:
241 proxyError("Unexpected message type: ${message.header.type}"); 247 proxyError("Unexpected message type: ${message.header.type}");
242 close(immediate: true); 248 close(immediate: true);
243 break; 249 break;
244 } 250 }
245 } 251 }
246 252
247 @override 253 @override
248 String toString() { 254 String toString() {
(...skipping 24 matching lines...) Expand all
273 return newMockedProxy; 279 return newMockedProxy;
274 } 280 }
275 281
276 static VSyncProviderProxy newFromEndpoint( 282 static VSyncProviderProxy newFromEndpoint(
277 core.MojoMessagePipeEndpoint endpoint) { 283 core.MojoMessagePipeEndpoint endpoint) {
278 assert(endpoint.setDescription("For VSyncProviderProxy")); 284 assert(endpoint.setDescription("For VSyncProviderProxy"));
279 return new VSyncProviderProxy.fromEndpoint(endpoint); 285 return new VSyncProviderProxy.fromEndpoint(endpoint);
280 } 286 }
281 287
282 288
283 dynamic awaitVSync([Function responseFactory = null]) { 289 void awaitVSync(void callback(int timeStamp)) {
284 if (impl != null) { 290 if (impl != null) {
285 return new Future(() => impl.awaitVSync(_VSyncProviderStubControl._vSyncPr oviderAwaitVSyncResponseParamsFactory)); 291 impl.awaitVSync(callback);
292 return;
286 } 293 }
287 var params = new _VSyncProviderAwaitVSyncParams(); 294 var params = new _VSyncProviderAwaitVSyncParams();
288 return ctrl.sendMessageWithRequestId( 295 ctrl.sendMessageWithRequestId(
289 params, 296 params,
290 _vSyncProviderMethodAwaitVSyncName, 297 _vSyncProviderMethodAwaitVSyncName,
291 -1, 298 -1,
292 bindings.MessageHeader.kMessageExpectsResponse); 299 bindings.MessageHeader.kMessageExpectsResponse,
300 callback);
293 } 301 }
294 } 302 }
295 303
296 class _VSyncProviderStubControl 304 class _VSyncProviderStubControl
297 extends bindings.StubMessageHandler 305 extends bindings.StubMessageHandler
298 implements bindings.StubControl<VSyncProvider> { 306 implements bindings.StubControl<VSyncProvider> {
299 VSyncProvider _impl; 307 VSyncProvider _impl;
300 308
301 _VSyncProviderStubControl.fromEndpoint( 309 _VSyncProviderStubControl.fromEndpoint(
302 core.MojoMessagePipeEndpoint endpoint, [VSyncProvider impl]) 310 core.MojoMessagePipeEndpoint endpoint, [VSyncProvider impl])
303 : super.fromEndpoint(endpoint, autoBegin: impl != null) { 311 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
304 _impl = impl; 312 _impl = impl;
305 } 313 }
306 314
307 _VSyncProviderStubControl.fromHandle( 315 _VSyncProviderStubControl.fromHandle(
308 core.MojoHandle handle, [VSyncProvider impl]) 316 core.MojoHandle handle, [VSyncProvider impl])
309 : super.fromHandle(handle, autoBegin: impl != null) { 317 : super.fromHandle(handle, autoBegin: impl != null) {
310 _impl = impl; 318 _impl = impl;
311 } 319 }
312 320
313 _VSyncProviderStubControl.unbound([this._impl]) : super.unbound(); 321 _VSyncProviderStubControl.unbound([this._impl]) : super.unbound();
314 322
315 String get serviceName => VSyncProvider.serviceName; 323 String get serviceName => VSyncProvider.serviceName;
316 324
317 325
318 static VSyncProviderAwaitVSyncResponseParams _vSyncProviderAwaitVSyncResponseP aramsFactory(int timeStamp) { 326 Function _vSyncProviderAwaitVSyncResponseParamsResponder(
319 var result = new VSyncProviderAwaitVSyncResponseParams(); 327 int requestId) {
320 result.timeStamp = timeStamp; 328 return (int timeStamp) {
321 return result; 329 var result = new VSyncProviderAwaitVSyncResponseParams();
330 result.timeStamp = timeStamp;
331 sendResponse(buildResponseWithId(
332 result,
333 _vSyncProviderMethodAwaitVSyncName,
334 requestId,
335 bindings.MessageHeader.kMessageIsResponse));
336 };
322 } 337 }
323 338
324 dynamic handleMessage(bindings.ServiceMessage message) { 339 void handleMessage(bindings.ServiceMessage message) {
325 if (bindings.ControlMessageHandler.isControlMessage(message)) { 340 if (bindings.ControlMessageHandler.isControlMessage(message)) {
326 return bindings.ControlMessageHandler.handleMessage(this, 341 bindings.ControlMessageHandler.handleMessage(
327 0, 342 this, 0, message);
328 message); 343 return;
329 } 344 }
330 if (_impl == null) { 345 if (_impl == null) {
331 throw new core.MojoApiError("$this has no implementation set"); 346 throw new core.MojoApiError("$this has no implementation set");
332 } 347 }
333 switch (message.header.type) { 348 switch (message.header.type) {
334 case _vSyncProviderMethodAwaitVSyncName: 349 case _vSyncProviderMethodAwaitVSyncName:
335 var response = _impl.awaitVSync(_vSyncProviderAwaitVSyncResponseParamsFa ctory); 350 _impl.awaitVSync(_vSyncProviderAwaitVSyncResponseParamsResponder(message .header.requestId));
336 if (response is Future) {
337 return response.then((response) {
338 if (response != null) {
339 return buildResponseWithId(
340 response,
341 _vSyncProviderMethodAwaitVSyncName,
342 message.header.requestId,
343 bindings.MessageHeader.kMessageIsResponse);
344 }
345 });
346 } else if (response != null) {
347 return buildResponseWithId(
348 response,
349 _vSyncProviderMethodAwaitVSyncName,
350 message.header.requestId,
351 bindings.MessageHeader.kMessageIsResponse);
352 }
353 break; 351 break;
354 default: 352 default:
355 throw new bindings.MojoCodecError("Unexpected message name"); 353 throw new bindings.MojoCodecError("Unexpected message name");
356 break; 354 break;
357 } 355 }
358 return null;
359 } 356 }
360 357
361 VSyncProvider get impl => _impl; 358 VSyncProvider get impl => _impl;
362 set impl(VSyncProvider d) { 359 set impl(VSyncProvider d) {
363 if (d == null) { 360 if (d == null) {
364 throw new core.MojoApiError("$this: Cannot set a null implementation"); 361 throw new core.MojoApiError("$this: Cannot set a null implementation");
365 } 362 }
366 if (isBound && (_impl == null)) { 363 if (isBound && (_impl == null)) {
367 beginHandlingEvents(); 364 beginHandlingEvents();
368 } 365 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 core.MojoHandle handle, [VSyncProvider impl]) 399 core.MojoHandle handle, [VSyncProvider impl])
403 : super(new _VSyncProviderStubControl.fromHandle(handle, impl)); 400 : super(new _VSyncProviderStubControl.fromHandle(handle, impl));
404 401
405 static VSyncProviderStub newFromEndpoint( 402 static VSyncProviderStub newFromEndpoint(
406 core.MojoMessagePipeEndpoint endpoint) { 403 core.MojoMessagePipeEndpoint endpoint) {
407 assert(endpoint.setDescription("For VSyncProviderStub")); 404 assert(endpoint.setDescription("For VSyncProviderStub"));
408 return new VSyncProviderStub.fromEndpoint(endpoint); 405 return new VSyncProviderStub.fromEndpoint(endpoint);
409 } 406 }
410 407
411 408
412 dynamic awaitVSync([Function responseFactory = null]) { 409 void awaitVSync(void callback(int timeStamp)) {
413 return impl.awaitVSync(responseFactory); 410 return impl.awaitVSync(callback);
414 } 411 }
415 } 412 }
416 413
417 414
418 415
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698