Chromium Code Reviews| 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..8eeb17de6e796b6f9678b6d760f5dc196a0c70c1 |
| --- /dev/null |
| +++ b/examples/indirect_service/indirect_integer_service.cc |
| @@ -0,0 +1,76 @@ |
| +// 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" |
| + |
| +namespace mojo { |
| +namespace examples { |
| + |
| +class IndirectIntegerServiceImpl : |
| + public InterfaceImpl<IndirectIntegerService> { |
| + public: |
| + IndirectIntegerServiceImpl() {} |
| + virtual ~IndirectIntegerServiceImpl() {} |
|
yzshen1
2014/11/20 18:17:17
Please use
~xxxx() override {} // without virtual
hansmuller
2014/11/20 19:27:59
Done.
|
| + |
| + virtual void Set(IntegerServicePtr service) override; |
|
yzshen1
2014/11/20 18:17:17
style nit: no need to have 'virtual'. (This was a
hansmuller
2014/11/20 19:27:59
Done.
|
| + virtual void Get(InterfaceRequest<IntegerService> service) override; |
| + |
| + IntegerService* integer_service() { |
| + return integer_service_.get(); |
| + } |
| + |
| +private: |
| + IntegerServicePtr integer_service_; |
| +}; |
| + |
| +class DelegatingIntegerServiceImpl : public InterfaceImpl<IntegerService> { |
|
Aaron Boodman
2014/11/20 07:21:58
I think it is possible to use jamesr's new binding
yzshen1
2014/11/20 18:17:17
+1
hansmuller
2014/11/20 19:27:59
I applied your suggestion - IndirectIntegerService
|
| + public: |
| + DelegatingIntegerServiceImpl(IndirectIntegerServiceImpl* delegate) |
|
yzshen1
2014/11/20 18:17:17
explicit, please.
|
| + : delegate_(delegate) { |
| + } |
| + virtual ~DelegatingIntegerServiceImpl() {} |
| + |
| + virtual void Increment(const Callback<void(int32_t)>& callback) override { |
| + delegate_->integer_service()->Increment(callback); |
| + } |
| + |
| + private: |
| + IndirectIntegerServiceImpl* delegate_; |
| +}; |
| + |
| +void IndirectIntegerServiceImpl::Set(IntegerServicePtr service) { |
| + integer_service_ = service.Pass(); |
| +} |
| + |
| +void IndirectIntegerServiceImpl::Get(InterfaceRequest<IntegerService> service) { |
| + BindToRequest(new DelegatingIntegerServiceImpl(this), &service); |
| +} |
| + |
| +class IndirectIntegerServiceAppDelegate : public ApplicationDelegate { |
| + public: |
| + virtual 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); |
| +} |
| + |