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

Unified Diff: mojo/public/cpp/bindings/strong_connector.h

Issue 718473003: Add mojo::Binding<Interface> for more flexible pipe<->impl binding (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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
Index: mojo/public/cpp/bindings/strong_connector.h
diff --git a/mojo/public/cpp/bindings/strong_connector.h b/mojo/public/cpp/bindings/strong_connector.h
new file mode 100644
index 0000000000000000000000000000000000000000..e242f1bcbbcffa76f705bf8b5bbfb7cd3c0ab0eb
--- /dev/null
+++ b/mojo/public/cpp/bindings/strong_connector.h
@@ -0,0 +1,57 @@
+// Copyright 2014 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_CPP_BINDINGS_STRONG_CONNECTOR_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_STRONG_CONNECTOR_H_
+
+#include "mojo/public/c/environment/async_waiter.h"
+#include "mojo/public/cpp/bindings/connector.h"
+#include "mojo/public/cpp/bindings/error_handler.h"
+#include "mojo/public/cpp/bindings/lib/filter_chain.h"
+#include "mojo/public/cpp/bindings/lib/message_header_validator.h"
+#include "mojo/public/cpp/bindings/lib/router.h"
+#include "mojo/public/cpp/system/core.h"
+
+namespace mojo {
+
+// This connects an interface implementation strongly to a pipe. When a
+// connection error is detected the implementation is deleted. Deleting the
+// connector also closes the pipe.
+//
+// Example of an implementation that is always bound strongly to a pipe
+//
+// class StronglyBound : public Foo {
+// public:
+// explicit StronglyBound(ScopedMessagePipeHandle handle)
+// : connector_(this, handle.Pass()) {}
+//
+// // Foo implementation here
+//
+// private:
+// StrongConnector<Foo> connector_;
+// };
+//
+template <typename Interface>
+class StrongConnector : public Connector<Interface> {
+ public:
+ explicit StrongConnector(Interface* impl) : Connector<Interface>(impl) {}
+
+ StrongConnector(
+ Interface* impl,
+ ScopedMessagePipeHandle handle,
+ const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter())
+ : Connector<Interface>(impl, handle.Pass(), waiter) {}
+
+ virtual ~StrongConnector() {}
+
+ // ErrorHandler implementation
+ void OnConnectionError() override {
+ Connector<Interface>::OnConnectionError();
+ delete this->impl();
+ }
+};
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_STRONG_CONNECTOR_H_

Powered by Google App Engine
This is Rietveld 408576698