OLD | NEW |
1 {%- import "interface_macros.tmpl" as interface_macros %} | 1 {%- import "interface_macros.tmpl" as interface_macros %} |
2 {%- import "struct_macros.tmpl" as struct_macros %} | 2 {%- import "struct_macros.tmpl" as struct_macros %} |
3 {%- set class_name = interface.name %} | 3 {%- set class_name = interface.name %} |
4 {%- set proxy_name = interface.name ~ "Proxy" %} | 4 {%- set proxy_name = interface.name ~ "Proxy" %} |
5 {%- set namespace_as_string = "%s"|format(namespace|replace(".","::")) %} | 5 {%- set namespace_as_string = "%s"|format(namespace|replace(".","::")) %} |
6 | 6 |
7 {%- macro alloc_params(struct) %} | 7 {%- macro alloc_params(struct) %} |
8 {%- for param in struct.packed.packed_fields_in_ordinal_order %} | 8 {%- for param in struct.packed.packed_fields_in_ordinal_order %} |
9 {{param.field.kind|cpp_result_type}} p_{{param.field.name}}{}; | 9 {{param.field.kind|cpp_result_type}} p_{{param.field.name}}{}; |
10 {%- endfor %} | 10 {%- endfor %} |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 {%- if method.response_parameters != None %} | 108 {%- if method.response_parameters != None %} |
109 {%- set message_name = | 109 {%- set message_name = |
110 "internal::k%s_%s_Name"|format(interface.name, method.name) %} | 110 "internal::k%s_%s_Name"|format(interface.name, method.name) %} |
111 {%- set response_params_struct = method|response_struct_from_method %} | 111 {%- set response_params_struct = method|response_struct_from_method %} |
112 {%- set params_description = | 112 {%- set params_description = |
113 "%s.%s response"|format(interface.name, method.name) %} | 113 "%s.%s response"|format(interface.name, method.name) %} |
114 class {{class_name}}_{{method.name}}_ProxyToResponder | 114 class {{class_name}}_{{method.name}}_ProxyToResponder |
115 : public {{class_name}}::{{method.name}}Callback::Runnable { | 115 : public {{class_name}}::{{method.name}}Callback::Runnable { |
116 public: | 116 public: |
117 virtual ~{{class_name}}_{{method.name}}_ProxyToResponder() { | 117 virtual ~{{class_name}}_{{method.name}}_ProxyToResponder() { |
| 118 // Is the Mojo application destroying the callback without running it |
| 119 // and without first closing the pipe? |
| 120 bool callback_was_dropped = responder_ && responder_->IsValid(); |
| 121 // If the Callback was dropped then deleting the responder will close |
| 122 // the pipe so the calling application knows to stop waiting for a reply. |
118 delete responder_; | 123 delete responder_; |
119 // TODO(rudominer) DCHECK if |was_run_| is false and we don't have evidence | 124 MOJO_DCHECK(!callback_was_dropped) << "The callback passed to " |
120 // that we are in a legitamte shutdown case such as the Connector detected | 125 "{{class_name}}::{{method.name}}({%- if method.parameters -%}{{pass_para
ms(method.parameters)}}, {% endif -%}callback) " |
121 // an error or Close() was invoked. | 126 "was never run."; |
122 } | 127 } |
123 | 128 |
124 {{class_name}}_{{method.name}}_ProxyToResponder( | 129 {{class_name}}_{{method.name}}_ProxyToResponder( |
125 uint64_t request_id, | 130 uint64_t request_id, |
126 mojo::MessageReceiver* responder) | 131 mojo::MessageReceiverWithStatus* responder) |
127 : request_id_(request_id), | 132 : request_id_(request_id), |
128 responder_(responder), | 133 responder_(responder) { |
129 was_run_(false) { | |
130 } | 134 } |
131 | 135 |
132 void Run({{interface_macros.declare_params("in_", method.response_parameters)}
}) const override; | 136 void Run({{interface_macros.declare_params("in_", method.response_parameters)}
}) const override; |
133 | 137 |
134 private: | 138 private: |
135 uint64_t request_id_; | 139 uint64_t request_id_; |
136 mutable mojo::MessageReceiver* responder_; | 140 mutable mojo::MessageReceiverWithStatus* responder_; |
137 mutable bool was_run_; | |
138 MOJO_DISALLOW_COPY_AND_ASSIGN({{class_name}}_{{method.name}}_ProxyToResponder)
; | 141 MOJO_DISALLOW_COPY_AND_ASSIGN({{class_name}}_{{method.name}}_ProxyToResponder)
; |
139 }; | 142 }; |
140 void {{class_name}}_{{method.name}}_ProxyToResponder::Run( | 143 void {{class_name}}_{{method.name}}_ProxyToResponder::Run( |
141 {{interface_macros.declare_params("in_", method.response_parameters)}}) cons
t { | 144 {{interface_macros.declare_params("in_", method.response_parameters)}}) cons
t { |
142 was_run_ = true; | |
143 {{struct_macros.get_serialized_size(response_params_struct, "in_%s")}} | 145 {{struct_macros.get_serialized_size(response_params_struct, "in_%s")}} |
144 mojo::internal::ResponseMessageBuilder builder( | 146 mojo::internal::ResponseMessageBuilder builder( |
145 {{message_name}}, size, request_id_); | 147 {{message_name}}, size, request_id_); |
146 {{build_message(response_params_struct, params_description)}} | 148 {{build_message(response_params_struct, params_description)}} |
147 bool ok = responder_->Accept(&message); | 149 bool ok = responder_->Accept(&message); |
148 MOJO_ALLOW_UNUSED_LOCAL(ok); | 150 MOJO_ALLOW_UNUSED_LOCAL(ok); |
149 // TODO(darin): !ok returned here indicates a malformed message, and that may | 151 // TODO(darin): !ok returned here indicates a malformed message, and that may |
150 // be good reason to close the connection. However, we don't have a way to do | 152 // be good reason to close the connection. However, we don't have a way to do |
151 // that from here. We should add a way. | 153 // that from here. We should add a way. |
152 delete responder_; | 154 delete responder_; |
153 responder_ = nullptr; | 155 responder_ = nullptr; |
154 } | 156 } |
155 {%- endif -%} | 157 {%- endif -%} |
156 {%- endfor %} | 158 {%- endfor %} |
157 | 159 |
158 {{class_name}}Stub::{{class_name}}Stub() | 160 {{class_name}}Stub::{{class_name}}Stub() |
159 : sink_(nullptr) { | 161 : sink_(nullptr) { |
160 } | 162 } |
161 | 163 |
| 164 {{class_name}}Stub::~{{interface.name}}Stub() {} |
| 165 |
162 {#--- Stub definition #} | 166 {#--- Stub definition #} |
163 | 167 |
164 bool {{class_name}}Stub::Accept(mojo::Message* message) { | 168 bool {{class_name}}Stub::Accept(mojo::Message* message) { |
165 {%- if interface.methods %} | 169 {%- if interface.methods %} |
166 switch (message->header()->name) { | 170 switch (message->header()->name) { |
167 {%- for method in interface.methods %} | 171 {%- for method in interface.methods %} |
168 case internal::k{{class_name}}_{{method.name}}_Name: { | 172 case internal::k{{class_name}}_{{method.name}}_Name: { |
169 {%- if method.response_parameters == None %} | 173 {%- if method.response_parameters == None %} |
170 internal::{{class_name}}_{{method.name}}_Params_Data* params = | 174 internal::{{class_name}}_{{method.name}}_Params_Data* params = |
171 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data*
>( | 175 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data*
>( |
172 message->mutable_payload()); | 176 message->mutable_payload()); |
173 | 177 |
174 params->DecodePointersAndHandles(message->mutable_handles()); | 178 params->DecodePointersAndHandles(message->mutable_handles()); |
175 {{alloc_params(method|struct_from_method)|indent(4)}} | 179 {{alloc_params(method|struct_from_method)|indent(4)}} |
176 // A null |sink_| means no implementation was bound. | 180 // A null |sink_| means no implementation was bound. |
177 assert(sink_); | 181 assert(sink_); |
178 sink_->{{method.name}}({{pass_params(method.parameters)}}); | 182 sink_->{{method.name}}({{pass_params(method.parameters)}}); |
179 return true; | 183 return true; |
180 {%- else %} | 184 {%- else %} |
181 break; | 185 break; |
182 {%- endif %} | 186 {%- endif %} |
183 } | 187 } |
184 {%- endfor %} | 188 {%- endfor %} |
185 } | 189 } |
186 {%- endif %} | 190 {%- endif %} |
187 return false; | 191 return false; |
188 } | 192 } |
189 | 193 |
190 bool {{class_name}}Stub::AcceptWithResponder( | 194 bool {{class_name}}Stub::AcceptWithResponder( |
191 mojo::Message* message, mojo::MessageReceiver* responder) { | 195 mojo::Message* message, mojo::MessageReceiverWithStatus* responder) { |
192 {%- if interface.methods %} | 196 {%- if interface.methods %} |
193 switch (message->header()->name) { | 197 switch (message->header()->name) { |
194 {%- for method in interface.methods %} | 198 {%- for method in interface.methods %} |
195 case internal::k{{class_name}}_{{method.name}}_Name: { | 199 case internal::k{{class_name}}_{{method.name}}_Name: { |
196 {%- if method.response_parameters != None %} | 200 {%- if method.response_parameters != None %} |
197 internal::{{class_name}}_{{method.name}}_Params_Data* params = | 201 internal::{{class_name}}_{{method.name}}_Params_Data* params = |
198 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data*
>( | 202 reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data*
>( |
199 message->mutable_payload()); | 203 message->mutable_payload()); |
200 | 204 |
201 params->DecodePointersAndHandles(message->mutable_handles()); | 205 params->DecodePointersAndHandles(message->mutable_handles()); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD); | 307 mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD); |
304 return false; | 308 return false; |
305 } | 309 } |
306 } | 310 } |
307 {%- endif %} | 311 {%- endif %} |
308 | 312 |
309 assert(sink_); | 313 assert(sink_); |
310 return sink_->Accept(message); | 314 return sink_->Accept(message); |
311 } | 315 } |
312 {%- endif -%} | 316 {%- endif -%} |
OLD | NEW |