OLD | NEW |
| (Empty) |
1 {%- for method in interface.methods %} | |
2 const int k{{interface|name}}_{{method|name}}_name = {{method.ordinal}}; | |
3 {%- endfor %} | |
4 | |
5 abstract class {{interface|name}}Calls { | |
6 void sendMessage(bindings.Struct message, int name); | |
7 Future sendMessageWithRequestId(bindings.Struct message, int name, int id); | |
8 | |
9 {%- for method in interface.methods %} | |
10 {%- if method.response_parameters == None %} | |
11 void call{{method|name|upper_camel_case}}( | |
12 {%- for parameter in method.parameters -%} | |
13 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {% en
dif %} | |
14 {%- endfor -%} | |
15 {%- set request_struct = method|struct_from_method %} | |
16 ) { | |
17 var params = new {{request_struct|name}}(); | |
18 {%- for parameter in method.parameters %} | |
19 params.{{parameter|name}} = {{parameter|name}}; | |
20 {%- endfor %} | |
21 sendMessage(params, k{{interface|name}}_{{method|name}}_name); | |
22 } | |
23 {% else %} | |
24 {%- set response_struct = method|response_struct_from_method %} | |
25 Future<{{response_struct|name}}> call{{method|name|upper_camel_case}}( | |
26 {%- for parameter in method.parameters -%} | |
27 {{parameter.kind|dart_type}} {{parameter|name}}, | |
28 {%- endfor -%} | |
29 {%- set request_struct = method|struct_from_method %} | |
30 [int requestId = -1] | |
31 ) { | |
32 var params = new {{request_struct|name}}(); | |
33 {%- for parameter in method.parameters %} | |
34 params.{{parameter|name}} = {{parameter|name}}; | |
35 {%- endfor %} | |
36 return sendMessageWithRequestId( | |
37 params, | |
38 k{{interface|name}}_{{method|name}}_name, | |
39 requestId, | |
40 bindings.MessageHeader.kMessageExpectsResponse); | |
41 } | |
42 {%- endif %} | |
43 {%- endfor %} | |
44 } | |
45 | |
46 class {{interface|name}}Client extends bindings.Client with {{interface|name}}Ca
lls { | |
47 {{interface|name}}Client(core.MojoMessagePipeEndpoint endpoint) : super(endpoi
nt); | |
48 | |
49 {{interface|name}}Client.fromHandle(core.MojoHandle handle) : | |
50 super.fromHandle(handle); | |
51 | |
52 {{interface|name}}Client.unbound() : super.unbound(); | |
53 | |
54 static {{interface|name}}Client newFromEndpoint( | |
55 core.MojoMessagePipeEndpoint endpoint) => | |
56 new {{interface|name}}Client(endpoint); | |
57 | |
58 void handleResponse(bindings.ServiceMessage message) { | |
59 switch (message.header.type) { | |
60 {%- for method in interface.methods %} | |
61 {%- if method.response_parameters != None %} | |
62 {%- set response_struct = method|response_struct_from_method %} | |
63 case k{{interface|name}}_{{method|name}}_name: | |
64 var r = {{response_struct|name}}.deserialize( | |
65 message.payload); | |
66 if (!message.header.hasRequestId) { | |
67 throw 'Expected a message with a valid request Id.'; | |
68 } | |
69 Completer c = completerMap[message.header.requestId]; | |
70 completerMap[message.header.requestId] = null; | |
71 c.complete(r); | |
72 break; | |
73 {%- endif %} | |
74 {%- endfor %} | |
75 default: | |
76 throw new Exception("Unexpected message name"); | |
77 break; | |
78 } | |
79 } | |
80 } | |
81 | |
82 | |
83 class {{interface|name}}Interface extends bindings.Interface | |
84 {% if interface.client != None -%} | |
85 with {{imported_from[interface.client]}}{{interface.client|upper_camel_case}}Cal
ls | |
86 {% endif -%} { | |
87 {{interface|name}}Interface _delegate = null; | |
88 | |
89 {{interface|name}}Interface(core.MojoMessagePipeEndpoint endpoint) : super(end
point); | |
90 | |
91 {{interface|name}}Interface.fromHandle(core.MojoHandle handle) : | |
92 super.fromHandle(handle); | |
93 | |
94 {{interface|name}}Interface.unbound() : super.unbound(); | |
95 | |
96 static {{interface|name}}Interface newFromEndpoint( | |
97 core.MojoMessagePipeEndpoint endpoint) => | |
98 new {{interface|name}}Interface(endpoint); | |
99 | |
100 static const String name = '{{namespace|replace(".","::")}}::{{interface|name}
}'; | |
101 | |
102 {% for method in interface.methods %} | |
103 {%- if method.response_parameters == None %} | |
104 void {{method|name}}( | |
105 {%- for parameter in method.parameters -%} | |
106 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {% en
dif %} | |
107 {%- endfor -%} | |
108 ) { | |
109 assert(_delegate != null); | |
110 _delegate.{{method|name}}( | |
111 {%- for parameter in method.parameters -%} | |
112 {{parameter|name}}{% if not loop.last %}, {% endif %} | |
113 {%- endfor %}); | |
114 } | |
115 {%- else %} | |
116 {%- set response_struct = method|response_struct_from_method %} | |
117 Future<{{response_struct|name}}> {{method|name}}( | |
118 {%- for parameter in method.parameters -%} | |
119 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {% en
dif %} | |
120 {%- endfor -%} | |
121 ) { | |
122 assert(_delegate != null); | |
123 return _delegate.{{method|name}}( | |
124 {%- for parameter in method.parameters -%} | |
125 {{parameter|name}}{% if not loop.last %}, {% endif %} | |
126 {%- endfor %}); | |
127 } | |
128 {%- endif %} | |
129 {%- endfor %} | |
130 | |
131 Future<bindings.Message> handleMessage(bindings.ServiceMessage message) { | |
132 switch (message.header.type) { | |
133 {%- for method in interface.methods %} | |
134 {%- set request_struct = method|struct_from_method %} | |
135 case k{{interface|name}}_{{method|name}}_name: | |
136 var params = {{request_struct|name}}.deserialize( | |
137 message.payload); | |
138 {%- if method.response_parameters == None %} | |
139 {{method|name}}( | |
140 {%- for parameter in method.parameters -%} | |
141 params.{{parameter|name}}{% if not loop.last %}, {% endif %} | |
142 {%- endfor -%} | |
143 ); | |
144 {%- else %} | |
145 return {{method|name}}( | |
146 {%- for parameter in method.parameters -%} | |
147 params.{{parameter|name}}{% if not loop.last %}, {% endif %} | |
148 {%- endfor -%} | |
149 ).then((response) { | |
150 if (response != null) { | |
151 return buildResponseWithId( | |
152 response, | |
153 k{{interface|name}}_{{method|name}}_name, | |
154 message.header.requestId, | |
155 bindings.MessageHeader.kMessageIsResponse); | |
156 } | |
157 }); | |
158 {%- endif %} | |
159 break; | |
160 {%- endfor %} | |
161 default: | |
162 throw new Exception("Unexpected message name"); | |
163 break; | |
164 } | |
165 return null; | |
166 } | |
167 | |
168 {{interface|name}}Interface get delegate => _delegate; | |
169 set delegate({{interface|name}}Interface d) { | |
170 assert(_delegate == null); | |
171 _delegate = d; | |
172 } | |
173 } | |
174 | |
175 | |
176 {#--- TODO(zra): Validation #} | |
177 | |
178 | |
179 {#--- Interface Constants #} | |
180 {% for constant in interface.constants %} | |
181 final {{constant|name}} = {{constant.value|expression_to_text}}; | |
182 {%- endfor %} | |
183 | |
184 | |
185 {#--- Interface Enums #} | |
186 {%- from "enum_definition.tmpl" import enum_def -%} | |
187 {%- for enum in interface.enums %} | |
188 {{ enum_def("", enum) }} | |
189 {%- endfor %} | |
OLD | NEW |