Index: mojo/public/tools/bindings/generators/cpp_templates/interface_stub_declaration.tmpl |
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/interface_stub_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/interface_stub_declaration.tmpl |
index 8f1a45c3f43c0f0f7e637c80402d354f664b192e..a8296b71fe9ebf762d4f4847bfa7f113c42882e9 100644 |
--- a/mojo/public/tools/bindings/generators/cpp_templates/interface_stub_declaration.tmpl |
+++ b/mojo/public/tools/bindings/generators/cpp_templates/interface_stub_declaration.tmpl |
@@ -1,18 +1,49 @@ |
-class {{export_attribute}} {{interface.name}}Stub : public NON_EXPORTED_BASE(mojo::MessageReceiverWithResponderStatus) { |
+class {{export_attribute}} {{interface.name}}StubDispatch { |
public: |
- {{interface.name}}Stub(); |
- ~{{interface.name}}Stub() override; |
- void set_sink({{interface.name}}* sink) { sink_ = sink; } |
- {{interface.name}}* sink() { return sink_; } |
+ static bool Accept({{interface.name}}* impl, |
+ mojo::internal::SerializationContext* context, |
+ mojo::Message* message); |
+ static bool AcceptWithResponder({{interface.name}}* impl, |
+ mojo::internal::SerializationContext* context, |
+ mojo::Message* message, |
+ mojo::MessageReceiverWithStatus* responder); |
+}; |
+ |
+template <typename ImplRefTraits = |
+ mojo::RawPtrImplRefTraits<{{interface.name}}>> |
+class {{interface.name}}Stub |
+ : public NON_EXPORTED_BASE(mojo::MessageReceiverWithResponderStatus) { |
+ public: |
+ using ImplPointerType = typename ImplRefTraits::PointerType; |
+ |
+ {{interface.name}}Stub() {} |
+ ~{{interface.name}}Stub() override {} |
+ |
+ void set_sink(ImplPointerType sink) { sink_ = std::move(sink); } |
+ ImplPointerType& sink() { return sink_; } |
+ |
mojo::internal::SerializationContext* serialization_context() { |
return &serialization_context_; |
} |
- bool Accept(mojo::Message* message) override; |
- bool AcceptWithResponder(mojo::Message* message, |
- mojo::MessageReceiverWithStatus* responder) override; |
+ bool Accept(mojo::Message* message) override { |
+ if (ImplRefTraits::IsNull(sink_)) |
+ return false; |
+ return {{interface.name}}StubDispatch::Accept( |
+ ImplRefTraits::GetRawPointer(&sink_), &serialization_context_, message); |
+ } |
+ |
+ bool AcceptWithResponder( |
+ mojo::Message* message, |
+ mojo::MessageReceiverWithStatus* responder) override { |
+ if (ImplRefTraits::IsNull(sink_)) |
+ return false; |
+ return {{interface.name}}StubDispatch::AcceptWithResponder( |
+ ImplRefTraits::GetRawPointer(&sink_), &serialization_context_, message, |
+ responder); |
+ } |
private: |
- {{interface.name}}* sink_; |
+ ImplPointerType sink_; |
mojo::internal::SerializationContext serialization_context_; |
}; |