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

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: 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 unified diff | Download patch
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 "base/memory/scoped_vector.h"
6 #include "examples/indirect_service/indirect_service_demo.mojom.h"
7 #include "mojo/public/c/system/main.h"
8 #include "mojo/public/cpp/application/application_connection.h"
9 #include "mojo/public/cpp/application/application_delegate.h"
10 #include "mojo/public/cpp/application/application_runner.h"
11 #include "mojo/public/cpp/application/interface_factory_impl.h"
12 #include "mojo/public/cpp/bindings/binding.h"
13
14 namespace mojo {
15 namespace examples {
16
17 class IndirectIntegerServiceImpl :
18 public InterfaceImpl<IndirectIntegerService>, public IntegerService {
19 public:
20 IndirectIntegerServiceImpl() {}
21 ~IndirectIntegerServiceImpl() override {}
22
23 // IndirectIntegerService
24
25 void Set(IntegerServicePtr service) override {
26 integer_service_ = service.Pass();
27 }
28
29 void Get(InterfaceRequest<IntegerService> service) override {
30 bindings_.push_back(new Binding<IntegerService>(this, service.Pass()));
31 }
32
33 // IntegerService
34
35 void Increment(const Callback<void(int32_t)>& callback) override {
36 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.
37 }
38
39 private:
40 IntegerServicePtr integer_service_;
41 ScopedVector<Binding<IntegerService>> bindings_;
42 };
43
44 class IndirectIntegerServiceAppDelegate : public ApplicationDelegate {
45 public:
46 bool ConfigureIncomingConnection(
47 ApplicationConnection* connection) override {
48 connection->AddService(&indirect_integer_service_factory_);
49 return true;
50 }
51
52 private:
53 InterfaceFactoryImpl<IndirectIntegerServiceImpl>
54 indirect_integer_service_factory_;
55 };
56
57 } // namespace examples
58 } // namespace mojo
59
60 MojoResult MojoMain(MojoHandle shell_handle) {
61 mojo::ApplicationRunner runner(
62 new mojo::examples::IndirectIntegerServiceAppDelegate);
63 return runner.Run(shell_handle);
64 }
65
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698