Commit 5456e86f authored by darin@chromium.org's avatar darin@chromium.org

Mojo: Add support for InterfacePtr as a struct member

BUG=392693

Review URL: https://codereview.chromium.org/376383002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282555 0039d316-1c4b-4281-b951-d872f2087c98
parent 2b6eb3da
...@@ -26,6 +26,24 @@ class StringRecorder { ...@@ -26,6 +26,24 @@ class StringRecorder {
std::string* buf_; std::string* buf_;
}; };
class ImportedInterfaceImpl
: public InterfaceImpl<imported::ImportedInterface> {
public:
virtual void OnConnectionError() MOJO_OVERRIDE {
delete this;
}
virtual void DoSomething() MOJO_OVERRIDE {
do_something_count_++;
}
static int do_something_count() { return do_something_count_; }
private:
static int do_something_count_;
};
int ImportedInterfaceImpl::do_something_count_ = 0;
class SampleNamedObjectImpl : public InterfaceImpl<sample::NamedObject> { class SampleNamedObjectImpl : public InterfaceImpl<sample::NamedObject> {
public: public:
virtual void OnConnectionError() MOJO_OVERRIDE { virtual void OnConnectionError() MOJO_OVERRIDE {
...@@ -75,6 +93,9 @@ class SampleFactoryImpl : public InterfaceImpl<sample::Factory> { ...@@ -75,6 +93,9 @@ class SampleFactoryImpl : public InterfaceImpl<sample::Factory> {
response->x = 2; response->x = 2;
response->pipe = pipe0.Pass(); response->pipe = pipe0.Pass();
client()->DidStuff(response.Pass(), text1); client()->DidStuff(response.Pass(), text1);
if (request->obj.get())
request->obj->DoSomething();
} }
virtual void DoStuff2(ScopedDataPipeConsumerHandle pipe) MOJO_OVERRIDE { virtual void DoStuff2(ScopedDataPipeConsumerHandle pipe) MOJO_OVERRIDE {
...@@ -194,16 +215,22 @@ TEST_F(HandlePassingTest, Basic) { ...@@ -194,16 +215,22 @@ TEST_F(HandlePassingTest, Basic) {
MessagePipe pipe1; MessagePipe pipe1;
EXPECT_TRUE(WriteTextMessage(pipe1.handle1.get(), kText2)); EXPECT_TRUE(WriteTextMessage(pipe1.handle1.get(), kText2));
imported::ImportedInterfacePtr imported;
BindToProxy(new ImportedInterfaceImpl(), &imported);
sample::RequestPtr request(sample::Request::New()); sample::RequestPtr request(sample::Request::New());
request->x = 1; request->x = 1;
request->pipe = pipe1.handle0.Pass(); request->pipe = pipe1.handle0.Pass();
request->obj = imported.Pass();
factory->DoStuff(request.Pass(), pipe0.handle0.Pass()); factory->DoStuff(request.Pass(), pipe0.handle0.Pass());
EXPECT_FALSE(factory_client.got_response()); EXPECT_FALSE(factory_client.got_response());
int count_before = ImportedInterfaceImpl::do_something_count();
PumpMessages(); PumpMessages();
EXPECT_TRUE(factory_client.got_response()); EXPECT_TRUE(factory_client.got_response());
EXPECT_EQ(1, ImportedInterfaceImpl::do_something_count() - count_before);
} }
TEST_F(HandlePassingTest, PassInvalid) { TEST_F(HandlePassingTest, PassInvalid) {
......
...@@ -14,6 +14,9 @@ struct Request { ...@@ -14,6 +14,9 @@ struct Request {
int32 x; int32 x;
handle<message_pipe> pipe; handle<message_pipe> pipe;
handle<message_pipe>[] more_pipes; handle<message_pipe>[] more_pipes;
// Interfaces can be used as members.
imported.ImportedInterface obj;
}; };
struct Response { struct Response {
......
...@@ -20,6 +20,7 @@ struct Point { ...@@ -20,6 +20,7 @@ struct Point {
}; };
interface ImportedInterface { interface ImportedInterface {
DoSomething();
}; };
} // module imported } // module imported
...@@ -16,6 +16,8 @@ void Serialize_({{struct.name}}Ptr input, mojo::internal::Buffer* buf, ...@@ -16,6 +16,8 @@ void Serialize_({{struct.name}}Ptr input, mojo::internal::Buffer* buf,
{%- for pf in struct.packed.packed_fields %} {%- for pf in struct.packed.packed_fields %}
{%- if pf.field.kind|is_object_kind %} {%- if pf.field.kind|is_object_kind %}
Serialize_(mojo::internal::Forward(input->{{pf.field.name}}), buf, &result->{{pf.field.name}}.ptr); Serialize_(mojo::internal::Forward(input->{{pf.field.name}}), buf, &result->{{pf.field.name}}.ptr);
{%- elif pf.field.kind|is_interface_kind %}
result->{{pf.field.name}} = input->{{pf.field.name}}.PassMessagePipe().release();
{%- elif pf.field.kind|is_handle_kind %} {%- elif pf.field.kind|is_handle_kind %}
result->{{pf.field.name}} = input->{{pf.field.name}}.release(); result->{{pf.field.name}} = input->{{pf.field.name}}.release();
{%- else %} {%- else %}
...@@ -35,6 +37,9 @@ void Deserialize_(internal::{{struct.name}}_Data* input, ...@@ -35,6 +37,9 @@ void Deserialize_(internal::{{struct.name}}_Data* input,
{%- for pf in struct.packed.packed_fields %} {%- for pf in struct.packed.packed_fields %}
{%- if pf.field.kind|is_object_kind %} {%- if pf.field.kind|is_object_kind %}
Deserialize_(input->{{pf.field.name}}.ptr, &result->{{pf.field.name}}); Deserialize_(input->{{pf.field.name}}.ptr, &result->{{pf.field.name}});
{%- elif pf.field.kind|is_interface_kind %}
if (input->{{pf.field.name}}.is_valid())
result->{{pf.field.name}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(&input->{{pf.field.name}})));
{%- elif pf.field.kind|is_handle_kind %} {%- elif pf.field.kind|is_handle_kind %}
result->{{pf.field.name}}.reset(mojo::internal::FetchAndReset(&input->{{pf.field.name}})); result->{{pf.field.name}}.reset(mojo::internal::FetchAndReset(&input->{{pf.field.name}}));
{%- elif pf.field.kind|is_enum_kind %} {%- elif pf.field.kind|is_enum_kind %}
......
...@@ -128,7 +128,7 @@ def GetCppWrapperType(kind): ...@@ -128,7 +128,7 @@ def GetCppWrapperType(kind):
if isinstance(kind, (mojom.Array, mojom.FixedArray)): if isinstance(kind, (mojom.Array, mojom.FixedArray)):
return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind)
if isinstance(kind, mojom.Interface): if isinstance(kind, mojom.Interface):
return "mojo::ScopedMessagePipeHandle" return "%sPtr" % GetNameForKind(kind)
if isinstance(kind, mojom.InterfaceRequest): if isinstance(kind, mojom.InterfaceRequest):
raise Exception("InterfaceRequest fields not supported!") raise Exception("InterfaceRequest fields not supported!")
if kind.spec == 's': if kind.spec == 's':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment