OLD | NEW |
1 {%- for method in interface.methods %} | 1 {%- for method in interface.methods %} |
2 const int _{{interface|name|lower_camel}}Method{{method|name|upper_camel}}Name =
{{method.ordinal}}; | 2 const int _{{interface|name|lower_camel}}Method{{method|name|upper_camel}}Name =
{{method.ordinal}}; |
3 {%- endfor %} | 3 {%- endfor %} |
4 | 4 |
5 {#--- Interface Enums #} | 5 {#--- Interface Enums #} |
6 {%- from "enum_definition.tmpl" import enum_def -%} | 6 {%- from "enum_definition.tmpl" import enum_def -%} |
7 {%- for enum in interface.enums %} | 7 {%- for enum in interface.enums %} |
8 {{ enum_def(enum, typepkg, package) }} | 8 {{ enum_def(enum, typepkg, package) }} |
9 {%- endfor %} | 9 {%- endfor %} |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 {%- endif %} | 33 {%- endif %} |
34 } | 34 } |
35 | 35 |
36 abstract class {{interface|name}} { | 36 abstract class {{interface|name}} { |
37 {%- if interface.service_name %} | 37 {%- if interface.service_name %} |
38 static const String serviceName = "{{interface.service_name}}"; | 38 static const String serviceName = "{{interface.service_name}}"; |
39 {%- else %} | 39 {%- else %} |
40 static const String serviceName = null; | 40 static const String serviceName = null; |
41 {%- endif %} | 41 {%- endif %} |
42 | 42 |
| 43 static {{descpkg}}ServiceDescription _cachedServiceDescription; |
| 44 static {{descpkg}}ServiceDescription get serviceDescription { |
| 45 if (_cachedServiceDescription == null) { |
| 46 _cachedServiceDescription = new _{{interface|name}}ServiceDescription(); |
| 47 } |
| 48 return _cachedServiceDescription; |
| 49 } |
| 50 |
| 51 static {{interface|name}}Proxy connectToService( |
| 52 bindings.ServiceConnector s, String url, [String serviceName]) { |
| 53 {{interface|name}}Proxy p = new {{interface|name}}Proxy.unbound(); |
| 54 String name = serviceName ?? {{interface|name}}.serviceName; |
| 55 if ((name == null) || name.isEmpty) { |
| 56 throw new core.MojoApiError( |
| 57 "If an interface has no ServiceName, then one must be provided."); |
| 58 } |
| 59 s.connectToService(url, p, name); |
| 60 return p; |
| 61 } |
| 62 |
43 {%- for method in interface.methods %} | 63 {%- for method in interface.methods %} |
44 {%- if method.response_parameters == None %} | 64 {%- if method.response_parameters == None %} |
45 void {{method|name}}( | 65 void {{method|name}}( |
46 {%- for parameter in method.parameters -%} | 66 {%- for parameter in method.parameters -%} |
47 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {%
endif %} | 67 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {%
endif %} |
48 {%- endfor -%} | 68 {%- endfor -%} |
49 ); | 69 ); |
50 {%- else %} | 70 {%- else %} |
51 dynamic {{method|name}}( | 71 dynamic {{method|name}}( |
52 {%- for parameter in method.parameters -%} | 72 {%- for parameter in method.parameters -%} |
53 {{parameter.kind|dart_type}} {{parameter|name}}, | 73 {{parameter.kind|dart_type}} {{parameter|name}}, |
54 {%- endfor -%} | 74 {%- endfor -%} |
55 [Function responseFactory = null]); | 75 [Function responseFactory = null]); |
56 {%- endif %} | 76 {%- endif %} |
57 {%- endfor %} | 77 {%- endfor %} |
58 | 78 |
59 {#--- Interface Constants #} | 79 {#--- Interface Constants #} |
60 {%- for constant in interface.constants %} | 80 {%- for constant in interface.constants %} |
61 static const {{constant.kind|dart_type}} {{constant|name}} = {{constant.resolv
ed_value}}; | 81 static const {{constant.kind|dart_type}} {{constant|name}} = {{constant.resolv
ed_value}}; |
62 {%- endfor %} | 82 {%- endfor %} |
63 } | 83 } |
64 | 84 |
| 85 abstract class {{interface|name}}Interface |
| 86 implements bindings.MojoInterface<{{interface|name}}>, |
| 87 {{interface|name}} { |
| 88 factory {{interface|name}}Interface([{{interface|name}} impl]) => |
| 89 new {{interface|name}}Stub.unbound(impl); |
| 90 factory {{interface|name}}Interface.fromEndpoint( |
| 91 core.MojoMessagePipeEndpoint endpoint, |
| 92 [{{interface|name}} impl]) => |
| 93 new {{interface|name}}Stub.fromEndpoint(endpoint, impl); |
| 94 } |
| 95 |
| 96 abstract class {{interface|name}}InterfaceRequest |
| 97 implements bindings.MojoInterface<{{interface|name}}>, |
| 98 {{interface|name}} { |
| 99 factory {{interface|name}}InterfaceRequest() => |
| 100 new {{interface|name}}Proxy.unbound(); |
| 101 } |
| 102 |
65 class _{{interface|name}}ProxyControl | 103 class _{{interface|name}}ProxyControl |
66 extends bindings.ProxyMessageHandler | 104 extends bindings.ProxyMessageHandler |
67 implements bindings.ProxyControl { | 105 implements bindings.ProxyControl<{{interface|name}}> { |
68 _{{interface|name}}ProxyControl.fromEndpoint( | 106 _{{interface|name}}ProxyControl.fromEndpoint( |
69 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); | 107 core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint); |
70 | 108 |
71 _{{interface|name}}ProxyControl.fromHandle( | 109 _{{interface|name}}ProxyControl.fromHandle( |
72 core.MojoHandle handle) : super.fromHandle(handle); | 110 core.MojoHandle handle) : super.fromHandle(handle); |
73 | 111 |
74 _{{interface|name}}ProxyControl.unbound() : super.unbound(); | 112 _{{interface|name}}ProxyControl.unbound() : super.unbound(); |
75 | 113 |
76 {{descpkg}}ServiceDescription get serviceDescription => | |
77 new _{{interface|name}}ServiceDescription(); | |
78 | |
79 String get serviceName => {{interface|name}}.serviceName; | 114 String get serviceName => {{interface|name}}.serviceName; |
80 | 115 |
81 void handleResponse(bindings.ServiceMessage message) { | 116 void handleResponse(bindings.ServiceMessage message) { |
82 switch (message.header.type) { | 117 switch (message.header.type) { |
83 {%- for method in interface.methods %} | 118 {%- for method in interface.methods %} |
84 {%- if method.response_parameters != None %} | 119 {%- if method.response_parameters != None %} |
85 {%- set response_struct = method.response_param_struct %} | 120 {%- set response_struct = method.response_param_struct %} |
86 case _{{interface|name|lower_camel}}Method{{method|name|upper_camel}}Name: | 121 case _{{interface|name|lower_camel}}Method{{method|name|upper_camel}}Name: |
87 var r = {{response_struct|name}}.deserialize( | 122 var r = {{response_struct|name}}.deserialize( |
88 message.payload); | 123 message.payload); |
(...skipping 16 matching lines...) Expand all Loading... |
105 break; | 140 break; |
106 {%- endif %} | 141 {%- endif %} |
107 {%- endfor %} | 142 {%- endfor %} |
108 default: | 143 default: |
109 proxyError("Unexpected message type: ${message.header.type}"); | 144 proxyError("Unexpected message type: ${message.header.type}"); |
110 close(immediate: true); | 145 close(immediate: true); |
111 break; | 146 break; |
112 } | 147 } |
113 } | 148 } |
114 | 149 |
| 150 {{interface|name}} get impl => null; |
| 151 set impl({{interface|name}} _) { |
| 152 throw new core.MojoApiError("The impl of a Proxy cannot be set."); |
| 153 } |
| 154 |
115 @override | 155 @override |
116 String toString() { | 156 String toString() { |
117 var superString = super.toString(); | 157 var superString = super.toString(); |
118 return "_{{interface|name}}ProxyControl($superString)"; | 158 return "_{{interface|name}}ProxyControl($superString)"; |
119 } | 159 } |
120 } | 160 } |
121 | 161 |
122 class {{interface|name}}Proxy | 162 class {{interface|name}}Proxy |
123 extends bindings.Proxy | 163 extends bindings.Proxy<{{interface|name}}> |
124 implements {{interface|name}} { | 164 implements {{interface|name}}, |
| 165 {{interface|name}}Interface, |
| 166 {{interface|name}}InterfaceRequest { |
125 {{interface|name}}Proxy.fromEndpoint( | 167 {{interface|name}}Proxy.fromEndpoint( |
126 core.MojoMessagePipeEndpoint endpoint) | 168 core.MojoMessagePipeEndpoint endpoint) |
127 : super(new _{{interface|name}}ProxyControl.fromEndpoint(endpoint)); | 169 : super(new _{{interface|name}}ProxyControl.fromEndpoint(endpoint)); |
128 | 170 |
129 {{interface|name}}Proxy.fromHandle(core.MojoHandle handle) | 171 {{interface|name}}Proxy.fromHandle(core.MojoHandle handle) |
130 : super(new _{{interface|name}}ProxyControl.fromHandle(handle)); | 172 : super(new _{{interface|name}}ProxyControl.fromHandle(handle)); |
131 | 173 |
132 {{interface|name}}Proxy.unbound() | 174 {{interface|name}}Proxy.unbound() |
133 : super(new _{{interface|name}}ProxyControl.unbound()); | 175 : super(new _{{interface|name}}ProxyControl.unbound()); |
134 | 176 |
135 static {{interface|name}}Proxy newFromEndpoint( | 177 static {{interface|name}}Proxy newFromEndpoint( |
136 core.MojoMessagePipeEndpoint endpoint) { | 178 core.MojoMessagePipeEndpoint endpoint) { |
137 assert(endpoint.setDescription("For {{interface|name}}Proxy")); | 179 assert(endpoint.setDescription("For {{interface|name}}Proxy")); |
138 return new {{interface|name}}Proxy.fromEndpoint(endpoint); | 180 return new {{interface|name}}Proxy.fromEndpoint(endpoint); |
139 } | 181 } |
140 | 182 |
141 factory {{interface|name}}Proxy.connectToService( | |
142 bindings.ServiceConnector s, String url, [String serviceName]) { | |
143 {{interface|name}}Proxy p = new {{interface|name}}Proxy.unbound(); | |
144 s.connectToService(url, p, serviceName); | |
145 return p; | |
146 } | |
147 | |
148 {% for method in interface.methods %} | 183 {% for method in interface.methods %} |
149 {%- if method.response_parameters == None %} | 184 {%- if method.response_parameters == None %} |
150 void {{method|name}}( | 185 void {{method|name}}( |
151 {%- for parameter in method.parameters -%} | 186 {%- for parameter in method.parameters -%} |
152 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {% en
dif %} | 187 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {% en
dif %} |
153 {%- endfor -%} | 188 {%- endfor -%} |
154 {%- set request_struct = method.param_struct -%} | 189 {%- set request_struct = method.param_struct -%} |
155 ) { | 190 ) { |
156 if (!ctrl.isBound) { | 191 if (!ctrl.isBound) { |
157 ctrl.proxyError("The Proxy is closed."); | 192 ctrl.proxyError("The Proxy is closed."); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 232 } |
198 | 233 |
199 _{{interface|name}}StubControl.fromHandle( | 234 _{{interface|name}}StubControl.fromHandle( |
200 core.MojoHandle handle, [{{interface|name}} impl]) | 235 core.MojoHandle handle, [{{interface|name}} impl]) |
201 : super.fromHandle(handle, autoBegin: impl != null) { | 236 : super.fromHandle(handle, autoBegin: impl != null) { |
202 _impl = impl; | 237 _impl = impl; |
203 } | 238 } |
204 | 239 |
205 _{{interface|name}}StubControl.unbound([this._impl]) : super.unbound(); | 240 _{{interface|name}}StubControl.unbound([this._impl]) : super.unbound(); |
206 | 241 |
| 242 String get serviceName => {{interface|name}}.serviceName; |
| 243 |
207 {% for method in interface.methods %} | 244 {% for method in interface.methods %} |
208 {%- if method.response_parameters != None %} | 245 {%- if method.response_parameters != None %} |
209 {%- set response_struct = method.response_param_struct %} | 246 {%- set response_struct = method.response_param_struct %} |
210 {{response_struct|name}} _{{response_struct|name|lower_camel}}Factory( | 247 {{response_struct|name}} _{{response_struct|name|lower_camel}}Factory( |
211 {%- for param in method.response_parameters -%} | 248 {%- for param in method.response_parameters -%} |
212 {{param.kind|dart_type}} {{param|name}}{% if not loop.last %}, {% endif %} | 249 {{param.kind|dart_type}} {{param|name}}{% if not loop.last %}, {% endif %} |
213 {%- endfor -%} | 250 {%- endfor -%} |
214 ) { | 251 ) { |
215 var result = new {{response_struct|name}}(); | 252 var result = new {{response_struct|name}}(); |
216 {%- for param in method.response_parameters %} | 253 {%- for param in method.response_parameters %} |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } | 334 } |
298 } | 335 } |
299 | 336 |
300 @override | 337 @override |
301 String toString() { | 338 String toString() { |
302 var superString = super.toString(); | 339 var superString = super.toString(); |
303 return "_{{interface|name}}StubControl($superString)"; | 340 return "_{{interface|name}}StubControl($superString)"; |
304 } | 341 } |
305 | 342 |
306 int get version => {{interface.version}}; | 343 int get version => {{interface.version}}; |
307 | |
308 static {{descpkg}}ServiceDescription _cachedServiceDescription; | |
309 static {{descpkg}}ServiceDescription get serviceDescription { | |
310 if (_cachedServiceDescription == null) { | |
311 _cachedServiceDescription = new _{{interface|name}}ServiceDescription(); | |
312 } | |
313 return _cachedServiceDescription; | |
314 } | |
315 } | 344 } |
316 | 345 |
317 class {{interface|name}}Stub | 346 class {{interface|name}}Stub |
318 extends bindings.Stub<{{interface|name}}> | 347 extends bindings.Stub<{{interface|name}}> |
319 implements {{interface|name}} { | 348 implements {{interface|name}}, |
| 349 {{interface|name}}Interface, |
| 350 {{interface|name}}InterfaceRequest { |
| 351 {{interface|name}}Stub.unbound([{{interface|name}} impl]) |
| 352 : super(new _{{interface|name}}StubControl.unbound(impl)); |
| 353 |
320 {{interface|name}}Stub.fromEndpoint( | 354 {{interface|name}}Stub.fromEndpoint( |
321 core.MojoMessagePipeEndpoint endpoint, [{{interface|name}} impl]) | 355 core.MojoMessagePipeEndpoint endpoint, [{{interface|name}} impl]) |
322 : super(new _{{interface|name}}StubControl.fromEndpoint(endpoint, impl)); | 356 : super(new _{{interface|name}}StubControl.fromEndpoint(endpoint, impl)); |
323 | 357 |
324 {{interface|name}}Stub.fromHandle( | 358 {{interface|name}}Stub.fromHandle( |
325 core.MojoHandle handle, [{{interface|name}} impl]) | 359 core.MojoHandle handle, [{{interface|name}} impl]) |
326 : super(new _{{interface|name}}StubControl.fromHandle(handle, impl)); | 360 : super(new _{{interface|name}}StubControl.fromHandle(handle, impl)); |
327 | 361 |
328 {{interface|name}}Stub.unbound([{{interface|name}} impl]) | |
329 : super(new _{{interface|name}}StubControl.unbound(impl)); | |
330 | |
331 static {{interface|name}}Stub newFromEndpoint( | 362 static {{interface|name}}Stub newFromEndpoint( |
332 core.MojoMessagePipeEndpoint endpoint) { | 363 core.MojoMessagePipeEndpoint endpoint) { |
333 assert(endpoint.setDescription("For {{interface|name}}Stub")); | 364 assert(endpoint.setDescription("For {{interface|name}}Stub")); |
334 return new {{interface|name}}Stub.fromEndpoint(endpoint); | 365 return new {{interface|name}}Stub.fromEndpoint(endpoint); |
335 } | 366 } |
336 | 367 |
337 static {{descpkg}}ServiceDescription get serviceDescription => | |
338 _{{interface|name}}StubControl.serviceDescription; | |
339 | |
340 {% for method in interface.methods %} | 368 {% for method in interface.methods %} |
341 {%- if method.response_parameters == None %} | 369 {%- if method.response_parameters == None %} |
342 void {{method|name}}( | 370 void {{method|name}}( |
343 {%- for parameter in method.parameters -%} | 371 {%- for parameter in method.parameters -%} |
344 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {% en
dif %} | 372 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {% en
dif %} |
345 {%- endfor -%} | 373 {%- endfor -%} |
346 ) { | 374 ) { |
347 return impl.{{method|name}}( | 375 return impl.{{method|name}}( |
348 {%- for parameter in method.parameters -%} | 376 {%- for parameter in method.parameters -%} |
349 {{parameter|name}}{% if not loop.last %}, {% endif %} | 377 {{parameter|name}}{% if not loop.last %}, {% endif %} |
350 {%- endfor -%} | 378 {%- endfor -%} |
351 ); | 379 ); |
352 } | 380 } |
353 {%- else %} | 381 {%- else %} |
354 dynamic {{method|name}}( | 382 dynamic {{method|name}}( |
355 {%- for parameter in method.parameters -%} | 383 {%- for parameter in method.parameters -%} |
356 {{parameter.kind|dart_type}} {{parameter|name}}, | 384 {{parameter.kind|dart_type}} {{parameter|name}}, |
357 {%- endfor -%} | 385 {%- endfor -%} |
358 [Function responseFactory = null]) { | 386 [Function responseFactory = null]) { |
359 return impl.{{method|name}}( | 387 return impl.{{method|name}}( |
360 {%- for parameter in method.parameters -%} | 388 {%- for parameter in method.parameters -%} |
361 {{parameter|name}}, | 389 {{parameter|name}}, |
362 {%- endfor -%} | 390 {%- endfor -%} |
363 responseFactory); | 391 responseFactory); |
364 } | 392 } |
365 {%- endif %} | 393 {%- endif %} |
366 {%- endfor %} | 394 {%- endfor %} |
367 } | 395 } |
OLD | NEW |