OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/public/cpp/bindings/error_handler.h" | 5 #include "mojo/public/cpp/bindings/error_handler.h" |
6 #include "mojo/public/cpp/environment/environment.h" | 6 #include "mojo/public/cpp/environment/environment.h" |
7 #include "mojo/public/cpp/utility/run_loop.h" | 7 #include "mojo/public/cpp/utility/run_loop.h" |
8 #include "mojo/public/interfaces/bindings/tests/math_calculator.mojom.h" | 8 #include "mojo/public/interfaces/bindings/tests/math_calculator.mojom.h" |
9 #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h" | 9 #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 public: | 32 public: |
33 virtual ~MathCalculatorImpl() {} | 33 virtual ~MathCalculatorImpl() {} |
34 | 34 |
35 MathCalculatorImpl() : total_(0.0) { | 35 MathCalculatorImpl() : total_(0.0) { |
36 } | 36 } |
37 | 37 |
38 virtual void OnConnectionError() MOJO_OVERRIDE { | 38 virtual void OnConnectionError() MOJO_OVERRIDE { |
39 delete this; | 39 delete this; |
40 } | 40 } |
41 | 41 |
42 virtual void SetClient(math::CalculatorUI* ui) MOJO_OVERRIDE { | |
43 ui_ = ui; | |
44 } | |
45 | |
46 virtual void Clear() MOJO_OVERRIDE { | 42 virtual void Clear() MOJO_OVERRIDE { |
47 ui_->Output(total_); | 43 client()->Output(total_); |
48 } | 44 } |
49 | 45 |
50 virtual void Add(double value) MOJO_OVERRIDE { | 46 virtual void Add(double value) MOJO_OVERRIDE { |
51 total_ += value; | 47 total_ += value; |
52 ui_->Output(total_); | 48 client()->Output(total_); |
53 } | 49 } |
54 | 50 |
55 virtual void Multiply(double value) MOJO_OVERRIDE { | 51 virtual void Multiply(double value) MOJO_OVERRIDE { |
56 total_ *= value; | 52 total_ *= value; |
57 ui_->Output(total_); | 53 client()->Output(total_); |
58 } | 54 } |
59 | 55 |
60 private: | 56 private: |
61 math::CalculatorUI* ui_; | |
62 double total_; | 57 double total_; |
63 }; | 58 }; |
64 | 59 |
65 class MathCalculatorUIImpl : public math::CalculatorUI { | 60 class MathCalculatorUIImpl : public math::CalculatorUI { |
66 public: | 61 public: |
67 explicit MathCalculatorUIImpl(math::CalculatorPtr calculator) | 62 explicit MathCalculatorUIImpl(math::CalculatorPtr calculator) |
68 : calculator_(calculator.Pass()), | 63 : calculator_(calculator.Pass()), |
69 output_(0.0) { | 64 output_(0.0) { |
70 calculator_->SetClient(this); | 65 calculator_->SetClient(this); |
71 } | 66 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 // This is a test to ensure the following compiles. The sample::Port interface | 229 // This is a test to ensure the following compiles. The sample::Port interface |
235 // does not have an explicit Client attribute. | 230 // does not have an explicit Client attribute. |
236 sample::PortPtr port; | 231 sample::PortPtr port; |
237 MessagePipe pipe; | 232 MessagePipe pipe; |
238 port.Bind(pipe.handle0.Pass()); | 233 port.Bind(pipe.handle0.Pass()); |
239 } | 234 } |
240 | 235 |
241 } // namespace | 236 } // namespace |
242 } // namespace test | 237 } // namespace test |
243 } // namespace mojo | 238 } // namespace mojo |
OLD | NEW |