summaryrefslogtreecommitdiffstats
path: root/mojo/public
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-07 22:41:53 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-07 22:41:53 +0000
commitc8826725c7d1fe6a5cf8d46eae51b226ec4a2359 (patch)
tree4f27fb6424541152472b9b10e6a010d1fe87649c /mojo/public
parent37ae8a4ebc0593bc0fb8704f5b070b6686f61f02 (diff)
downloadchromium_src-c8826725c7d1fe6a5cf8d46eae51b226ec4a2359.zip
chromium_src-c8826725c7d1fe6a5cf8d46eae51b226ec4a2359.tar.gz
chromium_src-c8826725c7d1fe6a5cf8d46eae51b226ec4a2359.tar.bz2
Mojo: abstract interface implementation from generated Stub classes
Remove RemotePtr<S>::SetPeer method in favor of an optionally NULL second constructor argument. (The reset method also gains an optionally NULL second argument.) R=davemoore@chromium.org Review URL: https://codereview.chromium.org/109103003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243416 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/public')
-rw-r--r--mojo/public/bindings/generators/cpp_templates/interface_definition.tmpl6
-rw-r--r--mojo/public/bindings/generators/cpp_templates/interface_stub_declaration.tmpl7
-rw-r--r--mojo/public/bindings/lib/remote_ptr.h29
-rw-r--r--mojo/public/bindings/sample/sample_service_unittests.cc6
-rw-r--r--mojo/public/tests/bindings_handle_passing_unittest.cc10
-rw-r--r--mojo/public/tests/bindings_remote_ptr_unittest.cc14
6 files changed, 38 insertions, 34 deletions
diff --git a/mojo/public/bindings/generators/cpp_templates/interface_definition.tmpl b/mojo/public/bindings/generators/cpp_templates/interface_definition.tmpl
index 3ca8b46..9885a36 100644
--- a/mojo/public/bindings/generators/cpp_templates/interface_definition.tmpl
+++ b/mojo/public/bindings/generators/cpp_templates/interface_definition.tmpl
@@ -55,6 +55,10 @@ void {{proxy_name}}::{{method.name}}({{params_list(method)}}) {
}
{%- endfor %}
+{{class_name}}Stub::{{class_name}}Stub({{class_name}}* sink)
+ : sink_(sink) {
+}
+
{#--- Stub definition #}
{%- macro params(method) %}
{%- for param in method.parameters %}
@@ -79,7 +83,7 @@ bool {{class_name}}Stub::Accept(mojo::Message* message) {
if (!mojo::internal::DecodePointersAndHandles(params, message))
return false;
- {{method.name}}({{params(method)}});
+ sink_->{{method.name}}({{params(method)}});
mojo::internal::CloseHandles(params);
break;
}
diff --git a/mojo/public/bindings/generators/cpp_templates/interface_stub_declaration.tmpl b/mojo/public/bindings/generators/cpp_templates/interface_stub_declaration.tmpl
index c4e3d1f..a01c5f4 100644
--- a/mojo/public/bindings/generators/cpp_templates/interface_stub_declaration.tmpl
+++ b/mojo/public/bindings/generators/cpp_templates/interface_stub_declaration.tmpl
@@ -1,4 +1,9 @@
-class {{interface.name}}Stub : public {{interface.name}}, public mojo::MessageReceiver {
+class {{interface.name}}Stub : public mojo::MessageReceiver {
public:
+ explicit {{interface.name}}Stub({{interface.name}}* sink);
+
virtual bool Accept(mojo::Message* message) MOJO_OVERRIDE;
+
+ private:
+ {{interface.name}}* sink_;
};
diff --git a/mojo/public/bindings/lib/remote_ptr.h b/mojo/public/bindings/lib/remote_ptr.h
index 3b57594..a0c42e3 100644
--- a/mojo/public/bindings/lib/remote_ptr.h
+++ b/mojo/public/bindings/lib/remote_ptr.h
@@ -22,8 +22,7 @@ namespace mojo {
// class FooClientImpl : public FooClientStub {
// public:
// explicit FooClientImpl(const mojo::MessagePipeHandle& message_pipe)
-// : foo_(message_pipe) {
-// foo_.SetPeer(this);
+// : foo_(message_pipe, this) {
// foo_.Ping();
// }
// virtual void Pong() {
@@ -38,8 +37,7 @@ namespace mojo {
// class FooImpl : public FooStub {
// public:
// explicit FooImpl(const mojo::MessagePipeHandle& message_pipe)
-// : client_(message_pipe) {
-// client_.SetPeer(this);
+// : client_(message_pipe, this) {
// }
// virtual void Ping() {
// client_->Pong();
@@ -54,8 +52,9 @@ class RemotePtr {
public:
RemotePtr() : state_(NULL) {}
- explicit RemotePtr(ScopedMessagePipeHandle message_pipe)
- : state_(new State(message_pipe.Pass())) {
+ explicit RemotePtr(ScopedMessagePipeHandle message_pipe,
+ typename S::_Peer* peer = NULL)
+ : state_(new State(message_pipe.Pass(), peer)) {
}
// Move-only constructor and operator=.
@@ -87,9 +86,10 @@ class RemotePtr {
state_ = NULL;
}
- void reset(ScopedMessagePipeHandle message_pipe) {
+ void reset(ScopedMessagePipeHandle message_pipe,
+ typename S::_Peer* peer = NULL) {
delete state_;
- state_ = new State(message_pipe.Pass());
+ state_ = new State(message_pipe.Pass(), peer);
}
bool encountered_error() const {
@@ -97,19 +97,18 @@ class RemotePtr {
return state_->connector.encountered_error();
}
- void SetPeer(typename S::_Peer::_Stub* peer) {
- assert(state_);
- state_->connector.SetIncomingReceiver(peer);
- }
-
private:
struct State {
- State(ScopedMessagePipeHandle message_pipe)
+ State(ScopedMessagePipeHandle message_pipe, typename S::_Peer* peer)
: connector(message_pipe.Pass()),
- proxy(&connector) {
+ proxy(&connector),
+ stub(peer) {
+ if (peer)
+ connector.SetIncomingReceiver(&stub);
}
internal::Connector connector;
typename S::_Proxy proxy;
+ typename S::_Peer::_Stub stub;
};
State* release() {
diff --git a/mojo/public/bindings/sample/sample_service_unittests.cc b/mojo/public/bindings/sample/sample_service_unittests.cc
index 0588a11..8670441 100644
--- a/mojo/public/bindings/sample/sample_service_unittests.cc
+++ b/mojo/public/bindings/sample/sample_service_unittests.cc
@@ -238,7 +238,7 @@ static void DumpHex(const uint8_t* bytes, uint32_t num_bytes) {
}
}
-class ServiceImpl : public ServiceStub {
+class ServiceImpl : public Service {
public:
virtual void Frobinate(const Foo& foo, int32_t baz,
mojo::ScopedMessagePipeHandle port)
@@ -273,8 +273,8 @@ class SimpleMessageReceiver : public mojo::MessageReceiver {
// the system. It receives the incoming message.
ServiceImpl impl;
- ServiceStub* stub = &impl;
- return stub->Accept(message);
+ ServiceStub stub(&impl);
+ return stub.Accept(message);
}
};
diff --git a/mojo/public/tests/bindings_handle_passing_unittest.cc b/mojo/public/tests/bindings_handle_passing_unittest.cc
index df27359..2f687de 100644
--- a/mojo/public/tests/bindings_handle_passing_unittest.cc
+++ b/mojo/public/tests/bindings_handle_passing_unittest.cc
@@ -15,11 +15,10 @@ namespace {
const char kText1[] = "hello";
const char kText2[] = "world";
-class SampleFactoryImpl : public sample::FactoryStub {
+class SampleFactoryImpl : public sample::Factory {
public:
explicit SampleFactoryImpl(ScopedMessagePipeHandle pipe)
- : client_(pipe.Pass()) {
- client_.SetPeer(this);
+ : client_(pipe.Pass(), this) {
}
virtual void DoStuff(const sample::Request& request,
@@ -54,12 +53,11 @@ class SampleFactoryImpl : public sample::FactoryStub {
ScopedMessagePipeHandle pipe1_;
};
-class SampleFactoryClientImpl : public sample::FactoryClientStub {
+class SampleFactoryClientImpl : public sample::FactoryClient {
public:
explicit SampleFactoryClientImpl(ScopedMessagePipeHandle pipe)
- : factory_(pipe.Pass()),
+ : factory_(pipe.Pass(), this),
got_response_(false) {
- factory_.SetPeer(this);
}
void Start() {
diff --git a/mojo/public/tests/bindings_remote_ptr_unittest.cc b/mojo/public/tests/bindings_remote_ptr_unittest.cc
index beada47..0d52224 100644
--- a/mojo/public/tests/bindings_remote_ptr_unittest.cc
+++ b/mojo/public/tests/bindings_remote_ptr_unittest.cc
@@ -10,14 +10,13 @@
namespace mojo {
namespace test {
-class MathCalculatorImpl : public math::CalculatorStub {
+class MathCalculatorImpl : public math::Calculator {
public:
virtual ~MathCalculatorImpl() {}
explicit MathCalculatorImpl(ScopedMessagePipeHandle pipe)
- : ui_(pipe.Pass()),
+ : ui_(pipe.Pass(), this),
total_(0.0) {
- ui_.SetPeer(this);
}
virtual void Clear() MOJO_OVERRIDE {
@@ -39,12 +38,11 @@ class MathCalculatorImpl : public math::CalculatorStub {
double total_;
};
-class MathCalculatorUIImpl : public math::CalculatorUIStub {
+class MathCalculatorUIImpl : public math::CalculatorUI {
public:
explicit MathCalculatorUIImpl(ScopedMessagePipeHandle pipe)
- : calculator_(pipe.Pass()),
+ : calculator_(pipe.Pass(), this),
output_(0.0) {
- calculator_.SetPeer(this);
}
bool encountered_error() const {
@@ -119,7 +117,7 @@ TEST_F(BindingsRemotePtrTest, EndToEnd) {
TEST_F(BindingsRemotePtrTest, Movable) {
RemotePtr<math::Calculator> a;
- RemotePtr<math::Calculator> b(pipe0_.Pass());
+ RemotePtr<math::Calculator> b(pipe0_.Pass(), NULL);
EXPECT_TRUE(a.is_null());
EXPECT_FALSE(b.is_null());
@@ -137,7 +135,7 @@ TEST_F(BindingsRemotePtrTest, Resettable) {
MessagePipeHandle handle = pipe0_.get();
- a.reset(pipe0_.Pass());
+ a.reset(pipe0_.Pass(), NULL);
EXPECT_FALSE(a.is_null());