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 service_registry_mojom; |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:mojo/bindings.dart' as bindings; |
| 10 import 'package:mojo/core.dart' as core; |
| 11 import 'package:mojo/mojo/service_provider.mojom.dart' as service_provider_mojom
; |
| 12 |
| 13 |
| 14 |
| 15 class ServiceRegistryAddServicesParams extends bindings.Struct { |
| 16 static const List<bindings.StructDataHeader> kVersions = const [ |
| 17 const bindings.StructDataHeader(24, 0) |
| 18 ]; |
| 19 List<String> interfaceNames = null; |
| 20 Object serviceProvider = null; |
| 21 |
| 22 ServiceRegistryAddServicesParams() : super(kVersions.last.size); |
| 23 |
| 24 static ServiceRegistryAddServicesParams deserialize(bindings.Message message)
{ |
| 25 var decoder = new bindings.Decoder(message); |
| 26 var result = decode(decoder); |
| 27 if (decoder.excessHandles != null) { |
| 28 decoder.excessHandles.forEach((h) => h.close()); |
| 29 } |
| 30 return result; |
| 31 } |
| 32 |
| 33 static ServiceRegistryAddServicesParams decode(bindings.Decoder decoder0) { |
| 34 if (decoder0 == null) { |
| 35 return null; |
| 36 } |
| 37 ServiceRegistryAddServicesParams result = new ServiceRegistryAddServicesPara
ms(); |
| 38 |
| 39 var mainDataHeader = decoder0.decodeStructDataHeader(); |
| 40 if (mainDataHeader.version <= kVersions.last.version) { |
| 41 // Scan in reverse order to optimize for more recent versions. |
| 42 for (int i = kVersions.length - 1; i >= 0; --i) { |
| 43 if (mainDataHeader.version >= kVersions[i].version) { |
| 44 if (mainDataHeader.size == kVersions[i].size) { |
| 45 // Found a match. |
| 46 break; |
| 47 } |
| 48 throw new bindings.MojoCodecError( |
| 49 'Header size doesn\'t correspond to known version size.'); |
| 50 } |
| 51 } |
| 52 } else if (mainDataHeader.size < kVersions.last.size) { |
| 53 throw new bindings.MojoCodecError( |
| 54 'Message newer than the last known version cannot be shorter than ' |
| 55 'required by the last known version.'); |
| 56 } |
| 57 if (mainDataHeader.version >= 0) { |
| 58 |
| 59 var decoder1 = decoder0.decodePointer(8, false); |
| 60 { |
| 61 var si1 = decoder1.decodeDataHeaderForPointerArray(bindings.kUnspecified
ArrayLength); |
| 62 result.interfaceNames = new List<String>(si1.numElements); |
| 63 for (int i1 = 0; i1 < si1.numElements; ++i1) { |
| 64 |
| 65 result.interfaceNames[i1] = decoder1.decodeString(bindings.ArrayDataHe
ader.kHeaderSize + bindings.kPointerSize * i1, false); |
| 66 } |
| 67 } |
| 68 } |
| 69 if (mainDataHeader.version >= 0) { |
| 70 |
| 71 result.serviceProvider = decoder0.decodeServiceInterface(16, false, servic
e_provider_mojom.ServiceProviderProxy.newFromEndpoint); |
| 72 } |
| 73 return result; |
| 74 } |
| 75 |
| 76 void encode(bindings.Encoder encoder) { |
| 77 var encoder0 = encoder.getStructEncoderAtOffset(kVersions.last); |
| 78 |
| 79 if (interfaceNames == null) { |
| 80 encoder0.encodeNullPointer(8, false); |
| 81 } else { |
| 82 var encoder1 = encoder0.encodePointerArray(interfaceNames.length, 8, bindi
ngs.kUnspecifiedArrayLength); |
| 83 for (int i0 = 0; i0 < interfaceNames.length; ++i0) { |
| 84 |
| 85 encoder1.encodeString(interfaceNames[i0], bindings.ArrayDataHeader.kHead
erSize + bindings.kPointerSize * i0, false); |
| 86 } |
| 87 } |
| 88 |
| 89 encoder0.encodeInterface(serviceProvider, 16, false); |
| 90 } |
| 91 |
| 92 String toString() { |
| 93 return "ServiceRegistryAddServicesParams(" |
| 94 "interfaceNames: $interfaceNames" ", " |
| 95 "serviceProvider: $serviceProvider" ")"; |
| 96 } |
| 97 |
| 98 Map toJson() { |
| 99 throw new bindings.MojoCodecError( |
| 100 'Object containing handles cannot be encoded to JSON.'); |
| 101 } |
| 102 } |
| 103 |
| 104 const int kServiceRegistry_addServices_name = 0; |
| 105 |
| 106 const String ServiceRegistryName = |
| 107 'mojo::ServiceRegistry'; |
| 108 |
| 109 abstract class ServiceRegistry { |
| 110 void addServices(List<String> interfaceNames, Object serviceProvider); |
| 111 |
| 112 } |
| 113 |
| 114 |
| 115 class ServiceRegistryProxyImpl extends bindings.Proxy { |
| 116 ServiceRegistryProxyImpl.fromEndpoint( |
| 117 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); |
| 118 |
| 119 ServiceRegistryProxyImpl.fromHandle(core.MojoHandle handle) : |
| 120 super.fromHandle(handle); |
| 121 |
| 122 ServiceRegistryProxyImpl.unbound() : super.unbound(); |
| 123 |
| 124 static ServiceRegistryProxyImpl newFromEndpoint( |
| 125 core.MojoMessagePipeEndpoint endpoint) { |
| 126 assert(endpoint.setDescription("For ServiceRegistryProxyImpl")); |
| 127 return new ServiceRegistryProxyImpl.fromEndpoint(endpoint); |
| 128 } |
| 129 |
| 130 String get name => ServiceRegistryName; |
| 131 |
| 132 void handleResponse(bindings.ServiceMessage message) { |
| 133 switch (message.header.type) { |
| 134 default: |
| 135 proxyError("Unexpected message type: ${message.header.type}"); |
| 136 close(immediate: true); |
| 137 break; |
| 138 } |
| 139 } |
| 140 |
| 141 String toString() { |
| 142 var superString = super.toString(); |
| 143 return "ServiceRegistryProxyImpl($superString)"; |
| 144 } |
| 145 } |
| 146 |
| 147 |
| 148 class _ServiceRegistryProxyCalls implements ServiceRegistry { |
| 149 ServiceRegistryProxyImpl _proxyImpl; |
| 150 |
| 151 _ServiceRegistryProxyCalls(this._proxyImpl); |
| 152 void addServices(List<String> interfaceNames, Object serviceProvider) { |
| 153 if (!_proxyImpl.isBound) { |
| 154 _proxyImpl.proxyError("The Proxy is closed."); |
| 155 return; |
| 156 } |
| 157 var params = new ServiceRegistryAddServicesParams(); |
| 158 params.interfaceNames = interfaceNames; |
| 159 params.serviceProvider = serviceProvider; |
| 160 _proxyImpl.sendMessage(params, kServiceRegistry_addServices_name); |
| 161 } |
| 162 |
| 163 } |
| 164 |
| 165 |
| 166 class ServiceRegistryProxy implements bindings.ProxyBase { |
| 167 final bindings.Proxy impl; |
| 168 ServiceRegistry ptr; |
| 169 final String name = ServiceRegistryName; |
| 170 |
| 171 ServiceRegistryProxy(ServiceRegistryProxyImpl proxyImpl) : |
| 172 impl = proxyImpl, |
| 173 ptr = new _ServiceRegistryProxyCalls(proxyImpl); |
| 174 |
| 175 ServiceRegistryProxy.fromEndpoint( |
| 176 core.MojoMessagePipeEndpoint endpoint) : |
| 177 impl = new ServiceRegistryProxyImpl.fromEndpoint(endpoint) { |
| 178 ptr = new _ServiceRegistryProxyCalls(impl); |
| 179 } |
| 180 |
| 181 ServiceRegistryProxy.fromHandle(core.MojoHandle handle) : |
| 182 impl = new ServiceRegistryProxyImpl.fromHandle(handle) { |
| 183 ptr = new _ServiceRegistryProxyCalls(impl); |
| 184 } |
| 185 |
| 186 ServiceRegistryProxy.unbound() : |
| 187 impl = new ServiceRegistryProxyImpl.unbound() { |
| 188 ptr = new _ServiceRegistryProxyCalls(impl); |
| 189 } |
| 190 |
| 191 factory ServiceRegistryProxy.connectToService( |
| 192 bindings.ServiceConnector s, String url) { |
| 193 ServiceRegistryProxy p = new ServiceRegistryProxy.unbound(); |
| 194 s.connectToService(url, p); |
| 195 return p; |
| 196 } |
| 197 |
| 198 static ServiceRegistryProxy newFromEndpoint( |
| 199 core.MojoMessagePipeEndpoint endpoint) { |
| 200 assert(endpoint.setDescription("For ServiceRegistryProxy")); |
| 201 return new ServiceRegistryProxy.fromEndpoint(endpoint); |
| 202 } |
| 203 |
| 204 Future close({bool immediate: false}) => impl.close(immediate: immediate); |
| 205 |
| 206 Future responseOrError(Future f) => impl.responseOrError(f); |
| 207 |
| 208 Future get errorFuture => impl.errorFuture; |
| 209 |
| 210 int get version => impl.version; |
| 211 |
| 212 Future<int> queryVersion() => impl.queryVersion(); |
| 213 |
| 214 void requireVersion(int requiredVersion) { |
| 215 impl.requireVersion(requiredVersion); |
| 216 } |
| 217 |
| 218 String toString() { |
| 219 return "ServiceRegistryProxy($impl)"; |
| 220 } |
| 221 } |
| 222 |
| 223 |
| 224 class ServiceRegistryStub extends bindings.Stub { |
| 225 ServiceRegistry _impl = null; |
| 226 |
| 227 ServiceRegistryStub.fromEndpoint( |
| 228 core.MojoMessagePipeEndpoint endpoint, [this._impl]) |
| 229 : super.fromEndpoint(endpoint); |
| 230 |
| 231 ServiceRegistryStub.fromHandle(core.MojoHandle handle, [this._impl]) |
| 232 : super.fromHandle(handle); |
| 233 |
| 234 ServiceRegistryStub.unbound() : super.unbound(); |
| 235 |
| 236 static ServiceRegistryStub newFromEndpoint( |
| 237 core.MojoMessagePipeEndpoint endpoint) { |
| 238 assert(endpoint.setDescription("For ServiceRegistryStub")); |
| 239 return new ServiceRegistryStub.fromEndpoint(endpoint); |
| 240 } |
| 241 |
| 242 static const String name = ServiceRegistryName; |
| 243 |
| 244 |
| 245 |
| 246 dynamic handleMessage(bindings.ServiceMessage message) { |
| 247 if (bindings.ControlMessageHandler.isControlMessage(message)) { |
| 248 return bindings.ControlMessageHandler.handleMessage(this, |
| 249 0, |
| 250 message); |
| 251 } |
| 252 assert(_impl != null); |
| 253 switch (message.header.type) { |
| 254 case kServiceRegistry_addServices_name: |
| 255 var params = ServiceRegistryAddServicesParams.deserialize( |
| 256 message.payload); |
| 257 _impl.addServices(params.interfaceNames, params.serviceProvider); |
| 258 break; |
| 259 default: |
| 260 throw new bindings.MojoCodecError("Unexpected message name"); |
| 261 break; |
| 262 } |
| 263 return null; |
| 264 } |
| 265 |
| 266 ServiceRegistry get impl => _impl; |
| 267 set impl(ServiceRegistry d) { |
| 268 assert(_impl == null); |
| 269 _impl = d; |
| 270 } |
| 271 |
| 272 String toString() { |
| 273 var superString = super.toString(); |
| 274 return "ServiceRegistryStub($superString)"; |
| 275 } |
| 276 |
| 277 int get version => 0; |
| 278 } |
| 279 |
| 280 |
OLD | NEW |