| 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 #ifndef MOJO_EDK_SYSTEM_ENDPOINT_RELAYER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_ENDPOINT_RELAYER_H_ |
| 6 #define MOJO_EDK_SYSTEM_ENDPOINT_RELAYER_H_ | 6 #define MOJO_EDK_SYSTEM_ENDPOINT_RELAYER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "mojo/edk/system/channel_endpoint_client.h" | 10 #include "mojo/edk/system/channel_endpoint_client.h" |
| 11 #include "mojo/edk/system/mutex.h" | 11 #include "mojo/edk/system/mutex.h" |
| 12 #include "mojo/edk/system/ref_ptr.h" | 12 #include "mojo/edk/util/ref_ptr.h" |
| 13 #include "mojo/public/cpp/system/macros.h" | 13 #include "mojo/public/cpp/system/macros.h" |
| 14 | 14 |
| 15 namespace mojo { | 15 namespace mojo { |
| 16 namespace system { | 16 namespace system { |
| 17 | 17 |
| 18 class ChannelEndpoint; | 18 class ChannelEndpoint; |
| 19 | 19 |
| 20 // This is a simple |ChannelEndpointClient| that just relays messages between | 20 // This is a simple |ChannelEndpointClient| that just relays messages between |
| 21 // two |ChannelEndpoint|s (without the overhead of |MessagePipe|). | 21 // two |ChannelEndpoint|s (without the overhead of |MessagePipe|). |
| 22 class EndpointRelayer final : public ChannelEndpointClient { | 22 class EndpointRelayer final : public ChannelEndpointClient { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 ChannelEndpoint* peer_endpoint, | 54 ChannelEndpoint* peer_endpoint, |
| 55 MessageInTransit* message) = 0; | 55 MessageInTransit* message) = 0; |
| 56 | 56 |
| 57 protected: | 57 protected: |
| 58 Filter() {} | 58 Filter() {} |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 MOJO_DISALLOW_COPY_AND_ASSIGN(Filter); | 61 MOJO_DISALLOW_COPY_AND_ASSIGN(Filter); |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 // Note: Use |MakeRefCounted<EndpointRelayer>()|. | 64 // Note: Use |util::MakeRefCounted<EndpointRelayer>()|. |
| 65 | 65 |
| 66 // Gets the other port number (i.e., 0 -> 1, 1 -> 0). | 66 // Gets the other port number (i.e., 0 -> 1, 1 -> 0). |
| 67 static unsigned GetPeerPort(unsigned port); | 67 static unsigned GetPeerPort(unsigned port); |
| 68 | 68 |
| 69 // Initialize this object. This must be called before any other method. | 69 // Initialize this object. This must be called before any other method. |
| 70 void Init(RefPtr<ChannelEndpoint>&& endpoint0, | 70 void Init(util::RefPtr<ChannelEndpoint>&& endpoint0, |
| 71 RefPtr<ChannelEndpoint>&& endpoint1) MOJO_NOT_THREAD_SAFE; | 71 util::RefPtr<ChannelEndpoint>&& endpoint1) MOJO_NOT_THREAD_SAFE; |
| 72 | 72 |
| 73 // Sets (or resets) the filter, which can (optionally) handle/filter | 73 // Sets (or resets) the filter, which can (optionally) handle/filter |
| 74 // |Type::ENDPOINT_CLIENT| messages (see |Filter| above). | 74 // |Type::ENDPOINT_CLIENT| messages (see |Filter| above). |
| 75 void SetFilter(std::unique_ptr<Filter> filter); | 75 void SetFilter(std::unique_ptr<Filter> filter); |
| 76 | 76 |
| 77 // |ChannelEndpointClient| methods: | 77 // |ChannelEndpointClient| methods: |
| 78 bool OnReadMessage(unsigned port, MessageInTransit* message) override; | 78 bool OnReadMessage(unsigned port, MessageInTransit* message) override; |
| 79 void OnDetachFromChannel(unsigned port) override; | 79 void OnDetachFromChannel(unsigned port) override; |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 FRIEND_MAKE_REF_COUNTED(EndpointRelayer); | 82 FRIEND_MAKE_REF_COUNTED(EndpointRelayer); |
| 83 | 83 |
| 84 EndpointRelayer(); | 84 EndpointRelayer(); |
| 85 ~EndpointRelayer() override; | 85 ~EndpointRelayer() override; |
| 86 | 86 |
| 87 Mutex mutex_; | 87 Mutex mutex_; |
| 88 RefPtr<ChannelEndpoint> endpoints_[2] MOJO_GUARDED_BY(mutex_); | 88 util::RefPtr<ChannelEndpoint> endpoints_[2] MOJO_GUARDED_BY(mutex_); |
| 89 std::unique_ptr<Filter> filter_ MOJO_GUARDED_BY(mutex_); | 89 std::unique_ptr<Filter> filter_ MOJO_GUARDED_BY(mutex_); |
| 90 | 90 |
| 91 MOJO_DISALLOW_COPY_AND_ASSIGN(EndpointRelayer); | 91 MOJO_DISALLOW_COPY_AND_ASSIGN(EndpointRelayer); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 } // namespace system | 94 } // namespace system |
| 95 } // namespace mojo | 95 } // namespace mojo |
| 96 | 96 |
| 97 #endif // MOJO_EDK_SYSTEM_ENDPOINT_RELAYER_H_ | 97 #endif // MOJO_EDK_SYSTEM_ENDPOINT_RELAYER_H_ |
| OLD | NEW |