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 {
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> {
public:
virtual void OnConnectionError() MOJO_OVERRIDE {
......@@ -75,6 +93,9 @@ class SampleFactoryImpl : public InterfaceImpl<sample::Factory> {
response->x = 2;
response->pipe = pipe0.Pass();
client()->DidStuff(response.Pass(), text1);
if (request->obj.get())
request->obj->DoSomething();
}
virtual void DoStuff2(ScopedDataPipeConsumerHandle pipe) MOJO_OVERRIDE {
......@@ -194,16 +215,22 @@ TEST_F(HandlePassingTest, Basic) {
MessagePipe pipe1;
EXPECT_TRUE(WriteTextMessage(pipe1.handle1.get(), kText2));
imported::ImportedInterfacePtr imported;
BindToProxy(new ImportedInterfaceImpl(), &imported);
sample::RequestPtr request(sample::Request::New());
request->x = 1;
request->pipe = pipe1.handle0.Pass();
request->obj = imported.Pass();
factory->DoStuff(request.Pass(), pipe0.handle0.Pass());
EXPECT_FALSE(factory_client.got_response());
int count_before = ImportedInterfaceImpl::do_something_count();
PumpMessages();
EXPECT_TRUE(factory_client.got_response());
EXPECT_EQ(1, ImportedInterfaceImpl::do_something_count() - count_before);
}
TEST_F(HandlePassingTest, PassInvalid) {
......
......@@ -14,6 +14,9 @@ struct Request {
int32 x;
handle<message_pipe> pipe;
handle<message_pipe>[] more_pipes;
// Interfaces can be used as members.
imported.ImportedInterface obj;
};
struct Response {
......
......@@ -20,6 +20,7 @@ struct Point {
};
interface ImportedInterface {
DoSomething();
};
} // module imported
......@@ -16,6 +16,8 @@ void Serialize_({{struct.name}}Ptr input, mojo::internal::Buffer* buf,
{%- for pf in struct.packed.packed_fields %}
{%- if pf.field.kind|is_object_kind %}
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 %}
result->{{pf.field.name}} = input->{{pf.field.name}}.release();
{%- else %}
......@@ -35,6 +37,9 @@ void Deserialize_(internal::{{struct.name}}_Data* input,
{%- for pf in struct.packed.packed_fields %}
{%- if pf.field.kind|is_object_kind %}
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 %}
result->{{pf.field.name}}.reset(mojo::internal::FetchAndReset(&input->{{pf.field.name}}));
{%- elif pf.field.kind|is_enum_kind %}
......
......@@ -128,7 +128,7 @@ def GetCppWrapperType(kind):
if isinstance(kind, (mojom.Array, mojom.FixedArray)):
return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind)
if isinstance(kind, mojom.Interface):
return "mojo::ScopedMessagePipeHandle"
return "%sPtr" % GetNameForKind(kind)
if isinstance(kind, mojom.InterfaceRequest):
raise Exception("InterfaceRequest fields not supported!")
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