Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Unified Diff: mojo/public/tools/bindings/generators/cpp_templates/interface_stub_declaration.tmpl

Issue 2403533003: Mojo C++ Bindings: Support custom impl ref types (Closed)
Patch Set: nit, move Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_;
};

Powered by Google App Engine
This is Rietveld 408576698