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

Unified Diff: mojo/public/bindings/lib/remote_ptr.h

Issue 66353002: Mojo: RemotePtr<S> + bindings changes for Peer attribute. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase + fix error in sample_service.h Created 7 years, 1 month 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
« no previous file with comments | « mojo/public/bindings/generators/mojom_data.py ('k') | mojo/public/bindings/parser/mojo_translate.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/bindings/lib/remote_ptr.h
diff --git a/mojo/public/bindings/lib/remote_ptr.h b/mojo/public/bindings/lib/remote_ptr.h
new file mode 100644
index 0000000000000000000000000000000000000000..2905992fbb3bad9440e8b3b94c0967200bf40dfc
--- /dev/null
+++ b/mojo/public/bindings/lib/remote_ptr.h
@@ -0,0 +1,77 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_BINDINGS_LIB_REMOTE_PTR_H_
+#define MOJO_PUBLIC_BINDINGS_LIB_REMOTE_PTR_H_
+
+#include "mojo/public/bindings/lib/connector.h"
+
+namespace mojo {
+
+// A RemotePtr is a smart-pointer for managing the connection of a message pipe
+// to an interface proxy.
+//
+// EXAMPLE
+//
+// On the client side of a service, RemotePtr might be used like so:
+//
+// class FooClientImpl : public FooClientStub {
+// public:
+// explicit FooClientImpl(mojo::Handle message_pipe)
+// : foo_(message_pipe) {
+// foo_.SetPeer(this);
+// foo_.Ping();
+// }
+// virtual void Pong() {
+// ...
+// }
+// private:
+// mojo::RemotePtr<Foo> foo_;
+// };
+//
+// On the implementation side of a service, RemotePtr might be used like so:
+//
+// class FooImpl : public FooStub {
+// public:
+// explicit FooImpl(mojo::Handle message_pipe)
+// : client_(message_pipe) {
+// client_.SetPeer(this);
+// }
+// virtual void Ping() {
+// client_->Pong();
+// }
+// private:
+// mojo::RemotePtr<FooClient> client_;
+// };
+//
+template <typename S>
+class RemotePtr {
+ public:
+ explicit RemotePtr(Handle message_pipe)
+ : connector_(message_pipe),
+ proxy_(&connector_) {
+ }
+
+ S* get() {
+ return &proxy_;
+ }
+
+ S* operator->() {
+ return get();
+ }
+
+ void SetPeer(typename S::_Peer::_Stub* peer) {
+ connector_.SetIncomingReceiver(peer);
+ }
+
+ private:
+ Connector connector_;
+ typename S::_Proxy proxy_;
+
+ MOJO_DISALLOW_COPY_AND_ASSIGN(RemotePtr);
+};
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_BINDINGS_LIB_REMOTE_PTR_H_
« no previous file with comments | « mojo/public/bindings/generators/mojom_data.py ('k') | mojo/public/bindings/parser/mojo_translate.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698