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