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

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

Issue 2006093002: Dart: Futures -> Callbacks. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Move code from mojo_patch to proxy.dart Created 4 years, 7 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 icu_data_mojom; 5 library icu_data_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 _IcuDataMapParams extends bindings.Struct { 13 class _IcuDataMapParams extends bindings.Struct {
14 static const List<bindings.StructDataHeader> kVersions = const [ 14 static const List<bindings.StructDataHeader> kVersions = const [
15 const bindings.StructDataHeader(16, 0) 15 const bindings.StructDataHeader(16, 0)
16 ]; 16 ];
17 String sha1hash = null; 17 String sha1hash = null;
18 18
19 _IcuDataMapParams() : super(kVersions.last.size); 19 _IcuDataMapParams() : super(kVersions.last.size);
20 20
21 _IcuDataMapParams.init(
22 String this.sha1hash
23 ) : super(kVersions.last.size);
24
21 static _IcuDataMapParams deserialize(bindings.Message message) { 25 static _IcuDataMapParams deserialize(bindings.Message message) {
22 var decoder = new bindings.Decoder(message); 26 var decoder = new bindings.Decoder(message);
23 var result = decode(decoder); 27 var result = decode(decoder);
24 if (decoder.excessHandles != null) { 28 if (decoder.excessHandles != null) {
25 decoder.excessHandles.forEach((h) => h.close()); 29 decoder.excessHandles.forEach((h) => h.close());
26 } 30 }
27 return result; 31 return result;
28 } 32 }
29 33
30 static _IcuDataMapParams decode(bindings.Decoder decoder0) { 34 static _IcuDataMapParams decode(bindings.Decoder decoder0) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 87
84 88
85 class IcuDataMapResponseParams extends bindings.Struct { 89 class IcuDataMapResponseParams extends bindings.Struct {
86 static const List<bindings.StructDataHeader> kVersions = const [ 90 static const List<bindings.StructDataHeader> kVersions = const [
87 const bindings.StructDataHeader(16, 0) 91 const bindings.StructDataHeader(16, 0)
88 ]; 92 ];
89 core.MojoSharedBuffer icuData = null; 93 core.MojoSharedBuffer icuData = null;
90 94
91 IcuDataMapResponseParams() : super(kVersions.last.size); 95 IcuDataMapResponseParams() : super(kVersions.last.size);
92 96
97 IcuDataMapResponseParams.init(
98 core.MojoSharedBuffer this.icuData
99 ) : super(kVersions.last.size);
100
93 static IcuDataMapResponseParams deserialize(bindings.Message message) { 101 static IcuDataMapResponseParams deserialize(bindings.Message message) {
94 var decoder = new bindings.Decoder(message); 102 var decoder = new bindings.Decoder(message);
95 var result = decode(decoder); 103 var result = decode(decoder);
96 if (decoder.excessHandles != null) { 104 if (decoder.excessHandles != null) {
97 decoder.excessHandles.forEach((h) => h.close()); 105 decoder.excessHandles.forEach((h) => h.close());
98 } 106 }
99 return result; 107 return result;
100 } 108 }
101 109
102 static IcuDataMapResponseParams decode(bindings.Decoder decoder0) { 110 static IcuDataMapResponseParams decode(bindings.Decoder decoder0) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 156
149 Map toJson() { 157 Map toJson() {
150 throw new bindings.MojoCodecError( 158 throw new bindings.MojoCodecError(
151 'Object containing handles cannot be encoded to JSON.'); 159 'Object containing handles cannot be encoded to JSON.');
152 } 160 }
153 } 161 }
154 162
155 const int _icuDataMethodMapName = 0; 163 const int _icuDataMethodMapName = 0;
156 164
157 class _IcuDataServiceDescription implements service_describer.ServiceDescription { 165 class _IcuDataServiceDescription implements service_describer.ServiceDescription {
158 dynamic getTopLevelInterface([Function responseFactory]) => 166 void getTopLevelInterface(Function responder) {
159 responseFactory(null); 167 responder(null);
168 }
160 169
161 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => 170 void getTypeDefinition(String typeKey, Function responder) {
162 responseFactory(null); 171 responder(null);
172 }
163 173
164 dynamic getAllTypeDefinitions([Function responseFactory]) => 174 void getAllTypeDefinitions(Function responder) {
165 responseFactory(null); 175 responder(null);
176 }
166 } 177 }
167 178
168 abstract class IcuData { 179 abstract class IcuData {
169 static const String serviceName = "icu_data::ICUData"; 180 static const String serviceName = "icu_data::ICUData";
170 181
171 static service_describer.ServiceDescription _cachedServiceDescription; 182 static service_describer.ServiceDescription _cachedServiceDescription;
172 static service_describer.ServiceDescription get serviceDescription { 183 static service_describer.ServiceDescription get serviceDescription {
173 if (_cachedServiceDescription == null) { 184 if (_cachedServiceDescription == null) {
174 _cachedServiceDescription = new _IcuDataServiceDescription(); 185 _cachedServiceDescription = new _IcuDataServiceDescription();
175 } 186 }
176 return _cachedServiceDescription; 187 return _cachedServiceDescription;
177 } 188 }
178 189
179 static IcuDataProxy connectToService( 190 static IcuDataProxy connectToService(
180 bindings.ServiceConnector s, String url, [String serviceName]) { 191 bindings.ServiceConnector s, String url, [String serviceName]) {
181 IcuDataProxy p = new IcuDataProxy.unbound(); 192 IcuDataProxy p = new IcuDataProxy.unbound();
182 String name = serviceName ?? IcuData.serviceName; 193 String name = serviceName ?? IcuData.serviceName;
183 if ((name == null) || name.isEmpty) { 194 if ((name == null) || name.isEmpty) {
184 throw new core.MojoApiError( 195 throw new core.MojoApiError(
185 "If an interface has no ServiceName, then one must be provided."); 196 "If an interface has no ServiceName, then one must be provided.");
186 } 197 }
187 s.connectToService(url, p, name); 198 s.connectToService(url, p, name);
188 return p; 199 return p;
189 } 200 }
190 dynamic map(String sha1hash,[Function responseFactory = null]); 201 void map(String sha1hash,void callback(core.MojoSharedBuffer icuData));
191 } 202 }
192 203
193 abstract class IcuDataInterface 204 abstract class IcuDataInterface
194 implements bindings.MojoInterface<IcuData>, 205 implements bindings.MojoInterface<IcuData>,
195 IcuData { 206 IcuData {
196 factory IcuDataInterface([IcuData impl]) => 207 factory IcuDataInterface([IcuData impl]) =>
197 new IcuDataStub.unbound(impl); 208 new IcuDataStub.unbound(impl);
198 factory IcuDataInterface.fromEndpoint( 209 factory IcuDataInterface.fromEndpoint(
199 core.MojoMessagePipeEndpoint endpoint, 210 core.MojoMessagePipeEndpoint endpoint,
200 [IcuData impl]) => 211 [IcuData impl]) =>
(...skipping 22 matching lines...) Expand all
223 234
224 void handleResponse(bindings.ServiceMessage message) { 235 void handleResponse(bindings.ServiceMessage message) {
225 switch (message.header.type) { 236 switch (message.header.type) {
226 case _icuDataMethodMapName: 237 case _icuDataMethodMapName:
227 var r = IcuDataMapResponseParams.deserialize( 238 var r = IcuDataMapResponseParams.deserialize(
228 message.payload); 239 message.payload);
229 if (!message.header.hasRequestId) { 240 if (!message.header.hasRequestId) {
230 proxyError("Expected a message with a valid request Id."); 241 proxyError("Expected a message with a valid request Id.");
231 return; 242 return;
232 } 243 }
233 Completer c = completerMap[message.header.requestId]; 244 Function callback = callbackMap[message.header.requestId];
234 if (c == null) { 245 if (callback == null) {
235 proxyError( 246 proxyError(
236 "Message had unknown request Id: ${message.header.requestId}"); 247 "Message had unknown request Id: ${message.header.requestId}");
237 return; 248 return;
238 } 249 }
239 completerMap.remove(message.header.requestId); 250 callbackMap.remove(message.header.requestId);
240 if (c.isCompleted) { 251 callback(r.icuData );
241 proxyError("Response completer already completed");
242 return;
243 }
244 c.complete(r);
245 break; 252 break;
246 default: 253 default:
247 proxyError("Unexpected message type: ${message.header.type}"); 254 proxyError("Unexpected message type: ${message.header.type}");
248 close(immediate: true); 255 close(immediate: true);
249 break; 256 break;
250 } 257 }
251 } 258 }
252 259
253 IcuData get impl => null; 260 IcuData get impl => null;
254 set impl(IcuData _) { 261 set impl(IcuData _) {
(...skipping 22 matching lines...) Expand all
277 IcuDataProxy.unbound() 284 IcuDataProxy.unbound()
278 : super(new _IcuDataProxyControl.unbound()); 285 : super(new _IcuDataProxyControl.unbound());
279 286
280 static IcuDataProxy newFromEndpoint( 287 static IcuDataProxy newFromEndpoint(
281 core.MojoMessagePipeEndpoint endpoint) { 288 core.MojoMessagePipeEndpoint endpoint) {
282 assert(endpoint.setDescription("For IcuDataProxy")); 289 assert(endpoint.setDescription("For IcuDataProxy"));
283 return new IcuDataProxy.fromEndpoint(endpoint); 290 return new IcuDataProxy.fromEndpoint(endpoint);
284 } 291 }
285 292
286 293
287 dynamic map(String sha1hash,[Function responseFactory = null]) { 294 void map(String sha1hash,void callback(core.MojoSharedBuffer icuData)) {
288 var params = new _IcuDataMapParams(); 295 var params = new _IcuDataMapParams();
289 params.sha1hash = sha1hash; 296 params.sha1hash = sha1hash;
290 return ctrl.sendMessageWithRequestId( 297 ctrl.sendMessageWithRequestId(
291 params, 298 params,
292 _icuDataMethodMapName, 299 _icuDataMethodMapName,
293 -1, 300 -1,
294 bindings.MessageHeader.kMessageExpectsResponse); 301 bindings.MessageHeader.kMessageExpectsResponse,
302 callback);
295 } 303 }
296 } 304 }
297 305
298 class _IcuDataStubControl 306 class _IcuDataStubControl
299 extends bindings.StubMessageHandler 307 extends bindings.StubMessageHandler
300 implements bindings.StubControl<IcuData> { 308 implements bindings.StubControl<IcuData> {
301 IcuData _impl; 309 IcuData _impl;
302 310
303 _IcuDataStubControl.fromEndpoint( 311 _IcuDataStubControl.fromEndpoint(
304 core.MojoMessagePipeEndpoint endpoint, [IcuData impl]) 312 core.MojoMessagePipeEndpoint endpoint, [IcuData impl])
305 : super.fromEndpoint(endpoint, autoBegin: impl != null) { 313 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
306 _impl = impl; 314 _impl = impl;
307 } 315 }
308 316
309 _IcuDataStubControl.fromHandle( 317 _IcuDataStubControl.fromHandle(
310 core.MojoHandle handle, [IcuData impl]) 318 core.MojoHandle handle, [IcuData impl])
311 : super.fromHandle(handle, autoBegin: impl != null) { 319 : super.fromHandle(handle, autoBegin: impl != null) {
312 _impl = impl; 320 _impl = impl;
313 } 321 }
314 322
315 _IcuDataStubControl.unbound([this._impl]) : super.unbound(); 323 _IcuDataStubControl.unbound([this._impl]) : super.unbound();
316 324
317 String get serviceName => IcuData.serviceName; 325 String get serviceName => IcuData.serviceName;
318 326
319 327
320 IcuDataMapResponseParams _icuDataMapResponseParamsFactory(core.MojoSharedBuffe r icuData) { 328 Function _icuDataMapResponseParamsResponder(
321 var result = new IcuDataMapResponseParams(); 329 int requestId) {
322 result.icuData = icuData; 330 return (core.MojoSharedBuffer icuData) {
323 return result; 331 var result = new IcuDataMapResponseParams();
332 result.icuData = icuData;
333 sendResponse(buildResponseWithId(
334 result,
335 _icuDataMethodMapName,
336 requestId,
337 bindings.MessageHeader.kMessageIsResponse));
338 };
324 } 339 }
325 340
326 dynamic handleMessage(bindings.ServiceMessage message) { 341 void handleMessage(bindings.ServiceMessage message) {
327 if (bindings.ControlMessageHandler.isControlMessage(message)) { 342 if (bindings.ControlMessageHandler.isControlMessage(message)) {
328 return bindings.ControlMessageHandler.handleMessage(this, 343 bindings.ControlMessageHandler.handleMessage(
329 0, 344 this, 0, message);
330 message); 345 return;
331 } 346 }
332 if (_impl == null) { 347 if (_impl == null) {
333 throw new core.MojoApiError("$this has no implementation set"); 348 throw new core.MojoApiError("$this has no implementation set");
334 } 349 }
335 switch (message.header.type) { 350 switch (message.header.type) {
336 case _icuDataMethodMapName: 351 case _icuDataMethodMapName:
337 var params = _IcuDataMapParams.deserialize( 352 var params = _IcuDataMapParams.deserialize(
338 message.payload); 353 message.payload);
339 var response = _impl.map(params.sha1hash,_icuDataMapResponseParamsFactor y); 354 _impl.map(params.sha1hash, _icuDataMapResponseParamsResponder(message.he ader.requestId));
340 if (response is Future) {
341 return response.then((response) {
342 if (response != null) {
343 return buildResponseWithId(
344 response,
345 _icuDataMethodMapName,
346 message.header.requestId,
347 bindings.MessageHeader.kMessageIsResponse);
348 }
349 });
350 } else if (response != null) {
351 return buildResponseWithId(
352 response,
353 _icuDataMethodMapName,
354 message.header.requestId,
355 bindings.MessageHeader.kMessageIsResponse);
356 }
357 break; 355 break;
358 default: 356 default:
359 throw new bindings.MojoCodecError("Unexpected message name"); 357 throw new bindings.MojoCodecError("Unexpected message name");
360 break; 358 break;
361 } 359 }
362 return null;
363 } 360 }
364 361
365 IcuData get impl => _impl; 362 IcuData get impl => _impl;
366 set impl(IcuData d) { 363 set impl(IcuData d) {
367 if (d == null) { 364 if (d == null) {
368 throw new core.MojoApiError("$this: Cannot set a null implementation"); 365 throw new core.MojoApiError("$this: Cannot set a null implementation");
369 } 366 }
370 if (isBound && (_impl == null)) { 367 if (isBound && (_impl == null)) {
371 beginHandlingEvents(); 368 beginHandlingEvents();
372 } 369 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 core.MojoHandle handle, [IcuData impl]) 403 core.MojoHandle handle, [IcuData impl])
407 : super(new _IcuDataStubControl.fromHandle(handle, impl)); 404 : super(new _IcuDataStubControl.fromHandle(handle, impl));
408 405
409 static IcuDataStub newFromEndpoint( 406 static IcuDataStub newFromEndpoint(
410 core.MojoMessagePipeEndpoint endpoint) { 407 core.MojoMessagePipeEndpoint endpoint) {
411 assert(endpoint.setDescription("For IcuDataStub")); 408 assert(endpoint.setDescription("For IcuDataStub"));
412 return new IcuDataStub.fromEndpoint(endpoint); 409 return new IcuDataStub.fromEndpoint(endpoint);
413 } 410 }
414 411
415 412
416 dynamic map(String sha1hash,[Function responseFactory = null]) { 413 void map(String sha1hash,void callback(core.MojoSharedBuffer icuData)) {
417 return impl.map(sha1hash,responseFactory); 414 return impl.map(sha1hash,callback);
418 } 415 }
419 } 416 }
420 417
421 418
422 419
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698