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 tcp_connected_socket_mojom; | 5 library tcp_connected_socket_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 _TcpConnectedSocketServiceDescription implements service_describer.Service
Description { | 13 class _TcpConnectedSocketServiceDescription implements service_describer.Service
Description { |
14 dynamic getTopLevelInterface([Function responseFactory]) => | 14 dynamic getTopLevelInterface([Function responseFactory]) => |
15 responseFactory(null); | 15 responseFactory(null); |
16 | 16 |
17 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => | 17 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => |
18 responseFactory(null); | 18 responseFactory(null); |
19 | 19 |
20 dynamic getAllTypeDefinitions([Function responseFactory]) => | 20 dynamic getAllTypeDefinitions([Function responseFactory]) => |
21 responseFactory(null); | 21 responseFactory(null); |
22 } | 22 } |
23 | 23 |
24 abstract class TcpConnectedSocket { | 24 abstract class TcpConnectedSocket { |
25 static const String serviceName = null; | 25 static const String serviceName = null; |
| 26 |
| 27 static service_describer.ServiceDescription _cachedServiceDescription; |
| 28 static service_describer.ServiceDescription get serviceDescription { |
| 29 if (_cachedServiceDescription == null) { |
| 30 _cachedServiceDescription = new _TcpConnectedSocketServiceDescription(); |
| 31 } |
| 32 return _cachedServiceDescription; |
| 33 } |
| 34 |
| 35 static TcpConnectedSocketProxy connectToService( |
| 36 bindings.ServiceConnector s, String url, [String serviceName]) { |
| 37 TcpConnectedSocketProxy p = new TcpConnectedSocketProxy.unbound(); |
| 38 String name = serviceName ?? TcpConnectedSocket.serviceName; |
| 39 if ((name == null) || name.isEmpty) { |
| 40 throw new core.MojoApiError( |
| 41 "If an interface has no ServiceName, then one must be provided."); |
| 42 } |
| 43 s.connectToService(url, p, name); |
| 44 return p; |
| 45 } |
| 46 } |
| 47 |
| 48 abstract class TcpConnectedSocketInterface |
| 49 implements bindings.MojoInterface<TcpConnectedSocket>, |
| 50 TcpConnectedSocket { |
| 51 factory TcpConnectedSocketInterface([TcpConnectedSocket impl]) => |
| 52 new TcpConnectedSocketStub.unbound(impl); |
| 53 factory TcpConnectedSocketInterface.fromEndpoint( |
| 54 core.MojoMessagePipeEndpoint endpoint, |
| 55 [TcpConnectedSocket impl]) => |
| 56 new TcpConnectedSocketStub.fromEndpoint(endpoint, impl); |
| 57 } |
| 58 |
| 59 abstract class TcpConnectedSocketInterfaceRequest |
| 60 implements bindings.MojoInterface<TcpConnectedSocket>, |
| 61 TcpConnectedSocket { |
| 62 factory TcpConnectedSocketInterfaceRequest() => |
| 63 new TcpConnectedSocketProxy.unbound(); |
26 } | 64 } |
27 | 65 |
28 class _TcpConnectedSocketProxyControl | 66 class _TcpConnectedSocketProxyControl |
29 extends bindings.ProxyMessageHandler | 67 extends bindings.ProxyMessageHandler |
30 implements bindings.ProxyControl { | 68 implements bindings.ProxyControl<TcpConnectedSocket> { |
31 _TcpConnectedSocketProxyControl.fromEndpoint( | 69 _TcpConnectedSocketProxyControl.fromEndpoint( |
32 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); | 70 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); |
33 | 71 |
34 _TcpConnectedSocketProxyControl.fromHandle( | 72 _TcpConnectedSocketProxyControl.fromHandle( |
35 core.MojoHandle handle) : super.fromHandle(handle); | 73 core.MojoHandle handle) : super.fromHandle(handle); |
36 | 74 |
37 _TcpConnectedSocketProxyControl.unbound() : super.unbound(); | 75 _TcpConnectedSocketProxyControl.unbound() : super.unbound(); |
38 | 76 |
39 service_describer.ServiceDescription get serviceDescription => | |
40 new _TcpConnectedSocketServiceDescription(); | |
41 | |
42 String get serviceName => TcpConnectedSocket.serviceName; | 77 String get serviceName => TcpConnectedSocket.serviceName; |
43 | 78 |
44 void handleResponse(bindings.ServiceMessage message) { | 79 void handleResponse(bindings.ServiceMessage message) { |
45 switch (message.header.type) { | 80 switch (message.header.type) { |
46 default: | 81 default: |
47 proxyError("Unexpected message type: ${message.header.type}"); | 82 proxyError("Unexpected message type: ${message.header.type}"); |
48 close(immediate: true); | 83 close(immediate: true); |
49 break; | 84 break; |
50 } | 85 } |
51 } | 86 } |
52 | 87 |
| 88 TcpConnectedSocket get impl => null; |
| 89 set impl(TcpConnectedSocket _) { |
| 90 throw new core.MojoApiError("The impl of a Proxy cannot be set."); |
| 91 } |
| 92 |
53 @override | 93 @override |
54 String toString() { | 94 String toString() { |
55 var superString = super.toString(); | 95 var superString = super.toString(); |
56 return "_TcpConnectedSocketProxyControl($superString)"; | 96 return "_TcpConnectedSocketProxyControl($superString)"; |
57 } | 97 } |
58 } | 98 } |
59 | 99 |
60 class TcpConnectedSocketProxy | 100 class TcpConnectedSocketProxy |
61 extends bindings.Proxy | 101 extends bindings.Proxy<TcpConnectedSocket> |
62 implements TcpConnectedSocket { | 102 implements TcpConnectedSocket, |
| 103 TcpConnectedSocketInterface, |
| 104 TcpConnectedSocketInterfaceRequest { |
63 TcpConnectedSocketProxy.fromEndpoint( | 105 TcpConnectedSocketProxy.fromEndpoint( |
64 core.MojoMessagePipeEndpoint endpoint) | 106 core.MojoMessagePipeEndpoint endpoint) |
65 : super(new _TcpConnectedSocketProxyControl.fromEndpoint(endpoint)); | 107 : super(new _TcpConnectedSocketProxyControl.fromEndpoint(endpoint)); |
66 | 108 |
67 TcpConnectedSocketProxy.fromHandle(core.MojoHandle handle) | 109 TcpConnectedSocketProxy.fromHandle(core.MojoHandle handle) |
68 : super(new _TcpConnectedSocketProxyControl.fromHandle(handle)); | 110 : super(new _TcpConnectedSocketProxyControl.fromHandle(handle)); |
69 | 111 |
70 TcpConnectedSocketProxy.unbound() | 112 TcpConnectedSocketProxy.unbound() |
71 : super(new _TcpConnectedSocketProxyControl.unbound()); | 113 : super(new _TcpConnectedSocketProxyControl.unbound()); |
72 | 114 |
73 static TcpConnectedSocketProxy newFromEndpoint( | 115 static TcpConnectedSocketProxy newFromEndpoint( |
74 core.MojoMessagePipeEndpoint endpoint) { | 116 core.MojoMessagePipeEndpoint endpoint) { |
75 assert(endpoint.setDescription("For TcpConnectedSocketProxy")); | 117 assert(endpoint.setDescription("For TcpConnectedSocketProxy")); |
76 return new TcpConnectedSocketProxy.fromEndpoint(endpoint); | 118 return new TcpConnectedSocketProxy.fromEndpoint(endpoint); |
77 } | 119 } |
78 | 120 |
79 factory TcpConnectedSocketProxy.connectToService( | |
80 bindings.ServiceConnector s, String url, [String serviceName]) { | |
81 TcpConnectedSocketProxy p = new TcpConnectedSocketProxy.unbound(); | |
82 s.connectToService(url, p, serviceName); | |
83 return p; | |
84 } | |
85 | |
86 | 121 |
87 } | 122 } |
88 | 123 |
89 class _TcpConnectedSocketStubControl | 124 class _TcpConnectedSocketStubControl |
90 extends bindings.StubMessageHandler | 125 extends bindings.StubMessageHandler |
91 implements bindings.StubControl<TcpConnectedSocket> { | 126 implements bindings.StubControl<TcpConnectedSocket> { |
92 TcpConnectedSocket _impl; | 127 TcpConnectedSocket _impl; |
93 | 128 |
94 _TcpConnectedSocketStubControl.fromEndpoint( | 129 _TcpConnectedSocketStubControl.fromEndpoint( |
95 core.MojoMessagePipeEndpoint endpoint, [TcpConnectedSocket impl]) | 130 core.MojoMessagePipeEndpoint endpoint, [TcpConnectedSocket impl]) |
96 : super.fromEndpoint(endpoint, autoBegin: impl != null) { | 131 : super.fromEndpoint(endpoint, autoBegin: impl != null) { |
97 _impl = impl; | 132 _impl = impl; |
98 } | 133 } |
99 | 134 |
100 _TcpConnectedSocketStubControl.fromHandle( | 135 _TcpConnectedSocketStubControl.fromHandle( |
101 core.MojoHandle handle, [TcpConnectedSocket impl]) | 136 core.MojoHandle handle, [TcpConnectedSocket impl]) |
102 : super.fromHandle(handle, autoBegin: impl != null) { | 137 : super.fromHandle(handle, autoBegin: impl != null) { |
103 _impl = impl; | 138 _impl = impl; |
104 } | 139 } |
105 | 140 |
106 _TcpConnectedSocketStubControl.unbound([this._impl]) : super.unbound(); | 141 _TcpConnectedSocketStubControl.unbound([this._impl]) : super.unbound(); |
107 | 142 |
| 143 String get serviceName => TcpConnectedSocket.serviceName; |
| 144 |
108 | 145 |
109 | 146 |
110 dynamic handleMessage(bindings.ServiceMessage message) { | 147 dynamic handleMessage(bindings.ServiceMessage message) { |
111 if (bindings.ControlMessageHandler.isControlMessage(message)) { | 148 if (bindings.ControlMessageHandler.isControlMessage(message)) { |
112 return bindings.ControlMessageHandler.handleMessage(this, | 149 return bindings.ControlMessageHandler.handleMessage(this, |
113 0, | 150 0, |
114 message); | 151 message); |
115 } | 152 } |
116 if (_impl == null) { | 153 if (_impl == null) { |
117 throw new core.MojoApiError("$this has no implementation set"); | 154 throw new core.MojoApiError("$this has no implementation set"); |
(...skipping 25 matching lines...) Expand all Loading... |
143 } | 180 } |
144 } | 181 } |
145 | 182 |
146 @override | 183 @override |
147 String toString() { | 184 String toString() { |
148 var superString = super.toString(); | 185 var superString = super.toString(); |
149 return "_TcpConnectedSocketStubControl($superString)"; | 186 return "_TcpConnectedSocketStubControl($superString)"; |
150 } | 187 } |
151 | 188 |
152 int get version => 0; | 189 int get version => 0; |
153 | |
154 static service_describer.ServiceDescription _cachedServiceDescription; | |
155 static service_describer.ServiceDescription get serviceDescription { | |
156 if (_cachedServiceDescription == null) { | |
157 _cachedServiceDescription = new _TcpConnectedSocketServiceDescription(); | |
158 } | |
159 return _cachedServiceDescription; | |
160 } | |
161 } | 190 } |
162 | 191 |
163 class TcpConnectedSocketStub | 192 class TcpConnectedSocketStub |
164 extends bindings.Stub<TcpConnectedSocket> | 193 extends bindings.Stub<TcpConnectedSocket> |
165 implements TcpConnectedSocket { | 194 implements TcpConnectedSocket, |
| 195 TcpConnectedSocketInterface, |
| 196 TcpConnectedSocketInterfaceRequest { |
| 197 TcpConnectedSocketStub.unbound([TcpConnectedSocket impl]) |
| 198 : super(new _TcpConnectedSocketStubControl.unbound(impl)); |
| 199 |
166 TcpConnectedSocketStub.fromEndpoint( | 200 TcpConnectedSocketStub.fromEndpoint( |
167 core.MojoMessagePipeEndpoint endpoint, [TcpConnectedSocket impl]) | 201 core.MojoMessagePipeEndpoint endpoint, [TcpConnectedSocket impl]) |
168 : super(new _TcpConnectedSocketStubControl.fromEndpoint(endpoint, impl)); | 202 : super(new _TcpConnectedSocketStubControl.fromEndpoint(endpoint, impl)); |
169 | 203 |
170 TcpConnectedSocketStub.fromHandle( | 204 TcpConnectedSocketStub.fromHandle( |
171 core.MojoHandle handle, [TcpConnectedSocket impl]) | 205 core.MojoHandle handle, [TcpConnectedSocket impl]) |
172 : super(new _TcpConnectedSocketStubControl.fromHandle(handle, impl)); | 206 : super(new _TcpConnectedSocketStubControl.fromHandle(handle, impl)); |
173 | 207 |
174 TcpConnectedSocketStub.unbound([TcpConnectedSocket impl]) | |
175 : super(new _TcpConnectedSocketStubControl.unbound(impl)); | |
176 | |
177 static TcpConnectedSocketStub newFromEndpoint( | 208 static TcpConnectedSocketStub newFromEndpoint( |
178 core.MojoMessagePipeEndpoint endpoint) { | 209 core.MojoMessagePipeEndpoint endpoint) { |
179 assert(endpoint.setDescription("For TcpConnectedSocketStub")); | 210 assert(endpoint.setDescription("For TcpConnectedSocketStub")); |
180 return new TcpConnectedSocketStub.fromEndpoint(endpoint); | 211 return new TcpConnectedSocketStub.fromEndpoint(endpoint); |
181 } | 212 } |
182 | 213 |
183 static service_describer.ServiceDescription get serviceDescription => | |
184 _TcpConnectedSocketStubControl.serviceDescription; | |
185 | |
186 | 214 |
187 } | 215 } |
188 | 216 |
189 | 217 |
190 | 218 |
OLD | NEW |