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