Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl

Issue 968243003: Dart: Adds optional named arguments for creating bindings. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Format Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/dart/src/stub.dart ('k') | services/dart/test/echo/main.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 {%- for method in interface.methods %} 1 {%- for method in interface.methods %}
2 const int k{{interface|name}}_{{method|name}}_name = {{method.ordinal}}; 2 const int k{{interface|name}}_{{method|name}}_name = {{method.ordinal}};
3 {%- endfor %} 3 {%- endfor %}
4 4
5 const String {{interface|name}}Name = 5 const String {{interface|name}}Name =
6 '{{namespace|replace(".","::")}}::{{interface|name}}'; 6 '{{namespace|replace(".","::")}}::{{interface|name}}';
7 7
8 abstract class {{interface|name}} { 8 abstract class {{interface|name}} {
9 {%- for method in interface.methods %} 9 {%- for method in interface.methods %}
10 {%- if method.response_parameters == None %} 10 {%- if method.response_parameters == None %}
(...skipping 20 matching lines...) Expand all
31 {#--- Interface Enums #} 31 {#--- Interface Enums #}
32 {%- from "enum_definition.tmpl" import enum_def -%} 32 {%- from "enum_definition.tmpl" import enum_def -%}
33 {%- for enum in interface.enums %} 33 {%- for enum in interface.enums %}
34 {{ enum_def(" static ", enum) }} 34 {{ enum_def(" static ", enum) }}
35 {%- endfor %} 35 {%- endfor %}
36 } 36 }
37 37
38 38
39 class {{interface|name}}ProxyImpl extends bindings.Proxy { 39 class {{interface|name}}ProxyImpl extends bindings.Proxy {
40 {{interface|name}}ProxyImpl.fromEndpoint( 40 {{interface|name}}ProxyImpl.fromEndpoint(
41 core.MojoMessagePipeEndpoint endpoint) : super(endpoint); 41 core.MojoMessagePipeEndpoint endpoint,
42 {bool doListen: true, Function onClosed}) :
43 super.fromEndpoint(endpoint, doListen: doListen, onClosed: onClosed);
42 44
43 {{interface|name}}ProxyImpl.fromHandle(core.MojoHandle handle) : 45 {{interface|name}}ProxyImpl.fromHandle(core.MojoHandle handle,
44 super.fromHandle(handle); 46 {bool doListen: true, Function onClosed}) :
47 super.fromHandle(handle, doListen: doListen, onClosed: onClosed);
45 48
46 {{interface|name}}ProxyImpl.unbound() : super.unbound(); 49 {{interface|name}}ProxyImpl.unbound() : super.unbound();
47 50
48 static {{interface|name}}ProxyImpl newFromEndpoint( 51 static {{interface|name}}ProxyImpl newFromEndpoint(
49 core.MojoMessagePipeEndpoint endpoint) => 52 core.MojoMessagePipeEndpoint endpoint) =>
50 new {{interface|name}}ProxyImpl.fromEndpoint(endpoint); 53 new {{interface|name}}ProxyImpl.fromEndpoint(endpoint);
51 54
52 String get name => {{interface|name}}Name; 55 String get name => {{interface|name}}Name;
53 56
54 void handleResponse(bindings.ServiceMessage message) { 57 void handleResponse(bindings.ServiceMessage message) {
(...skipping 27 matching lines...) Expand all
82 _{{interface|name}}ProxyCalls(this._proxyImpl); 85 _{{interface|name}}ProxyCalls(this._proxyImpl);
83 86
84 {%- for method in interface.methods %} 87 {%- for method in interface.methods %}
85 {%- if method.response_parameters == None %} 88 {%- if method.response_parameters == None %}
86 void {{method|name}}( 89 void {{method|name}}(
87 {%- for parameter in method.parameters -%} 90 {%- for parameter in method.parameters -%}
88 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {% endif %} 91 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {% endif %}
89 {%- endfor -%} 92 {%- endfor -%}
90 {%- set request_struct = method|struct_from_method -%} 93 {%- set request_struct = method|struct_from_method -%}
91 ) { 94 ) {
95 assert(_proxyImpl.isBound);
92 var params = new {{request_struct|name}}(); 96 var params = new {{request_struct|name}}();
93 {%- for parameter in method.parameters %} 97 {%- for parameter in method.parameters %}
94 params.{{parameter|name}} = {{parameter|name}}; 98 params.{{parameter|name}} = {{parameter|name}};
95 {%- endfor %} 99 {%- endfor %}
96 _proxyImpl.sendMessage(params, k{{interface|name}}_{{method|name}}_name); 100 _proxyImpl.sendMessage(params, k{{interface|name}}_{{method|name}}_name);
97 } 101 }
98 {% else %} 102 {% else %}
99 {%- set response_struct = method|response_struct_from_method %} 103 {%- set response_struct = method|response_struct_from_method %}
100 {%- set request_struct = method|struct_from_method %} 104 {%- set request_struct = method|struct_from_method %}
101 Future<{{response_struct|name}}> {{method|name}}( 105 Future<{{response_struct|name}}> {{method|name}}(
102 {%- for parameter in method.parameters -%} 106 {%- for parameter in method.parameters -%}
103 {{parameter.kind|dart_type}} {{parameter|name}}, 107 {{parameter.kind|dart_type}} {{parameter|name}},
104 {%- endfor -%} 108 {%- endfor -%}
105 [Function responseFactory = null]) { 109 [Function responseFactory = null]) {
110 assert(_proxyImpl.isBound);
106 var params = new {{request_struct|name}}(); 111 var params = new {{request_struct|name}}();
107 {%- for parameter in method.parameters %} 112 {%- for parameter in method.parameters %}
108 params.{{parameter|name}} = {{parameter|name}}; 113 params.{{parameter|name}} = {{parameter|name}};
109 {%- endfor %} 114 {%- endfor %}
110 return _proxyImpl.sendMessageWithRequestId( 115 return _proxyImpl.sendMessageWithRequestId(
111 params, 116 params,
112 k{{interface|name}}_{{method|name}}_name, 117 k{{interface|name}}_{{method|name}}_name,
113 -1, 118 -1,
114 bindings.MessageHeader.kMessageExpectsResponse); 119 bindings.MessageHeader.kMessageExpectsResponse);
115 } 120 }
116 {%- endif %} 121 {%- endif %}
117 {%- endfor %} 122 {%- endfor %}
118 } 123 }
119 124
120 125
121 class {{interface|name}}Proxy implements bindings.ProxyBase { 126 class {{interface|name}}Proxy implements bindings.ProxyBase {
122 final bindings.Proxy impl; 127 final bindings.Proxy impl;
123 {{interface|name}} ptr; 128 {{interface|name}} ptr;
124 final String name = {{interface|name}}Name; 129 final String name = {{interface|name}}Name;
125 130
126 {{interface|name}}Proxy({{interface|name}}ProxyImpl proxyImpl) : 131 {{interface|name}}Proxy({{interface|name}}ProxyImpl proxyImpl) :
127 impl = proxyImpl, 132 impl = proxyImpl,
128 ptr = new _{{interface|name}}ProxyCalls(proxyImpl); 133 ptr = new _{{interface|name}}ProxyCalls(proxyImpl);
129 134
130 {{interface|name}}Proxy.fromEndpoint( 135 {{interface|name}}Proxy.fromEndpoint(
131 core.MojoMessagePipeEndpoint endpoint) : 136 core.MojoMessagePipeEndpoint endpoint,
132 impl = new {{interface|name}}ProxyImpl.fromEndpoint(endpoint) { 137 {bool doListen: true, Function onClosed}) :
138 impl = new {{interface|name}}ProxyImpl.fromEndpoint(
139 endpoint, doListen: doListen, onClosed: onClosed) {
133 ptr = new _{{interface|name}}ProxyCalls(impl); 140 ptr = new _{{interface|name}}ProxyCalls(impl);
134 } 141 }
135 142
136 {{interface|name}}Proxy.fromHandle(core.MojoHandle handle) : 143 {{interface|name}}Proxy.fromHandle(core.MojoHandle handle,
137 impl = new {{interface|name}}ProxyImpl.fromHandle(handle) { 144 {bool doListen: true, Function onClosed}) :
145 impl = new {{interface|name}}ProxyImpl.fromHandle(
146 handle, doListen: doListen, onClosed: onClosed) {
138 ptr = new _{{interface|name}}ProxyCalls(impl); 147 ptr = new _{{interface|name}}ProxyCalls(impl);
139 } 148 }
140 149
141 {{interface|name}}Proxy.unbound() : 150 {{interface|name}}Proxy.unbound() :
142 impl = new {{interface|name}}ProxyImpl.unbound() { 151 impl = new {{interface|name}}ProxyImpl.unbound() {
143 ptr = new _{{interface|name}}ProxyCalls(impl); 152 ptr = new _{{interface|name}}ProxyCalls(impl);
144 } 153 }
145 154
146 static {{interface|name}}Proxy newFromEndpoint( 155 static {{interface|name}}Proxy newFromEndpoint(
147 core.MojoMessagePipeEndpoint endpoint) => 156 core.MojoMessagePipeEndpoint endpoint) =>
148 new {{interface|name}}Proxy.fromEndpoint(endpoint); 157 new {{interface|name}}Proxy.fromEndpoint(endpoint);
149 158
150 void close() => impl.close(); 159 void close() => impl.close();
151 } 160 }
152 161
153 162
154 class {{interface|name}}Stub extends bindings.Stub { 163 class {{interface|name}}Stub extends bindings.Stub {
155 {{interface|name}} _delegate = null; 164 {{interface|name}} _impl = null;
156 165
157 {{interface|name}}Stub.fromEndpoint(core.MojoMessagePipeEndpoint endpoint) : 166 {{interface|name}}Stub.fromEndpoint(core.MojoMessagePipeEndpoint endpoint,
158 super(endpoint); 167 { {{interface|name}} impl, bool doListen: true, Function onClosed}) :
168 super.fromEndpoint(endpoint, doListen: false) {
169 assert(!doListen || (impl != null));
170 if (impl != null) {
171 this._impl = impl;
172 }
173 if (doListen) {
174 listen(onClosed: onClosed);
175 }
176 }
159 177
160 {{interface|name}}Stub.fromHandle(core.MojoHandle handle) : 178 {{interface|name}}Stub.fromHandle(core.MojoHandle handle,
161 super.fromHandle(handle); 179 { {{interface|name}} impl, bool doListen: true, Function onClosed}) :
180 super.fromHandle(handle, doListen: false) {
181 assert(!doListen || (impl != null));
182 if (impl != null) {
183 this._impl = impl;
184 }
185 if (doListen) {
186 listen(onClosed: onClosed);
187 }
188 }
162 189
163 {{interface|name}}Stub.unbound() : super.unbound(); 190 {{interface|name}}Stub.unbound() : super.unbound();
164 191
165 static {{interface|name}}Stub newFromEndpoint( 192 static {{interface|name}}Stub newFromEndpoint(
166 core.MojoMessagePipeEndpoint endpoint) => 193 core.MojoMessagePipeEndpoint endpoint) =>
167 new {{interface|name}}Stub.fromEndpoint(endpoint); 194 new {{interface|name}}Stub.fromEndpoint(endpoint, doListen: false);
168 195
169 static const String name = {{interface|name}}Name; 196 static const String name = {{interface|name}}Name;
170 197
171 {% for method in interface.methods %} 198 {% for method in interface.methods %}
172 {%- if method.response_parameters != None %} 199 {%- if method.response_parameters != None %}
173 {%- set response_struct = method|response_struct_from_method %} 200 {%- set response_struct = method|response_struct_from_method %}
174 {{response_struct|name}} _{{response_struct|name}}Factory( 201 {{response_struct|name}} _{{response_struct|name}}Factory(
175 {%- for param in method.response_parameters -%} 202 {%- for param in method.response_parameters -%}
176 {{param.kind|dart_type}} {{param|name}}{% if not loop.last %}, {% endif %} 203 {{param.kind|dart_type}} {{param|name}}{% if not loop.last %}, {% endif %}
177 {%- endfor -%} 204 {%- endfor -%}
178 ) { 205 ) {
179 var result = new {{response_struct|name}}(); 206 var result = new {{response_struct|name}}();
180 {%- for param in method.response_parameters %} 207 {%- for param in method.response_parameters %}
181 result.{{param|name}} = {{param|name}}; 208 result.{{param|name}} = {{param|name}};
182 {%- endfor %} 209 {%- endfor %}
183 return result; 210 return result;
184 } 211 }
185 {%- endif %} 212 {%- endif %}
186 {%- endfor %} 213 {%- endfor %}
187 214
188 Future<bindings.Message> handleMessage(bindings.ServiceMessage message) { 215 Future<bindings.Message> handleMessage(bindings.ServiceMessage message) {
189 assert(_delegate != null); 216 assert(_impl != null);
190 switch (message.header.type) { 217 switch (message.header.type) {
191 {%- for method in interface.methods %} 218 {%- for method in interface.methods %}
192 {%- set request_struct = method|struct_from_method %} 219 {%- set request_struct = method|struct_from_method %}
193 case k{{interface|name}}_{{method|name}}_name: 220 case k{{interface|name}}_{{method|name}}_name:
194 var params = {{request_struct|name}}.deserialize( 221 var params = {{request_struct|name}}.deserialize(
195 message.payload); 222 message.payload);
196 {%- if method.response_parameters == None %} 223 {%- if method.response_parameters == None %}
197 _delegate.{{method|name}}( 224 _impl.{{method|name}}(
198 {%- for parameter in method.parameters -%} 225 {%- for parameter in method.parameters -%}
199 params.{{parameter|name}}{% if not loop.last %}, {% endif %} 226 params.{{parameter|name}}{% if not loop.last %}, {% endif %}
200 {%- endfor -%} 227 {%- endfor -%}
201 ); 228 );
202 {%- else %} 229 {%- else %}
203 {%- set response_struct = method|response_struct_from_method %} 230 {%- set response_struct = method|response_struct_from_method %}
204 return _delegate.{{method|name}}( 231 return _impl.{{method|name}}(
205 {%- for parameter in method.parameters -%} 232 {%- for parameter in method.parameters -%}
206 params.{{parameter|name}}, 233 params.{{parameter|name}},
207 {%- endfor -%} 234 {%- endfor -%}
208 _{{response_struct|name}}Factory).then((response) { 235 _{{response_struct|name}}Factory).then((response) {
209 if (response != null) { 236 if (response != null) {
210 return buildResponseWithId( 237 return buildResponseWithId(
211 response, 238 response,
212 k{{interface|name}}_{{method|name}}_name, 239 k{{interface|name}}_{{method|name}}_name,
213 message.header.requestId, 240 message.header.requestId,
214 bindings.MessageHeader.kMessageIsResponse); 241 bindings.MessageHeader.kMessageIsResponse);
215 } 242 }
216 }); 243 });
217 {%- endif %} 244 {%- endif %}
218 break; 245 break;
219 {%- endfor %} 246 {%- endfor %}
220 default: 247 default:
221 throw new bindings.MojoCodecError("Unexpected message name"); 248 throw new bindings.MojoCodecError("Unexpected message name");
222 break; 249 break;
223 } 250 }
224 return null; 251 return null;
225 } 252 }
226 253
227 {{interface|name}} get delegate => _delegate; 254 {{interface|name}} get impl => _impl;
228 set delegate({{interface|name}} d) { 255 set impl({{interface|name}} d) {
229 assert(_delegate == null); 256 assert(_impl == null);
230 _delegate = d; 257 _impl = d;
231 } 258 }
232 } 259 }
OLDNEW
« no previous file with comments | « mojo/public/dart/src/stub.dart ('k') | services/dart/test/echo/main.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698