OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 library prediction_mojom; |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:mojo/bindings.dart' as bindings; |
| 10 import 'package:mojo/core.dart' as core; |
| 11 |
| 12 |
| 13 |
| 14 class PrevWordInfo extends bindings.Struct { |
| 15 static const List<bindings.StructDataHeader> kVersions = const [ |
| 16 const bindings.StructDataHeader(24, 0) |
| 17 ]; |
| 18 String word = null; |
| 19 bool isBeginningOfSentence = false; |
| 20 |
| 21 PrevWordInfo() : super(kVersions.last.size); |
| 22 |
| 23 static PrevWordInfo deserialize(bindings.Message message) { |
| 24 var decoder = new bindings.Decoder(message); |
| 25 var result = decode(decoder); |
| 26 if (decoder.excessHandles != null) { |
| 27 decoder.excessHandles.forEach((h) => h.close()); |
| 28 } |
| 29 return result; |
| 30 } |
| 31 |
| 32 static PrevWordInfo decode(bindings.Decoder decoder0) { |
| 33 if (decoder0 == null) { |
| 34 return null; |
| 35 } |
| 36 PrevWordInfo result = new PrevWordInfo(); |
| 37 |
| 38 var mainDataHeader = decoder0.decodeStructDataHeader(); |
| 39 if (mainDataHeader.version <= kVersions.last.version) { |
| 40 // Scan in reverse order to optimize for more recent versions. |
| 41 for (int i = kVersions.length - 1; i >= 0; --i) { |
| 42 if (mainDataHeader.version >= kVersions[i].version) { |
| 43 if (mainDataHeader.size == kVersions[i].size) { |
| 44 // Found a match. |
| 45 break; |
| 46 } |
| 47 throw new bindings.MojoCodecError( |
| 48 'Header size doesn\'t correspond to known version size.'); |
| 49 } |
| 50 } |
| 51 } else if (mainDataHeader.size < kVersions.last.size) { |
| 52 throw new bindings.MojoCodecError( |
| 53 'Message newer than the last known version cannot be shorter than ' |
| 54 'required by the last known version.'); |
| 55 } |
| 56 if (mainDataHeader.version >= 0) { |
| 57 |
| 58 result.word = decoder0.decodeString(8, false); |
| 59 } |
| 60 if (mainDataHeader.version >= 0) { |
| 61 |
| 62 result.isBeginningOfSentence = decoder0.decodeBool(16, 0); |
| 63 } |
| 64 return result; |
| 65 } |
| 66 |
| 67 void encode(bindings.Encoder encoder) { |
| 68 var encoder0 = encoder.getStructEncoderAtOffset(kVersions.last); |
| 69 |
| 70 encoder0.encodeString(word, 8, false); |
| 71 |
| 72 encoder0.encodeBool(isBeginningOfSentence, 16, 0); |
| 73 } |
| 74 |
| 75 String toString() { |
| 76 return "PrevWordInfo(" |
| 77 "word: $word" ", " |
| 78 "isBeginningOfSentence: $isBeginningOfSentence" ")"; |
| 79 } |
| 80 |
| 81 Map toJson() { |
| 82 Map map = new Map(); |
| 83 map["word"] = word; |
| 84 map["isBeginningOfSentence"] = isBeginningOfSentence; |
| 85 return map; |
| 86 } |
| 87 } |
| 88 |
| 89 |
| 90 class PredictionInfo extends bindings.Struct { |
| 91 static const List<bindings.StructDataHeader> kVersions = const [ |
| 92 const bindings.StructDataHeader(24, 0) |
| 93 ]; |
| 94 List<PrevWordInfo> previousWords = null; |
| 95 String currentWord = null; |
| 96 |
| 97 PredictionInfo() : super(kVersions.last.size); |
| 98 |
| 99 static PredictionInfo deserialize(bindings.Message message) { |
| 100 var decoder = new bindings.Decoder(message); |
| 101 var result = decode(decoder); |
| 102 if (decoder.excessHandles != null) { |
| 103 decoder.excessHandles.forEach((h) => h.close()); |
| 104 } |
| 105 return result; |
| 106 } |
| 107 |
| 108 static PredictionInfo decode(bindings.Decoder decoder0) { |
| 109 if (decoder0 == null) { |
| 110 return null; |
| 111 } |
| 112 PredictionInfo result = new PredictionInfo(); |
| 113 |
| 114 var mainDataHeader = decoder0.decodeStructDataHeader(); |
| 115 if (mainDataHeader.version <= kVersions.last.version) { |
| 116 // Scan in reverse order to optimize for more recent versions. |
| 117 for (int i = kVersions.length - 1; i >= 0; --i) { |
| 118 if (mainDataHeader.version >= kVersions[i].version) { |
| 119 if (mainDataHeader.size == kVersions[i].size) { |
| 120 // Found a match. |
| 121 break; |
| 122 } |
| 123 throw new bindings.MojoCodecError( |
| 124 'Header size doesn\'t correspond to known version size.'); |
| 125 } |
| 126 } |
| 127 } else if (mainDataHeader.size < kVersions.last.size) { |
| 128 throw new bindings.MojoCodecError( |
| 129 'Message newer than the last known version cannot be shorter than ' |
| 130 'required by the last known version.'); |
| 131 } |
| 132 if (mainDataHeader.version >= 0) { |
| 133 |
| 134 var decoder1 = decoder0.decodePointer(8, false); |
| 135 { |
| 136 var si1 = decoder1.decodeDataHeaderForPointerArray(bindings.kUnspecified
ArrayLength); |
| 137 result.previousWords = new List<PrevWordInfo>(si1.numElements); |
| 138 for (int i1 = 0; i1 < si1.numElements; ++i1) { |
| 139 |
| 140 var decoder2 = decoder1.decodePointer(bindings.ArrayDataHeader.kHeader
Size + bindings.kPointerSize * i1, false); |
| 141 result.previousWords[i1] = PrevWordInfo.decode(decoder2); |
| 142 } |
| 143 } |
| 144 } |
| 145 if (mainDataHeader.version >= 0) { |
| 146 |
| 147 result.currentWord = decoder0.decodeString(16, false); |
| 148 } |
| 149 return result; |
| 150 } |
| 151 |
| 152 void encode(bindings.Encoder encoder) { |
| 153 var encoder0 = encoder.getStructEncoderAtOffset(kVersions.last); |
| 154 |
| 155 if (previousWords == null) { |
| 156 encoder0.encodeNullPointer(8, false); |
| 157 } else { |
| 158 var encoder1 = encoder0.encodePointerArray(previousWords.length, 8, bindin
gs.kUnspecifiedArrayLength); |
| 159 for (int i0 = 0; i0 < previousWords.length; ++i0) { |
| 160 |
| 161 encoder1.encodeStruct(previousWords[i0], bindings.ArrayDataHeader.kHeade
rSize + bindings.kPointerSize * i0, false); |
| 162 } |
| 163 } |
| 164 |
| 165 encoder0.encodeString(currentWord, 16, false); |
| 166 } |
| 167 |
| 168 String toString() { |
| 169 return "PredictionInfo(" |
| 170 "previousWords: $previousWords" ", " |
| 171 "currentWord: $currentWord" ")"; |
| 172 } |
| 173 |
| 174 Map toJson() { |
| 175 Map map = new Map(); |
| 176 map["previousWords"] = previousWords; |
| 177 map["currentWord"] = currentWord; |
| 178 return map; |
| 179 } |
| 180 } |
| 181 |
| 182 |
| 183 class PredictionServiceGetPredictionListParams extends bindings.Struct { |
| 184 static const List<bindings.StructDataHeader> kVersions = const [ |
| 185 const bindings.StructDataHeader(16, 0) |
| 186 ]; |
| 187 PredictionInfo predictionInfo = null; |
| 188 |
| 189 PredictionServiceGetPredictionListParams() : super(kVersions.last.size); |
| 190 |
| 191 static PredictionServiceGetPredictionListParams deserialize(bindings.Message m
essage) { |
| 192 var decoder = new bindings.Decoder(message); |
| 193 var result = decode(decoder); |
| 194 if (decoder.excessHandles != null) { |
| 195 decoder.excessHandles.forEach((h) => h.close()); |
| 196 } |
| 197 return result; |
| 198 } |
| 199 |
| 200 static PredictionServiceGetPredictionListParams decode(bindings.Decoder decode
r0) { |
| 201 if (decoder0 == null) { |
| 202 return null; |
| 203 } |
| 204 PredictionServiceGetPredictionListParams result = new PredictionServiceGetPr
edictionListParams(); |
| 205 |
| 206 var mainDataHeader = decoder0.decodeStructDataHeader(); |
| 207 if (mainDataHeader.version <= kVersions.last.version) { |
| 208 // Scan in reverse order to optimize for more recent versions. |
| 209 for (int i = kVersions.length - 1; i >= 0; --i) { |
| 210 if (mainDataHeader.version >= kVersions[i].version) { |
| 211 if (mainDataHeader.size == kVersions[i].size) { |
| 212 // Found a match. |
| 213 break; |
| 214 } |
| 215 throw new bindings.MojoCodecError( |
| 216 'Header size doesn\'t correspond to known version size.'); |
| 217 } |
| 218 } |
| 219 } else if (mainDataHeader.size < kVersions.last.size) { |
| 220 throw new bindings.MojoCodecError( |
| 221 'Message newer than the last known version cannot be shorter than ' |
| 222 'required by the last known version.'); |
| 223 } |
| 224 if (mainDataHeader.version >= 0) { |
| 225 |
| 226 var decoder1 = decoder0.decodePointer(8, false); |
| 227 result.predictionInfo = PredictionInfo.decode(decoder1); |
| 228 } |
| 229 return result; |
| 230 } |
| 231 |
| 232 void encode(bindings.Encoder encoder) { |
| 233 var encoder0 = encoder.getStructEncoderAtOffset(kVersions.last); |
| 234 |
| 235 encoder0.encodeStruct(predictionInfo, 8, false); |
| 236 } |
| 237 |
| 238 String toString() { |
| 239 return "PredictionServiceGetPredictionListParams(" |
| 240 "predictionInfo: $predictionInfo" ")"; |
| 241 } |
| 242 |
| 243 Map toJson() { |
| 244 Map map = new Map(); |
| 245 map["predictionInfo"] = predictionInfo; |
| 246 return map; |
| 247 } |
| 248 } |
| 249 |
| 250 |
| 251 class PredictionServiceGetPredictionListResponseParams extends bindings.Struct { |
| 252 static const List<bindings.StructDataHeader> kVersions = const [ |
| 253 const bindings.StructDataHeader(16, 0) |
| 254 ]; |
| 255 List<String> predictionList = null; |
| 256 |
| 257 PredictionServiceGetPredictionListResponseParams() : super(kVersions.last.size
); |
| 258 |
| 259 static PredictionServiceGetPredictionListResponseParams deserialize(bindings.M
essage message) { |
| 260 var decoder = new bindings.Decoder(message); |
| 261 var result = decode(decoder); |
| 262 if (decoder.excessHandles != null) { |
| 263 decoder.excessHandles.forEach((h) => h.close()); |
| 264 } |
| 265 return result; |
| 266 } |
| 267 |
| 268 static PredictionServiceGetPredictionListResponseParams decode(bindings.Decode
r decoder0) { |
| 269 if (decoder0 == null) { |
| 270 return null; |
| 271 } |
| 272 PredictionServiceGetPredictionListResponseParams result = new PredictionServ
iceGetPredictionListResponseParams(); |
| 273 |
| 274 var mainDataHeader = decoder0.decodeStructDataHeader(); |
| 275 if (mainDataHeader.version <= kVersions.last.version) { |
| 276 // Scan in reverse order to optimize for more recent versions. |
| 277 for (int i = kVersions.length - 1; i >= 0; --i) { |
| 278 if (mainDataHeader.version >= kVersions[i].version) { |
| 279 if (mainDataHeader.size == kVersions[i].size) { |
| 280 // Found a match. |
| 281 break; |
| 282 } |
| 283 throw new bindings.MojoCodecError( |
| 284 'Header size doesn\'t correspond to known version size.'); |
| 285 } |
| 286 } |
| 287 } else if (mainDataHeader.size < kVersions.last.size) { |
| 288 throw new bindings.MojoCodecError( |
| 289 'Message newer than the last known version cannot be shorter than ' |
| 290 'required by the last known version.'); |
| 291 } |
| 292 if (mainDataHeader.version >= 0) { |
| 293 |
| 294 var decoder1 = decoder0.decodePointer(8, true); |
| 295 if (decoder1 == null) { |
| 296 result.predictionList = null; |
| 297 } else { |
| 298 var si1 = decoder1.decodeDataHeaderForPointerArray(bindings.kUnspecified
ArrayLength); |
| 299 result.predictionList = new List<String>(si1.numElements); |
| 300 for (int i1 = 0; i1 < si1.numElements; ++i1) { |
| 301 |
| 302 result.predictionList[i1] = decoder1.decodeString(bindings.ArrayDataHe
ader.kHeaderSize + bindings.kPointerSize * i1, false); |
| 303 } |
| 304 } |
| 305 } |
| 306 return result; |
| 307 } |
| 308 |
| 309 void encode(bindings.Encoder encoder) { |
| 310 var encoder0 = encoder.getStructEncoderAtOffset(kVersions.last); |
| 311 |
| 312 if (predictionList == null) { |
| 313 encoder0.encodeNullPointer(8, true); |
| 314 } else { |
| 315 var encoder1 = encoder0.encodePointerArray(predictionList.length, 8, bindi
ngs.kUnspecifiedArrayLength); |
| 316 for (int i0 = 0; i0 < predictionList.length; ++i0) { |
| 317 |
| 318 encoder1.encodeString(predictionList[i0], bindings.ArrayDataHeader.kHead
erSize + bindings.kPointerSize * i0, false); |
| 319 } |
| 320 } |
| 321 } |
| 322 |
| 323 String toString() { |
| 324 return "PredictionServiceGetPredictionListResponseParams(" |
| 325 "predictionList: $predictionList" ")"; |
| 326 } |
| 327 |
| 328 Map toJson() { |
| 329 Map map = new Map(); |
| 330 map["predictionList"] = predictionList; |
| 331 return map; |
| 332 } |
| 333 } |
| 334 |
| 335 const int kPredictionService_getPredictionList_name = 0; |
| 336 |
| 337 const String PredictionServiceName = |
| 338 'prediction::PredictionService'; |
| 339 |
| 340 abstract class PredictionService { |
| 341 dynamic getPredictionList(PredictionInfo predictionInfo,[Function responseFact
ory = null]); |
| 342 |
| 343 } |
| 344 |
| 345 |
| 346 class PredictionServiceProxyImpl extends bindings.Proxy { |
| 347 PredictionServiceProxyImpl.fromEndpoint( |
| 348 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); |
| 349 |
| 350 PredictionServiceProxyImpl.fromHandle(core.MojoHandle handle) : |
| 351 super.fromHandle(handle); |
| 352 |
| 353 PredictionServiceProxyImpl.unbound() : super.unbound(); |
| 354 |
| 355 static PredictionServiceProxyImpl newFromEndpoint( |
| 356 core.MojoMessagePipeEndpoint endpoint) { |
| 357 assert(endpoint.setDescription("For PredictionServiceProxyImpl")); |
| 358 return new PredictionServiceProxyImpl.fromEndpoint(endpoint); |
| 359 } |
| 360 |
| 361 String get name => PredictionServiceName; |
| 362 |
| 363 void handleResponse(bindings.ServiceMessage message) { |
| 364 switch (message.header.type) { |
| 365 case kPredictionService_getPredictionList_name: |
| 366 var r = PredictionServiceGetPredictionListResponseParams.deserialize( |
| 367 message.payload); |
| 368 if (!message.header.hasRequestId) { |
| 369 proxyError("Expected a message with a valid request Id."); |
| 370 return; |
| 371 } |
| 372 Completer c = completerMap[message.header.requestId]; |
| 373 if (c == null) { |
| 374 proxyError( |
| 375 "Message had unknown request Id: ${message.header.requestId}"); |
| 376 return; |
| 377 } |
| 378 completerMap.remove(message.header.requestId); |
| 379 if (c.isCompleted) { |
| 380 proxyError("Response completer already completed"); |
| 381 return; |
| 382 } |
| 383 c.complete(r); |
| 384 break; |
| 385 default: |
| 386 proxyError("Unexpected message type: ${message.header.type}"); |
| 387 close(immediate: true); |
| 388 break; |
| 389 } |
| 390 } |
| 391 |
| 392 String toString() { |
| 393 var superString = super.toString(); |
| 394 return "PredictionServiceProxyImpl($superString)"; |
| 395 } |
| 396 } |
| 397 |
| 398 |
| 399 class _PredictionServiceProxyCalls implements PredictionService { |
| 400 PredictionServiceProxyImpl _proxyImpl; |
| 401 |
| 402 _PredictionServiceProxyCalls(this._proxyImpl); |
| 403 dynamic getPredictionList(PredictionInfo predictionInfo,[Function responseFa
ctory = null]) { |
| 404 var params = new PredictionServiceGetPredictionListParams(); |
| 405 params.predictionInfo = predictionInfo; |
| 406 return _proxyImpl.sendMessageWithRequestId( |
| 407 params, |
| 408 kPredictionService_getPredictionList_name, |
| 409 -1, |
| 410 bindings.MessageHeader.kMessageExpectsResponse); |
| 411 } |
| 412 } |
| 413 |
| 414 |
| 415 class PredictionServiceProxy implements bindings.ProxyBase { |
| 416 final bindings.Proxy impl; |
| 417 PredictionService ptr; |
| 418 final String name = PredictionServiceName; |
| 419 |
| 420 PredictionServiceProxy(PredictionServiceProxyImpl proxyImpl) : |
| 421 impl = proxyImpl, |
| 422 ptr = new _PredictionServiceProxyCalls(proxyImpl); |
| 423 |
| 424 PredictionServiceProxy.fromEndpoint( |
| 425 core.MojoMessagePipeEndpoint endpoint) : |
| 426 impl = new PredictionServiceProxyImpl.fromEndpoint(endpoint) { |
| 427 ptr = new _PredictionServiceProxyCalls(impl); |
| 428 } |
| 429 |
| 430 PredictionServiceProxy.fromHandle(core.MojoHandle handle) : |
| 431 impl = new PredictionServiceProxyImpl.fromHandle(handle) { |
| 432 ptr = new _PredictionServiceProxyCalls(impl); |
| 433 } |
| 434 |
| 435 PredictionServiceProxy.unbound() : |
| 436 impl = new PredictionServiceProxyImpl.unbound() { |
| 437 ptr = new _PredictionServiceProxyCalls(impl); |
| 438 } |
| 439 |
| 440 factory PredictionServiceProxy.connectToService( |
| 441 bindings.ServiceConnector s, String url) { |
| 442 PredictionServiceProxy p = new PredictionServiceProxy.unbound(); |
| 443 s.connectToService(url, p); |
| 444 return p; |
| 445 } |
| 446 |
| 447 static PredictionServiceProxy newFromEndpoint( |
| 448 core.MojoMessagePipeEndpoint endpoint) { |
| 449 assert(endpoint.setDescription("For PredictionServiceProxy")); |
| 450 return new PredictionServiceProxy.fromEndpoint(endpoint); |
| 451 } |
| 452 |
| 453 Future close({bool immediate: false}) => impl.close(immediate: immediate); |
| 454 |
| 455 Future responseOrError(Future f) => impl.responseOrError(f); |
| 456 |
| 457 Future get errorFuture => impl.errorFuture; |
| 458 |
| 459 int get version => impl.version; |
| 460 |
| 461 Future<int> queryVersion() => impl.queryVersion(); |
| 462 |
| 463 void requireVersion(int requiredVersion) { |
| 464 impl.requireVersion(requiredVersion); |
| 465 } |
| 466 |
| 467 String toString() { |
| 468 return "PredictionServiceProxy($impl)"; |
| 469 } |
| 470 } |
| 471 |
| 472 |
| 473 class PredictionServiceStub extends bindings.Stub { |
| 474 PredictionService _impl = null; |
| 475 |
| 476 PredictionServiceStub.fromEndpoint( |
| 477 core.MojoMessagePipeEndpoint endpoint, [this._impl]) |
| 478 : super.fromEndpoint(endpoint); |
| 479 |
| 480 PredictionServiceStub.fromHandle(core.MojoHandle handle, [this._impl]) |
| 481 : super.fromHandle(handle); |
| 482 |
| 483 PredictionServiceStub.unbound() : super.unbound(); |
| 484 |
| 485 static PredictionServiceStub newFromEndpoint( |
| 486 core.MojoMessagePipeEndpoint endpoint) { |
| 487 assert(endpoint.setDescription("For PredictionServiceStub")); |
| 488 return new PredictionServiceStub.fromEndpoint(endpoint); |
| 489 } |
| 490 |
| 491 static const String name = PredictionServiceName; |
| 492 |
| 493 |
| 494 PredictionServiceGetPredictionListResponseParams _PredictionServiceGetPredicti
onListResponseParamsFactory(List<String> predictionList) { |
| 495 var result = new PredictionServiceGetPredictionListResponseParams(); |
| 496 result.predictionList = predictionList; |
| 497 return result; |
| 498 } |
| 499 |
| 500 dynamic handleMessage(bindings.ServiceMessage message) { |
| 501 if (bindings.ControlMessageHandler.isControlMessage(message)) { |
| 502 return bindings.ControlMessageHandler.handleMessage(this, |
| 503 0, |
| 504 message); |
| 505 } |
| 506 assert(_impl != null); |
| 507 switch (message.header.type) { |
| 508 case kPredictionService_getPredictionList_name: |
| 509 var params = PredictionServiceGetPredictionListParams.deserialize( |
| 510 message.payload); |
| 511 var response = _impl.getPredictionList(params.predictionInfo,_Prediction
ServiceGetPredictionListResponseParamsFactory); |
| 512 if (response is Future) { |
| 513 return response.then((response) { |
| 514 if (response != null) { |
| 515 return buildResponseWithId( |
| 516 response, |
| 517 kPredictionService_getPredictionList_name, |
| 518 message.header.requestId, |
| 519 bindings.MessageHeader.kMessageIsResponse); |
| 520 } |
| 521 }); |
| 522 } else if (response != null) { |
| 523 return buildResponseWithId( |
| 524 response, |
| 525 kPredictionService_getPredictionList_name, |
| 526 message.header.requestId, |
| 527 bindings.MessageHeader.kMessageIsResponse); |
| 528 } |
| 529 break; |
| 530 default: |
| 531 throw new bindings.MojoCodecError("Unexpected message name"); |
| 532 break; |
| 533 } |
| 534 return null; |
| 535 } |
| 536 |
| 537 PredictionService get impl => _impl; |
| 538 set impl(PredictionService d) { |
| 539 assert(_impl == null); |
| 540 _impl = d; |
| 541 } |
| 542 |
| 543 String toString() { |
| 544 var superString = super.toString(); |
| 545 return "PredictionServiceStub($superString)"; |
| 546 } |
| 547 |
| 548 int get version => 0; |
| 549 } |
| 550 |
| 551 |
OLD | NEW |