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

Unified Diff: examples/indirect_service/indirect_integer_service.cc

Issue 733563002: Mojo Example that demos the difference between providing and requesting an interface (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Manage IntegerServicePtr and DemoTask lifetimes. Fixed RunLoop::RemoveFirstInvalidHandle() 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: examples/indirect_service/indirect_integer_service.cc
diff --git a/examples/indirect_service/indirect_integer_service.cc b/examples/indirect_service/indirect_integer_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..767bf56f7ad54ace0ac587ab8120f903bfcea09f
--- /dev/null
+++ b/examples/indirect_service/indirect_integer_service.cc
@@ -0,0 +1,65 @@
+// 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.
+
+#include "base/memory/scoped_vector.h"
+#include "examples/indirect_service/indirect_service_demo.mojom.h"
+#include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/application_connection.h"
+#include "mojo/public/cpp/application/application_delegate.h"
+#include "mojo/public/cpp/application/application_runner.h"
+#include "mojo/public/cpp/application/interface_factory_impl.h"
+#include "mojo/public/cpp/bindings/binding.h"
+
+namespace mojo {
+namespace examples {
+
+class IndirectIntegerServiceImpl :
+ public InterfaceImpl<IndirectIntegerService>, public IntegerService {
+ public:
+ IndirectIntegerServiceImpl() {}
+ ~IndirectIntegerServiceImpl() override {}
+
+ // IndirectIntegerService
+
+ void Set(IntegerServicePtr service) override {
+ integer_service_ = service.Pass();
+ }
+
+ void Get(InterfaceRequest<IntegerService> service) override {
+ bindings_.push_back(new Binding<IntegerService>(this, service.Pass()));
+ }
+
+ // IntegerService
+
+ void Increment(const Callback<void(int32_t)>& callback) override {
+ integer_service_->Increment(callback);
yzshen1 2014/11/20 22:01:44 You might want to check whether integer_service_ i
hansmuller 2014/11/20 22:35:38 Done.
+ }
+
+private:
+ IntegerServicePtr integer_service_;
+ ScopedVector<Binding<IntegerService>> bindings_;
+};
+
+class IndirectIntegerServiceAppDelegate : public ApplicationDelegate {
+ public:
+ bool ConfigureIncomingConnection(
+ ApplicationConnection* connection) override {
+ connection->AddService(&indirect_integer_service_factory_);
+ return true;
+ }
+
+ private:
+ InterfaceFactoryImpl<IndirectIntegerServiceImpl>
+ indirect_integer_service_factory_;
+};
+
+} // namespace examples
+} // namespace mojo
+
+MojoResult MojoMain(MojoHandle shell_handle) {
+ mojo::ApplicationRunner runner(
+ new mojo::examples::IndirectIntegerServiceAppDelegate);
+ return runner.Run(shell_handle);
+}
+

Powered by Google App Engine
This is Rietveld 408576698