OLD | NEW |
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 abstract class {{interface|name}} implements core.Listener { | 5 const String {{interface|name}}Name = |
6 static const String name = '{{namespace|replace(".","::")}}::{{interface|name}
}'; | 6 '{{namespace|replace(".","::")}}::{{interface|name}}'; |
7 {{interface|name}}Stub stub; | |
8 | 7 |
9 {{interface|name}}(core.MojoMessagePipeEndpoint endpoint) : | 8 abstract class {{interface|name}} { |
10 stub = new {{interface|name}}Stub(endpoint); | |
11 | |
12 {{interface|name}}.fromHandle(core.MojoHandle handle) : | |
13 stub = new {{interface|name}}Stub.fromHandle(handle); | |
14 | |
15 {{interface|name}}.fromStub(this.stub); | |
16 | |
17 {{interface|name}}.unbound() : | |
18 stub = new {{interface|name}}Stub.unbound(); | |
19 | |
20 void close({bool nodefer : false}) => stub.close(nodefer: nodefer); | |
21 | |
22 StreamSubscription<int> listen() => stub.listen(); | |
23 | |
24 {{interface|name}} get delegate => stub.delegate; | |
25 set delegate({{interface|name}} d) { | |
26 stub.delegate = d; | |
27 } | |
28 | |
29 {%- for method in interface.methods %} | 9 {%- for method in interface.methods %} |
30 {%- if method.response_parameters == None %} | 10 {%- if method.response_parameters == None %} |
31 void {{method|name}}( | 11 void {{method|name}}( |
32 {%- for parameter in method.parameters -%} | 12 {%- for parameter in method.parameters -%} |
33 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {%
endif %} | 13 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {%
endif %} |
34 {%- endfor -%} | 14 {%- endfor -%} |
35 ); | 15 ); |
36 {%- else %} | 16 {%- else %} |
37 {%- set response_struct = method|response_struct_from_method %} | 17 {%- set response_struct = method|response_struct_from_method %} |
38 Future<{{response_struct|name}}> {{method|name}}( | 18 Future<{{response_struct|name}}> {{method|name}}( |
39 {%- for parameter in method.parameters -%} | 19 {%- for parameter in method.parameters -%} |
40 {{parameter.kind|dart_type}} {{parameter|name}}, | 20 {{parameter.kind|dart_type}} {{parameter|name}}, |
41 {%- endfor -%} | 21 {%- endfor -%} |
42 [Function responseFactory = null]); | 22 [Function responseFactory = null]); |
43 {%- endif %} | 23 {%- endif %} |
44 {%- endfor %} | 24 {%- endfor %} |
45 | 25 |
46 | |
47 {#--- Interface Constants #} | 26 {#--- Interface Constants #} |
48 {% for constant in interface.constants %} | 27 {% for constant in interface.constants %} |
49 static final {{constant|name}} = {{constant.value|expression_to_text}}; | 28 static final {{constant|name}} = {{constant.value|expression_to_text}}; |
50 {%- endfor %} | 29 {%- endfor %} |
51 | 30 |
52 | |
53 {#--- Interface Enums #} | 31 {#--- Interface Enums #} |
54 {%- from "enum_definition.tmpl" import enum_def -%} | 32 {%- from "enum_definition.tmpl" import enum_def -%} |
55 {%- for enum in interface.enums %} | 33 {%- for enum in interface.enums %} |
56 {{ enum_def(" static ", enum) }} | 34 {{ enum_def(" static ", enum) }} |
57 {%- endfor %} | 35 {%- endfor %} |
58 } | 36 } |
59 | 37 |
60 class {{interface|name}}Proxy extends bindings.Proxy implements {{interface|name
}} { | |
61 {{interface|name}}Proxy(core.MojoMessagePipeEndpoint endpoint) : super(endpoin
t); | |
62 | 38 |
63 {{interface|name}}Proxy.fromHandle(core.MojoHandle handle) : | 39 class {{interface|name}}ProxyImpl extends bindings.Proxy { |
| 40 {{interface|name}}ProxyImpl.fromEndpoint( |
| 41 core.MojoMessagePipeEndpoint endpoint) : super(endpoint); |
| 42 |
| 43 {{interface|name}}ProxyImpl.fromHandle(core.MojoHandle handle) : |
64 super.fromHandle(handle); | 44 super.fromHandle(handle); |
65 | 45 |
66 {{interface|name}}Proxy.unbound() : super.unbound(); | 46 {{interface|name}}ProxyImpl.unbound() : super.unbound(); |
67 | 47 |
68 String get name => {{interface|name}}.name; | 48 static {{interface|name}}ProxyImpl newFromEndpoint( |
| 49 core.MojoMessagePipeEndpoint endpoint) => |
| 50 new {{interface|name}}ProxyImpl.fromEndpoint(endpoint); |
69 | 51 |
70 static {{interface|name}}Proxy newFromEndpoint( | 52 String get name => {{interface|name}}Name; |
71 core.MojoMessagePipeEndpoint endpoint) => | |
72 new {{interface|name}}Proxy(endpoint); | |
73 | 53 |
74 void handleResponse(bindings.ServiceMessage message) { | 54 void handleResponse(bindings.ServiceMessage message) { |
75 switch (message.header.type) { | 55 switch (message.header.type) { |
76 {%- for method in interface.methods %} | 56 {%- for method in interface.methods %} |
77 {%- if method.response_parameters != None %} | 57 {%- if method.response_parameters != None %} |
78 {%- set response_struct = method|response_struct_from_method %} | 58 {%- set response_struct = method|response_struct_from_method %} |
79 case k{{interface|name}}_{{method|name}}_name: | 59 case k{{interface|name}}_{{method|name}}_name: |
80 var r = {{response_struct|name}}.deserialize( | 60 var r = {{response_struct|name}}.deserialize( |
81 message.payload); | 61 message.payload); |
82 if (!message.header.hasRequestId) { | 62 if (!message.header.hasRequestId) { |
83 throw 'Expected a message with a valid request Id.'; | 63 throw 'Expected a message with a valid request Id.'; |
84 } | 64 } |
85 Completer c = completerMap[message.header.requestId]; | 65 Completer c = completerMap[message.header.requestId]; |
86 completerMap[message.header.requestId] = null; | 66 completerMap[message.header.requestId] = null; |
87 c.complete(r); | 67 c.complete(r); |
88 break; | 68 break; |
89 {%- endif %} | 69 {%- endif %} |
90 {%- endfor %} | 70 {%- endfor %} |
91 default: | 71 default: |
92 throw new bindings.MojoCodecError("Unexpected message name"); | 72 throw new bindings.MojoCodecError("Unexpected message name"); |
93 break; | 73 break; |
94 } | 74 } |
95 } | 75 } |
| 76 } |
96 | 77 |
97 {%- for method in interface.methods %} | 78 |
98 {%- if method.response_parameters == None %} | 79 class {{interface|name}}Proxy implements {{interface|name}} { |
99 void {{method|name}}( | 80 {{interface|name}}ProxyImpl _proxyImpl; |
100 {%- for parameter in method.parameters -%} | 81 |
101 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {% en
dif %} | 82 {{interface|name}}Proxy(this._proxyImpl); |
102 {%- endfor -%} | 83 |
103 {%- set request_struct = method|struct_from_method -%} | 84 {{interface|name}}Proxy.fromEndpoint(core.MojoMessagePipeEndpoint endpoint) : |
104 ) { | 85 _proxyImpl = new {{interface|name}}ProxyImpl.fromEndpoint(endpoint); |
105 var params = new {{request_struct|name}}(); | 86 |
106 {%- for parameter in method.parameters %} | 87 {{interface|name}}Proxy.fromHandle(core.MojoHandle handle) : |
107 params.{{parameter|name}} = {{parameter|name}}; | 88 _proxyImpl = new {{interface|name}}ProxyImpl.fromHandle(handle); |
108 {%- endfor %} | 89 |
109 sendMessage(params, k{{interface|name}}_{{method|name}}_name); | 90 {{interface|name}}Proxy.unbound() : |
110 } | 91 _proxyImpl = new {{interface|name}}ProxyImpl.unbound(); |
111 {% else %} | 92 |
112 {%- set response_struct = method|response_struct_from_method %} | 93 {%- for method in interface.methods %} |
113 {%- set request_struct = method|struct_from_method %} | 94 {%- if method.response_parameters == None %} |
114 Future<{{response_struct|name}}> {{method|name}}( | 95 void {{method|name}}( |
115 {%- for parameter in method.parameters -%} | 96 {%- for parameter in method.parameters -%} |
116 {{parameter.kind|dart_type}} {{parameter|name}}, | 97 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {%
endif %} |
117 {%- endfor -%} | 98 {%- endfor -%} |
118 [Function responseFactory = null]) { | 99 {%- set request_struct = method|struct_from_method -%} |
119 var params = new {{request_struct|name}}(); | 100 ) { |
120 {%- for parameter in method.parameters %} | 101 var params = new {{request_struct|name}}(); |
121 params.{{parameter|name}} = {{parameter|name}}; | 102 {%- for parameter in method.parameters %} |
122 {%- endfor %} | 103 params.{{parameter|name}} = {{parameter|name}}; |
123 return sendMessageWithRequestId( | 104 {%- endfor %} |
124 params, | 105 _proxyImpl.sendMessage(params, k{{interface|name}}_{{method|name}}_name); |
125 k{{interface|name}}_{{method|name}}_name, | 106 } |
126 -1, | 107 {% else %} |
127 bindings.MessageHeader.kMessageExpectsResponse); | 108 {%- set response_struct = method|response_struct_from_method %} |
128 } | 109 {%- set request_struct = method|struct_from_method %} |
129 {%- endif %} | 110 Future<{{response_struct|name}}> {{method|name}}( |
130 {%- endfor %} | 111 {%- for parameter in method.parameters -%} |
| 112 {{parameter.kind|dart_type}} {{parameter|name}}, |
| 113 {%- endfor -%} |
| 114 [Function responseFactory = null]) { |
| 115 var params = new {{request_struct|name}}(); |
| 116 {%- for parameter in method.parameters %} |
| 117 params.{{parameter|name}} = {{parameter|name}}; |
| 118 {%- endfor %} |
| 119 return _proxyImpl.sendMessageWithRequestId( |
| 120 params, |
| 121 k{{interface|name}}_{{method|name}}_name, |
| 122 -1, |
| 123 bindings.MessageHeader.kMessageExpectsResponse); |
| 124 } |
| 125 {%- endif %} |
| 126 {%- endfor %} |
131 } | 127 } |
132 | 128 |
| 129 |
| 130 void {{interface|name}}ProxyClose({{interface|name}}Proxy proxy) { |
| 131 assert(proxy != null); |
| 132 proxy._proxyImpl.close(); |
| 133 } |
| 134 |
| 135 |
| 136 void {{interface|name}}ProxyBind({{interface|name}}Proxy proxy, |
| 137 core.MojoMessagePipeEndpoint endpoint) { |
| 138 assert(proxy != null); |
| 139 proxy._proxyImpl.bind(endpoint); |
| 140 } |
| 141 |
| 142 |
| 143 bindings.Proxy {{interface|name}}Request({{interface|name}}Proxy proxy) { |
| 144 assert(!proxy._proxyImpl.isBound); |
| 145 return proxy._proxyImpl; |
| 146 } |
| 147 |
| 148 |
| 149 bool {{interface|name}}IsBound({{interface|name}}Proxy proxy) { |
| 150 return proxy._proxyImpl.isBound; |
| 151 } |
| 152 |
| 153 |
| 154 bindings.Proxy {{interface|name}}GetProxyImpl({{interface|name}}Proxy proxy) { |
| 155 return proxy._proxyImpl; |
| 156 } |
| 157 |
| 158 |
133 class {{interface|name}}Stub extends bindings.Stub { | 159 class {{interface|name}}Stub extends bindings.Stub { |
134 {{interface|name}} _delegate = null; | 160 {{interface|name}} _delegate = null; |
135 | 161 |
136 {{interface|name}}Stub(core.MojoMessagePipeEndpoint endpoint) : super(endpoint
); | 162 {{interface|name}}Stub.fromEndpoint(core.MojoMessagePipeEndpoint endpoint) : |
| 163 super(endpoint); |
137 | 164 |
138 {{interface|name}}Stub.fromHandle(core.MojoHandle handle) : | 165 {{interface|name}}Stub.fromHandle(core.MojoHandle handle) : |
139 super.fromHandle(handle); | 166 super.fromHandle(handle); |
140 | 167 |
141 {{interface|name}}Stub.unbound() : super.unbound(); | 168 {{interface|name}}Stub.unbound() : super.unbound(); |
142 | 169 |
143 static {{interface|name}}Stub newFromEndpoint( | 170 static {{interface|name}}Stub newFromEndpoint( |
144 core.MojoMessagePipeEndpoint endpoint) => | 171 core.MojoMessagePipeEndpoint endpoint) => |
145 new {{interface|name}}Stub(endpoint); | 172 new {{interface|name}}Stub.fromEndpoint(endpoint); |
146 | 173 |
147 static const String name = {{interface|name}}.name; | 174 static const String name = {{interface|name}}Name; |
148 | 175 |
149 {% for method in interface.methods %} | 176 {% for method in interface.methods %} |
150 {%- if method.response_parameters != None %} | 177 {%- if method.response_parameters != None %} |
151 {%- set response_struct = method|response_struct_from_method %} | 178 {%- set response_struct = method|response_struct_from_method %} |
152 {{response_struct|name}} _{{response_struct|name}}Factory( | 179 {{response_struct|name}} _{{response_struct|name}}Factory( |
153 {%- for param in method.response_parameters -%} | 180 {%- for param in method.response_parameters -%} |
154 {{param.kind|dart_type}} {{param|name}}{% if not loop.last %}, {% endif %} | 181 {{param.kind|dart_type}} {{param|name}}{% if not loop.last %}, {% endif %} |
155 {%- endfor -%} | 182 {%- endfor -%} |
156 ) { | 183 ) { |
157 var result = new {{response_struct|name}}(); | 184 var result = new {{response_struct|name}}(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } | 228 } |
202 return null; | 229 return null; |
203 } | 230 } |
204 | 231 |
205 {{interface|name}} get delegate => _delegate; | 232 {{interface|name}} get delegate => _delegate; |
206 set delegate({{interface|name}} d) { | 233 set delegate({{interface|name}} d) { |
207 assert(_delegate == null); | 234 assert(_delegate == null); |
208 _delegate = d; | 235 _delegate = d; |
209 } | 236 } |
210 } | 237 } |
211 | |
212 | |
213 {#--- TODO(zra): Validation #} | |
214 | |
215 | |
OLD | NEW |