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

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: Fixed Android build 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
« no previous file with comments | « examples/indirect_service/README.md ('k') | examples/indirect_service/indirect_service_demo.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..72cc34e0a9b25626da9509028e3abda85961495e
--- /dev/null
+++ b/examples/indirect_service/indirect_integer_service.cc
@@ -0,0 +1,69 @@
+// 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 "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 {
+ for (auto itr = bindings_.begin(); itr < bindings_.end(); itr++)
+ delete *itr;
+ }
+
+ // 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 {
+ if (integer_service_.get())
+ integer_service_->Increment(callback);
+ }
+
+private:
+ IntegerServicePtr integer_service_;
+ std::vector<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);
+}
+
« no previous file with comments | « examples/indirect_service/README.md ('k') | examples/indirect_service/indirect_service_demo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698