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 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 Loading... |
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 Loading... |
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 | 209 |
199 factory IcuDataInterface.fromEndpoint( | 210 factory IcuDataInterface.fromEndpoint( |
200 core.MojoMessagePipeEndpoint endpoint, | 211 core.MojoMessagePipeEndpoint endpoint, |
(...skipping 29 matching lines...) Expand all Loading... |
230 | 241 |
231 void handleResponse(bindings.ServiceMessage message) { | 242 void handleResponse(bindings.ServiceMessage message) { |
232 switch (message.header.type) { | 243 switch (message.header.type) { |
233 case _icuDataMethodMapName: | 244 case _icuDataMethodMapName: |
234 var r = IcuDataMapResponseParams.deserialize( | 245 var r = IcuDataMapResponseParams.deserialize( |
235 message.payload); | 246 message.payload); |
236 if (!message.header.hasRequestId) { | 247 if (!message.header.hasRequestId) { |
237 proxyError("Expected a message with a valid request Id."); | 248 proxyError("Expected a message with a valid request Id."); |
238 return; | 249 return; |
239 } | 250 } |
240 Completer c = completerMap[message.header.requestId]; | 251 Function callback = callbackMap[message.header.requestId]; |
241 if (c == null) { | 252 if (callback == null) { |
242 proxyError( | 253 proxyError( |
243 "Message had unknown request Id: ${message.header.requestId}"); | 254 "Message had unknown request Id: ${message.header.requestId}"); |
244 return; | 255 return; |
245 } | 256 } |
246 completerMap.remove(message.header.requestId); | 257 callbackMap.remove(message.header.requestId); |
247 if (c.isCompleted) { | 258 callback(r.icuData ); |
248 proxyError("Response completer already completed"); | |
249 return; | |
250 } | |
251 c.complete(r); | |
252 break; | 259 break; |
253 default: | 260 default: |
254 proxyError("Unexpected message type: ${message.header.type}"); | 261 proxyError("Unexpected message type: ${message.header.type}"); |
255 close(immediate: true); | 262 close(immediate: true); |
256 break; | 263 break; |
257 } | 264 } |
258 } | 265 } |
259 | 266 |
260 @override | 267 @override |
261 String toString() { | 268 String toString() { |
(...skipping 24 matching lines...) Expand all Loading... |
286 return newMockedProxy; | 293 return newMockedProxy; |
287 } | 294 } |
288 | 295 |
289 static IcuDataProxy newFromEndpoint( | 296 static IcuDataProxy newFromEndpoint( |
290 core.MojoMessagePipeEndpoint endpoint) { | 297 core.MojoMessagePipeEndpoint endpoint) { |
291 assert(endpoint.setDescription("For IcuDataProxy")); | 298 assert(endpoint.setDescription("For IcuDataProxy")); |
292 return new IcuDataProxy.fromEndpoint(endpoint); | 299 return new IcuDataProxy.fromEndpoint(endpoint); |
293 } | 300 } |
294 | 301 |
295 | 302 |
296 dynamic map(String sha1hash,[Function responseFactory = null]) { | 303 void map(String sha1hash,void callback(core.MojoSharedBuffer icuData)) { |
297 if (impl != null) { | 304 if (impl != null) { |
298 return new Future(() => impl.map(sha1hash,_IcuDataStubControl._icuDataMapR
esponseParamsFactory)); | 305 impl.map(sha1hash,callback); |
| 306 return; |
299 } | 307 } |
300 var params = new _IcuDataMapParams(); | 308 var params = new _IcuDataMapParams(); |
301 params.sha1hash = sha1hash; | 309 params.sha1hash = sha1hash; |
302 return ctrl.sendMessageWithRequestId( | 310 ctrl.sendMessageWithRequestId( |
303 params, | 311 params, |
304 _icuDataMethodMapName, | 312 _icuDataMethodMapName, |
305 -1, | 313 -1, |
306 bindings.MessageHeader.kMessageExpectsResponse); | 314 bindings.MessageHeader.kMessageExpectsResponse, |
| 315 callback); |
307 } | 316 } |
308 } | 317 } |
309 | 318 |
310 class _IcuDataStubControl | 319 class _IcuDataStubControl |
311 extends bindings.StubMessageHandler | 320 extends bindings.StubMessageHandler |
312 implements bindings.StubControl<IcuData> { | 321 implements bindings.StubControl<IcuData> { |
313 IcuData _impl; | 322 IcuData _impl; |
314 | 323 |
315 _IcuDataStubControl.fromEndpoint( | 324 _IcuDataStubControl.fromEndpoint( |
316 core.MojoMessagePipeEndpoint endpoint, [IcuData impl]) | 325 core.MojoMessagePipeEndpoint endpoint, [IcuData impl]) |
317 : super.fromEndpoint(endpoint, autoBegin: impl != null) { | 326 : super.fromEndpoint(endpoint, autoBegin: impl != null) { |
318 _impl = impl; | 327 _impl = impl; |
319 } | 328 } |
320 | 329 |
321 _IcuDataStubControl.fromHandle( | 330 _IcuDataStubControl.fromHandle( |
322 core.MojoHandle handle, [IcuData impl]) | 331 core.MojoHandle handle, [IcuData impl]) |
323 : super.fromHandle(handle, autoBegin: impl != null) { | 332 : super.fromHandle(handle, autoBegin: impl != null) { |
324 _impl = impl; | 333 _impl = impl; |
325 } | 334 } |
326 | 335 |
327 _IcuDataStubControl.unbound([this._impl]) : super.unbound(); | 336 _IcuDataStubControl.unbound([this._impl]) : super.unbound(); |
328 | 337 |
329 String get serviceName => IcuData.serviceName; | 338 String get serviceName => IcuData.serviceName; |
330 | 339 |
331 | 340 |
332 static IcuDataMapResponseParams _icuDataMapResponseParamsFactory(core.MojoShar
edBuffer icuData) { | 341 Function _icuDataMapResponseParamsResponder( |
333 var result = new IcuDataMapResponseParams(); | 342 int requestId) { |
334 result.icuData = icuData; | 343 return (core.MojoSharedBuffer icuData) { |
335 return result; | 344 var result = new IcuDataMapResponseParams(); |
| 345 result.icuData = icuData; |
| 346 sendResponse(buildResponseWithId( |
| 347 result, |
| 348 _icuDataMethodMapName, |
| 349 requestId, |
| 350 bindings.MessageHeader.kMessageIsResponse)); |
| 351 }; |
336 } | 352 } |
337 | 353 |
338 dynamic handleMessage(bindings.ServiceMessage message) { | 354 void handleMessage(bindings.ServiceMessage message) { |
339 if (bindings.ControlMessageHandler.isControlMessage(message)) { | 355 if (bindings.ControlMessageHandler.isControlMessage(message)) { |
340 return bindings.ControlMessageHandler.handleMessage(this, | 356 bindings.ControlMessageHandler.handleMessage( |
341 0, | 357 this, 0, message); |
342 message); | 358 return; |
343 } | 359 } |
344 if (_impl == null) { | 360 if (_impl == null) { |
345 throw new core.MojoApiError("$this has no implementation set"); | 361 throw new core.MojoApiError("$this has no implementation set"); |
346 } | 362 } |
347 switch (message.header.type) { | 363 switch (message.header.type) { |
348 case _icuDataMethodMapName: | 364 case _icuDataMethodMapName: |
349 var params = _IcuDataMapParams.deserialize( | 365 var params = _IcuDataMapParams.deserialize( |
350 message.payload); | 366 message.payload); |
351 var response = _impl.map(params.sha1hash,_icuDataMapResponseParamsFactor
y); | 367 _impl.map(params.sha1hash, _icuDataMapResponseParamsResponder(message.he
ader.requestId)); |
352 if (response is Future) { | |
353 return response.then((response) { | |
354 if (response != null) { | |
355 return buildResponseWithId( | |
356 response, | |
357 _icuDataMethodMapName, | |
358 message.header.requestId, | |
359 bindings.MessageHeader.kMessageIsResponse); | |
360 } | |
361 }); | |
362 } else if (response != null) { | |
363 return buildResponseWithId( | |
364 response, | |
365 _icuDataMethodMapName, | |
366 message.header.requestId, | |
367 bindings.MessageHeader.kMessageIsResponse); | |
368 } | |
369 break; | 368 break; |
370 default: | 369 default: |
371 throw new bindings.MojoCodecError("Unexpected message name"); | 370 throw new bindings.MojoCodecError("Unexpected message name"); |
372 break; | 371 break; |
373 } | 372 } |
374 return null; | |
375 } | 373 } |
376 | 374 |
377 IcuData get impl => _impl; | 375 IcuData get impl => _impl; |
378 set impl(IcuData d) { | 376 set impl(IcuData d) { |
379 if (d == null) { | 377 if (d == null) { |
380 throw new core.MojoApiError("$this: Cannot set a null implementation"); | 378 throw new core.MojoApiError("$this: Cannot set a null implementation"); |
381 } | 379 } |
382 if (isBound && (_impl == null)) { | 380 if (isBound && (_impl == null)) { |
383 beginHandlingEvents(); | 381 beginHandlingEvents(); |
384 } | 382 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 core.MojoHandle handle, [IcuData impl]) | 416 core.MojoHandle handle, [IcuData impl]) |
419 : super(new _IcuDataStubControl.fromHandle(handle, impl)); | 417 : super(new _IcuDataStubControl.fromHandle(handle, impl)); |
420 | 418 |
421 static IcuDataStub newFromEndpoint( | 419 static IcuDataStub newFromEndpoint( |
422 core.MojoMessagePipeEndpoint endpoint) { | 420 core.MojoMessagePipeEndpoint endpoint) { |
423 assert(endpoint.setDescription("For IcuDataStub")); | 421 assert(endpoint.setDescription("For IcuDataStub")); |
424 return new IcuDataStub.fromEndpoint(endpoint); | 422 return new IcuDataStub.fromEndpoint(endpoint); |
425 } | 423 } |
426 | 424 |
427 | 425 |
428 dynamic map(String sha1hash,[Function responseFactory = null]) { | 426 void map(String sha1hash,void callback(core.MojoSharedBuffer icuData)) { |
429 return impl.map(sha1hash,responseFactory); | 427 return impl.map(sha1hash,callback); |
430 } | 428 } |
431 } | 429 } |
432 | 430 |
433 | 431 |
434 | 432 |
OLD | NEW |