| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef MOJO_EDK_SYSTEM_TEST_CHANNEL_ENDPOINT_CLIENT_H_ | 5 #ifndef MOJO_EDK_SYSTEM_TEST_CHANNEL_ENDPOINT_CLIENT_H_ |
| 6 #define MOJO_EDK_SYSTEM_TEST_CHANNEL_ENDPOINT_CLIENT_H_ | 6 #define MOJO_EDK_SYSTEM_TEST_CHANNEL_ENDPOINT_CLIENT_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "mojo/edk/system/channel_endpoint.h" | 10 #include "mojo/edk/system/channel_endpoint.h" |
| 11 #include "mojo/edk/system/channel_endpoint_client.h" | 11 #include "mojo/edk/system/channel_endpoint_client.h" |
| 12 #include "mojo/edk/system/message_in_transit_queue.h" | 12 #include "mojo/edk/system/message_in_transit_queue.h" |
| 13 #include "mojo/edk/system/mutex.h" | 13 #include "mojo/edk/system/mutex.h" |
| 14 #include "mojo/edk/system/ref_ptr.h" | 14 #include "mojo/edk/util/ref_ptr.h" |
| 15 #include "mojo/public/cpp/system/macros.h" | 15 #include "mojo/public/cpp/system/macros.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 namespace system { | 18 namespace system { |
| 19 | 19 |
| 20 class ManualResetWaitableEvent; | 20 class ManualResetWaitableEvent; |
| 21 | 21 |
| 22 namespace test { | 22 namespace test { |
| 23 | 23 |
| 24 class TestChannelEndpointClient final : public ChannelEndpointClient { | 24 class TestChannelEndpointClient final : public ChannelEndpointClient { |
| 25 public: | 25 public: |
| 26 // Note: Use |MakeRefCounted<TestChannelEndpointClient>()|. | 26 // Note: Use |util::MakeRefCounted<TestChannelEndpointClient>()|. |
| 27 | 27 |
| 28 // Initializes with the given port and endpoint. | 28 // Initializes with the given port and endpoint. |
| 29 void Init(unsigned port, RefPtr<ChannelEndpoint>&& endpoint); | 29 void Init(unsigned port, util::RefPtr<ChannelEndpoint>&& endpoint); |
| 30 | 30 |
| 31 // Returns true if we're detached from the |ChannelEndpoint|. | 31 // Returns true if we're detached from the |ChannelEndpoint|. |
| 32 bool IsDetached() const; | 32 bool IsDetached() const; |
| 33 | 33 |
| 34 // Gets the current number of messages received (but not dequeued). | 34 // Gets the current number of messages received (but not dequeued). |
| 35 size_t NumMessages() const; | 35 size_t NumMessages() const; |
| 36 | 36 |
| 37 // Gets/removes a message that was received (|NumMessages()| must be | 37 // Gets/removes a message that was received (|NumMessages()| must be |
| 38 // non-zero), in FIFO order. | 38 // non-zero), in FIFO order. |
| 39 std::unique_ptr<MessageInTransit> PopMessage(); | 39 std::unique_ptr<MessageInTransit> PopMessage(); |
| 40 | 40 |
| 41 // Sets an event to signal when we receive a message. (|read_event| must live | 41 // Sets an event to signal when we receive a message. (|read_event| must live |
| 42 // until this object is destroyed or the read event is reset to null.) | 42 // until this object is destroyed or the read event is reset to null.) |
| 43 void SetReadEvent(ManualResetWaitableEvent* read_event); | 43 void SetReadEvent(ManualResetWaitableEvent* read_event); |
| 44 | 44 |
| 45 // |ChannelEndpointClient| implementation: | 45 // |ChannelEndpointClient| implementation: |
| 46 bool OnReadMessage(unsigned port, MessageInTransit* message) override; | 46 bool OnReadMessage(unsigned port, MessageInTransit* message) override; |
| 47 void OnDetachFromChannel(unsigned port) override; | 47 void OnDetachFromChannel(unsigned port) override; |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 FRIEND_MAKE_REF_COUNTED(TestChannelEndpointClient); | 50 FRIEND_MAKE_REF_COUNTED(TestChannelEndpointClient); |
| 51 | 51 |
| 52 TestChannelEndpointClient(); | 52 TestChannelEndpointClient(); |
| 53 ~TestChannelEndpointClient() override; | 53 ~TestChannelEndpointClient() override; |
| 54 | 54 |
| 55 mutable Mutex mutex_; | 55 mutable Mutex mutex_; |
| 56 | 56 |
| 57 unsigned port_ MOJO_GUARDED_BY(mutex_); | 57 unsigned port_ MOJO_GUARDED_BY(mutex_); |
| 58 RefPtr<ChannelEndpoint> endpoint_ MOJO_GUARDED_BY(mutex_); | 58 util::RefPtr<ChannelEndpoint> endpoint_ MOJO_GUARDED_BY(mutex_); |
| 59 | 59 |
| 60 MessageInTransitQueue messages_ MOJO_GUARDED_BY(mutex_); | 60 MessageInTransitQueue messages_ MOJO_GUARDED_BY(mutex_); |
| 61 | 61 |
| 62 // Event to trigger if we read a message (may be null). | 62 // Event to trigger if we read a message (may be null). |
| 63 ManualResetWaitableEvent* read_event_ MOJO_GUARDED_BY(mutex_); | 63 ManualResetWaitableEvent* read_event_ MOJO_GUARDED_BY(mutex_); |
| 64 | 64 |
| 65 MOJO_DISALLOW_COPY_AND_ASSIGN(TestChannelEndpointClient); | 65 MOJO_DISALLOW_COPY_AND_ASSIGN(TestChannelEndpointClient); |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 } // namespace test | 68 } // namespace test |
| 69 } // namespace system | 69 } // namespace system |
| 70 } // namespace mojo | 70 } // namespace mojo |
| 71 | 71 |
| 72 #endif // MOJO_EDK_SYSTEM_TEST_CHANNEL_ENDPOINT_CLIENT_H_ | 72 #endif // MOJO_EDK_SYSTEM_TEST_CHANNEL_ENDPOINT_CLIENT_H_ |
| OLD | NEW |