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

Side by Side 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 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "examples/indirect_service/indirect_service_demo.mojom.h"
6 #include "mojo/public/c/system/main.h"
7 #include "mojo/public/cpp/application/application_connection.h"
8 #include "mojo/public/cpp/application/application_delegate.h"
9 #include "mojo/public/cpp/application/application_runner.h"
10 #include "mojo/public/cpp/application/interface_factory_impl.h"
11 #include "mojo/public/cpp/bindings/binding.h"
12
13 namespace mojo {
14 namespace examples {
15
16 class IndirectIntegerServiceImpl :
17 public InterfaceImpl<IndirectIntegerService>, public IntegerService {
18 public:
19 IndirectIntegerServiceImpl() {}
20
21 ~IndirectIntegerServiceImpl() override {
22 for (auto itr = bindings_.begin(); itr < bindings_.end(); itr++)
23 delete *itr;
24 }
25
26 // IndirectIntegerService
27
28 void Set(IntegerServicePtr service) override {
29 integer_service_ = service.Pass();
30 }
31
32 void Get(InterfaceRequest<IntegerService> service) override {
33 bindings_.push_back(new Binding<IntegerService>(this, service.Pass()));
34 }
35
36 // IntegerService
37
38 void Increment(const Callback<void(int32_t)>& callback) override {
39 if (integer_service_.get())
40 integer_service_->Increment(callback);
41 }
42
43 private:
44 IntegerServicePtr integer_service_;
45 std::vector<Binding<IntegerService>*> bindings_;
46 };
47
48 class IndirectIntegerServiceAppDelegate : public ApplicationDelegate {
49 public:
50 bool ConfigureIncomingConnection(
51 ApplicationConnection* connection) override {
52 connection->AddService(&indirect_integer_service_factory_);
53 return true;
54 }
55
56 private:
57 InterfaceFactoryImpl<IndirectIntegerServiceImpl>
58 indirect_integer_service_factory_;
59 };
60
61 } // namespace examples
62 } // namespace mojo
63
64 MojoResult MojoMain(MojoHandle shell_handle) {
65 mojo::ApplicationRunner runner(
66 new mojo::examples::IndirectIntegerServiceAppDelegate);
67 return runner.Run(shell_handle);
68 }
69
OLDNEW
« 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