| OLD | NEW |
| 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 <memory> | |
| 6 | |
| 7 #include "examples/indirect_service/indirect_service_demo.mojom.h" | 5 #include "examples/indirect_service/indirect_service_demo.mojom.h" |
| 8 #include "mojo/public/c/system/main.h" | 6 #include "mojo/public/c/system/main.h" |
| 9 #include "mojo/public/cpp/application/application_delegate.h" | 7 #include "mojo/public/cpp/application/application_impl_base.h" |
| 10 #include "mojo/public/cpp/application/application_runner.h" | 8 #include "mojo/public/cpp/application/run_application.h" |
| 11 #include "mojo/public/cpp/application/service_provider_impl.h" | 9 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 12 #include "mojo/public/cpp/bindings/strong_binding.h" | 10 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 13 | 11 |
| 14 namespace mojo { | 12 namespace mojo { |
| 15 namespace examples { | 13 namespace examples { |
| 16 | 14 |
| 17 class IntegerServiceImpl : public IntegerService { | 15 class IntegerServiceImpl : public IntegerService { |
| 18 public: | 16 public: |
| 19 explicit IntegerServiceImpl(InterfaceRequest<IntegerService> request) | 17 explicit IntegerServiceImpl(InterfaceRequest<IntegerService> request) |
| 20 : value_(0), binding_(this, request.Pass()) {} | 18 : value_(0), binding_(this, request.Pass()) {} |
| 21 ~IntegerServiceImpl() override {} | 19 ~IntegerServiceImpl() override {} |
| 22 | 20 |
| 23 void Increment(const Callback<void(int32_t)>& callback) override { | 21 void Increment(const Callback<void(int32_t)>& callback) override { |
| 24 callback.Run(value_++); | 22 callback.Run(value_++); |
| 25 } | 23 } |
| 26 | 24 |
| 27 private: | 25 private: |
| 28 int32_t value_; | 26 int32_t value_; |
| 29 StrongBinding<IntegerService> binding_; | 27 StrongBinding<IntegerService> binding_; |
| 30 }; | 28 }; |
| 31 | 29 |
| 32 class IntegerServiceAppDelegate : public ApplicationDelegate { | 30 class IntegerServiceApp : public ApplicationImplBase { |
| 33 public: | 31 public: |
| 34 bool ConfigureIncomingConnection( | 32 bool OnAcceptConnection(ServiceProviderImpl* service_provider_impl) override { |
| 35 ServiceProviderImpl* service_provider_impl) override { | |
| 36 service_provider_impl->AddService<IntegerService>( | 33 service_provider_impl->AddService<IntegerService>( |
| 37 [](const ConnectionContext& connection_context, | 34 [](const ConnectionContext& connection_context, |
| 38 InterfaceRequest<IntegerService> request) { | 35 InterfaceRequest<IntegerService> request) { |
| 39 new IntegerServiceImpl(request.Pass()); | 36 new IntegerServiceImpl(request.Pass()); |
| 40 }); | 37 }); |
| 41 return true; | 38 return true; |
| 42 } | 39 } |
| 43 }; | 40 }; |
| 44 | 41 |
| 45 } // namespace examples | 42 } // namespace examples |
| 46 } // namespace mojo | 43 } // namespace mojo |
| 47 | 44 |
| 48 MojoResult MojoMain(MojoHandle application_request) { | 45 MojoResult MojoMain(MojoHandle application_request) { |
| 49 mojo::ApplicationRunner runner( | 46 mojo::examples::IntegerServiceApp integer_service_app; |
| 50 std::unique_ptr<mojo::examples::IntegerServiceAppDelegate>( | 47 return mojo::RunMainApplication(application_request, &integer_service_app); |
| 51 new mojo::examples::IntegerServiceAppDelegate)); | |
| 52 return runner.Run(application_request); | |
| 53 } | 48 } |
| 54 | 49 |
| OLD | NEW |