| 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_INCOMING_ENDPOINT_H_ | 5 #ifndef MOJO_EDK_SYSTEM_INCOMING_ENDPOINT_H_ |
| 6 #define MOJO_EDK_SYSTEM_INCOMING_ENDPOINT_H_ | 6 #define MOJO_EDK_SYSTEM_INCOMING_ENDPOINT_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 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/message_in_transit_queue.h" | 11 #include "mojo/edk/system/message_in_transit_queue.h" |
| 12 #include "mojo/edk/system/mutex.h" | 12 #include "mojo/edk/system/mutex.h" |
| 13 #include "mojo/edk/system/ref_ptr.h" | 13 #include "mojo/edk/util/ref_ptr.h" |
| 14 #include "mojo/public/cpp/system/macros.h" | 14 #include "mojo/public/cpp/system/macros.h" |
| 15 | 15 |
| 16 struct MojoCreateDataPipeOptions; | 16 struct MojoCreateDataPipeOptions; |
| 17 | 17 |
| 18 namespace mojo { | 18 namespace mojo { |
| 19 namespace system { | 19 namespace system { |
| 20 | 20 |
| 21 class ChannelEndpoint; | 21 class ChannelEndpoint; |
| 22 class DataPipe; | 22 class DataPipe; |
| 23 class MessagePipe; | 23 class MessagePipe; |
| 24 | 24 |
| 25 // This is a simple |ChannelEndpointClient| that only receives messages. It's | 25 // This is a simple |ChannelEndpointClient| that only receives messages. It's |
| 26 // used for endpoints that are "received" by |Channel|, but not yet turned into | 26 // used for endpoints that are "received" by |Channel|, but not yet turned into |
| 27 // |MessagePipe|s or |DataPipe|s. | 27 // |MessagePipe|s or |DataPipe|s. |
| 28 class IncomingEndpoint final : public ChannelEndpointClient { | 28 class IncomingEndpoint final : public ChannelEndpointClient { |
| 29 public: | 29 public: |
| 30 // Note: Use |MakeRefCounted<IncomingEndpoint>()|. | 30 // Note: Use |util::MakeRefCounted<IncomingEndpoint>()|. |
| 31 | 31 |
| 32 // Must be called before any other method. | 32 // Must be called before any other method. |
| 33 RefPtr<ChannelEndpoint> Init() MOJO_NOT_THREAD_SAFE; | 33 util::RefPtr<ChannelEndpoint> Init() MOJO_NOT_THREAD_SAFE; |
| 34 | 34 |
| 35 RefPtr<MessagePipe> ConvertToMessagePipe(); | 35 util::RefPtr<MessagePipe> ConvertToMessagePipe(); |
| 36 RefPtr<DataPipe> ConvertToDataPipeProducer( | 36 util::RefPtr<DataPipe> ConvertToDataPipeProducer( |
| 37 const MojoCreateDataPipeOptions& validated_options, | 37 const MojoCreateDataPipeOptions& validated_options, |
| 38 size_t consumer_num_bytes); | 38 size_t consumer_num_bytes); |
| 39 RefPtr<DataPipe> ConvertToDataPipeConsumer( | 39 util::RefPtr<DataPipe> ConvertToDataPipeConsumer( |
| 40 const MojoCreateDataPipeOptions& validated_options); | 40 const MojoCreateDataPipeOptions& validated_options); |
| 41 | 41 |
| 42 // Must be called before destroying this object if |ConvertToMessagePipe()| | 42 // Must be called before destroying this object if |ConvertToMessagePipe()| |
| 43 // wasn't called (but |Init()| was). | 43 // wasn't called (but |Init()| was). |
| 44 void Close(); | 44 void Close(); |
| 45 | 45 |
| 46 // |ChannelEndpointClient| methods: | 46 // |ChannelEndpointClient| methods: |
| 47 bool OnReadMessage(unsigned port, MessageInTransit* message) override; | 47 bool OnReadMessage(unsigned port, MessageInTransit* message) override; |
| 48 void OnDetachFromChannel(unsigned port) override; | 48 void OnDetachFromChannel(unsigned port) override; |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 FRIEND_MAKE_REF_COUNTED(IncomingEndpoint); | 51 FRIEND_MAKE_REF_COUNTED(IncomingEndpoint); |
| 52 | 52 |
| 53 IncomingEndpoint(); | 53 IncomingEndpoint(); |
| 54 ~IncomingEndpoint() override; | 54 ~IncomingEndpoint() override; |
| 55 | 55 |
| 56 Mutex mutex_; | 56 Mutex mutex_; |
| 57 RefPtr<ChannelEndpoint> endpoint_ MOJO_GUARDED_BY(mutex_); | 57 util::RefPtr<ChannelEndpoint> endpoint_ MOJO_GUARDED_BY(mutex_); |
| 58 MessageInTransitQueue message_queue_ MOJO_GUARDED_BY(mutex_); | 58 MessageInTransitQueue message_queue_ MOJO_GUARDED_BY(mutex_); |
| 59 | 59 |
| 60 MOJO_DISALLOW_COPY_AND_ASSIGN(IncomingEndpoint); | 60 MOJO_DISALLOW_COPY_AND_ASSIGN(IncomingEndpoint); |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 } // namespace system | 63 } // namespace system |
| 64 } // namespace mojo | 64 } // namespace mojo |
| 65 | 65 |
| 66 #endif // MOJO_EDK_SYSTEM_INCOMING_ENDPOINT_H_ | 66 #endif // MOJO_EDK_SYSTEM_INCOMING_ENDPOINT_H_ |
| OLD | NEW |