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

Side by Side Diff: examples/indirect_service/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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "examples/echo/echo_service.mojom.h" 5 #include "examples/indirect_service/indirect_service_demo.mojom.h"
6 #include "mojo/public/c/system/main.h" 6 #include "mojo/public/c/system/main.h"
7 #include "mojo/public/cpp/application/application_connection.h" 7 #include "mojo/public/cpp/application/application_connection.h"
8 #include "mojo/public/cpp/application/application_delegate.h" 8 #include "mojo/public/cpp/application/application_delegate.h"
9 #include "mojo/public/cpp/application/application_runner.h" 9 #include "mojo/public/cpp/application/application_runner.h"
10 #include "mojo/public/cpp/application/interface_factory_impl.h" 10 #include "mojo/public/cpp/application/interface_factory_impl.h"
11 11
12 namespace mojo { 12 namespace mojo {
13 namespace examples { 13 namespace examples {
14 14
15 class EchoServiceImpl : public InterfaceImpl<EchoService> { 15 class IntegerServiceImpl : public InterfaceImpl<IntegerService> {
16 public: 16 public:
17 virtual void EchoString(const String& value, 17 IntegerServiceImpl() : value_(0) {}
18 const Callback<void(String)>& callback) override { 18 virtual ~IntegerServiceImpl() {}
yzshen1 2014/11/20 22:01:44 nit: use "override" instead of "virtual" whenever
hansmuller 2014/11/20 22:35:38 Sorry, I thought I had cleaned all of these up.
19 callback.Run(value); 19
20 virtual void Increment(const Callback<void(int32_t)>& callback) override {
21 callback.Run(value_++);
20 } 22 }
23
24 private:
25 int32_t value_;
21 }; 26 };
22 27
23 class EchoServiceDelegate : public ApplicationDelegate { 28 class IntegerServiceAppDelegate : public ApplicationDelegate {
24 public: 29 public:
25 virtual bool ConfigureIncomingConnection( 30 virtual bool ConfigureIncomingConnection(
26 ApplicationConnection* connection) override { 31 ApplicationConnection* connection) override {
27 connection->AddService(&echo_service_factory_); 32 connection->AddService(&integer_service_factory_);
28 return true; 33 return true;
29 } 34 }
30 35
31 private: 36 private:
32 InterfaceFactoryImpl<EchoServiceImpl> echo_service_factory_; 37 InterfaceFactoryImpl<IntegerServiceImpl> integer_service_factory_;
33 }; 38 };
34 39
35 } // namespace examples 40 } // namespace examples
36 } // namespace mojo 41 } // namespace mojo
37 42
38 MojoResult MojoMain(MojoHandle shell_handle) { 43 MojoResult MojoMain(MojoHandle shell_handle) {
39 mojo::ApplicationRunner runner(new mojo::examples::EchoServiceDelegate); 44 mojo::ApplicationRunner runner(new mojo::examples::IntegerServiceAppDelegate);
40 return runner.Run(shell_handle); 45 return runner.Run(shell_handle);
41 } 46 }
47
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698