Commit 3618dd34 authored by yzshen's avatar yzshen Committed by Commit bot

Mojo C++ bindings: add a MakeRequest overload that binds InterfacePtrInfo.

BUG=None

Review-Url: https://codereview.chromium.org/2855303003
Cr-Commit-Position: refs/heads/master@{#469448}
parent 20b49d7b
......@@ -31,10 +31,10 @@ namespace mojo {
// to a message pipe. All calls to this class or the proxy should be from the
// same thread that bound it. If you need to move the proxy to a different
// thread, extract the InterfacePtrInfo (containing just the message pipe and
// any version information) using PassInterface(), pass it to a different
// thread, and create and bind a new InterfacePtr from that thread. If an
// InterfacePtr is not bound to a message pipe, it may be bound or destroyed on
// any thread.
// any version information) using PassInterface() on the original thread, pass
// it to a different thread, and create and bind a new InterfacePtr from that
// thread. If an InterfacePtr is not bound to a message pipe, it may be bound or
// destroyed on any thread.
template <typename Interface>
class InterfacePtr {
public:
......
......@@ -46,6 +46,15 @@ class InterfaceRequest {
Bind(std::move(pipe.handle1));
}
// Similar to the constructor above, but binds one end of the message pipe to
// an InterfacePtrInfo instance.
explicit InterfaceRequest(InterfacePtrInfo<Interface>* ptr_info) {
MessagePipe pipe;
ptr_info->set_handle(std::move(pipe.handle0));
ptr_info->set_version(0u);
Bind(std::move(pipe.handle1));
}
// Takes the message pipe from another InterfaceRequest.
InterfaceRequest(InterfaceRequest&& other) {
handle_ = std::move(other.handle_);
......@@ -163,6 +172,13 @@ InterfaceRequest<Interface> MakeRequest(
return InterfaceRequest<Interface>(ptr, runner);
}
// Similar to the constructor above, but binds one end of the message pipe to
// an InterfacePtrInfo instance.
template <typename Interface>
InterfaceRequest<Interface> MakeRequest(InterfacePtrInfo<Interface>* ptr_info) {
return InterfaceRequest<Interface>(ptr_info);
}
// Fuses an InterfaceRequest<T> endpoint with an InterfacePtrInfo<T> endpoint.
// Returns |true| on success or |false| on failure.
template <typename Interface>
......
......@@ -704,15 +704,15 @@ class PingTestImpl : public sample::PingTest {
// Tests that FuseProxy does what it's supposed to do.
TEST_F(InterfacePtrTest, Fusion) {
sample::PingTestPtr proxy;
PingTestImpl impl(MakeRequest(&proxy));
sample::PingTestPtrInfo proxy_info;
PingTestImpl impl(MakeRequest(&proxy_info));
// Create another PingTest pipe.
sample::PingTestPtr ptr;
sample::PingTestRequest request(&ptr);
// Fuse the new pipe to the one hanging off |impl|.
EXPECT_TRUE(FuseInterface(std::move(request), proxy.PassInterface()));
EXPECT_TRUE(FuseInterface(std::move(request), std::move(proxy_info)));
// Ping!
bool called = false;
......
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