| 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 #ifndef MOJO_EDK_SYSTEM_DATA_PIPE_H_ | 5 #ifndef MOJO_EDK_SYSTEM_DATA_PIPE_H_ |
| 6 #define MOJO_EDK_SYSTEM_DATA_PIPE_H_ | 6 #define MOJO_EDK_SYSTEM_DATA_PIPE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "mojo/edk/embedder/platform_handle_vector.h" | 13 #include "mojo/edk/embedder/platform_handle_vector.h" |
| 14 #include "mojo/edk/system/channel_endpoint_client.h" | 14 #include "mojo/edk/system/channel_endpoint_client.h" |
| 15 #include "mojo/edk/system/handle_signals_state.h" | 15 #include "mojo/edk/system/handle_signals_state.h" |
| 16 #include "mojo/edk/system/memory.h" | 16 #include "mojo/edk/system/memory.h" |
| 17 #include "mojo/edk/system/mutex.h" | 17 #include "mojo/edk/system/mutex.h" |
| 18 #include "mojo/edk/system/ref_ptr.h" | |
| 19 #include "mojo/edk/system/thread_annotations.h" | 18 #include "mojo/edk/system/thread_annotations.h" |
| 19 #include "mojo/edk/util/ref_ptr.h" |
| 20 #include "mojo/public/c/system/data_pipe.h" | 20 #include "mojo/public/c/system/data_pipe.h" |
| 21 #include "mojo/public/c/system/types.h" | 21 #include "mojo/public/c/system/types.h" |
| 22 #include "mojo/public/cpp/system/macros.h" | 22 #include "mojo/public/cpp/system/macros.h" |
| 23 | 23 |
| 24 namespace mojo { | 24 namespace mojo { |
| 25 namespace system { | 25 namespace system { |
| 26 | 26 |
| 27 class Awakable; | 27 class Awakable; |
| 28 class AwakableList; | 28 class AwakableList; |
| 29 class Channel; | 29 class Channel; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 51 // may be partly overwritten on failure). | 51 // may be partly overwritten on failure). |
| 52 static MojoResult ValidateCreateOptions( | 52 static MojoResult ValidateCreateOptions( |
| 53 UserPointer<const MojoCreateDataPipeOptions> in_options, | 53 UserPointer<const MojoCreateDataPipeOptions> in_options, |
| 54 MojoCreateDataPipeOptions* out_options); | 54 MojoCreateDataPipeOptions* out_options); |
| 55 | 55 |
| 56 // Creates a local (both producer and consumer) data pipe (using | 56 // Creates a local (both producer and consumer) data pipe (using |
| 57 // |LocalDataPipeImpl|. |validated_options| should be the output of | 57 // |LocalDataPipeImpl|. |validated_options| should be the output of |
| 58 // |ValidateOptions()|. In particular: |struct_size| is ignored (so | 58 // |ValidateOptions()|. In particular: |struct_size| is ignored (so |
| 59 // |validated_options| must be the current version of the struct) and | 59 // |validated_options| must be the current version of the struct) and |
| 60 // |capacity_num_bytes| must be nonzero. | 60 // |capacity_num_bytes| must be nonzero. |
| 61 static RefPtr<DataPipe> CreateLocal( | 61 static util::RefPtr<DataPipe> CreateLocal( |
| 62 const MojoCreateDataPipeOptions& validated_options); | 62 const MojoCreateDataPipeOptions& validated_options); |
| 63 | 63 |
| 64 // Creates a data pipe with a remote producer and a local consumer, using an | 64 // Creates a data pipe with a remote producer and a local consumer, using an |
| 65 // existing |ChannelEndpoint| (whose |ReplaceClient()| it'll call) and taking | 65 // existing |ChannelEndpoint| (whose |ReplaceClient()| it'll call) and taking |
| 66 // |message_queue|'s contents as already-received incoming messages. If | 66 // |message_queue|'s contents as already-received incoming messages. If |
| 67 // |channel_endpoint| is null, this will create a "half-open" data pipe (with | 67 // |channel_endpoint| is null, this will create a "half-open" data pipe (with |
| 68 // only the consumer open). Note that this may fail, in which case it returns | 68 // only the consumer open). Note that this may fail, in which case it returns |
| 69 // null. | 69 // null. |
| 70 static RefPtr<DataPipe> CreateRemoteProducerFromExisting( | 70 static util::RefPtr<DataPipe> CreateRemoteProducerFromExisting( |
| 71 const MojoCreateDataPipeOptions& validated_options, | 71 const MojoCreateDataPipeOptions& validated_options, |
| 72 MessageInTransitQueue* message_queue, | 72 MessageInTransitQueue* message_queue, |
| 73 RefPtr<ChannelEndpoint>&& channel_endpoint); | 73 util::RefPtr<ChannelEndpoint>&& channel_endpoint); |
| 74 | 74 |
| 75 // Creates a data pipe with a local producer and a remote consumer, using an | 75 // Creates a data pipe with a local producer and a remote consumer, using an |
| 76 // existing |ChannelEndpoint| (whose |ReplaceClient()| it'll call) and taking | 76 // existing |ChannelEndpoint| (whose |ReplaceClient()| it'll call) and taking |
| 77 // |message_queue|'s contents as already-received incoming messages | 77 // |message_queue|'s contents as already-received incoming messages |
| 78 // (|message_queue| may be null). If |channel_endpoint| is null, this will | 78 // (|message_queue| may be null). If |channel_endpoint| is null, this will |
| 79 // create a "half-open" data pipe (with only the producer open). Note that | 79 // create a "half-open" data pipe (with only the producer open). Note that |
| 80 // this may fail, in which case it returns null. | 80 // this may fail, in which case it returns null. |
| 81 static RefPtr<DataPipe> CreateRemoteConsumerFromExisting( | 81 static util::RefPtr<DataPipe> CreateRemoteConsumerFromExisting( |
| 82 const MojoCreateDataPipeOptions& validated_options, | 82 const MojoCreateDataPipeOptions& validated_options, |
| 83 size_t consumer_num_bytes, | 83 size_t consumer_num_bytes, |
| 84 MessageInTransitQueue* message_queue, | 84 MessageInTransitQueue* message_queue, |
| 85 RefPtr<ChannelEndpoint>&& channel_endpoint); | 85 util::RefPtr<ChannelEndpoint>&& channel_endpoint); |
| 86 | 86 |
| 87 // Used by |DataPipeProducerDispatcher::Deserialize()|. Returns true on | 87 // Used by |DataPipeProducerDispatcher::Deserialize()|. Returns true on |
| 88 // success (in which case, |*data_pipe| is set appropriately) and false on | 88 // success (in which case, |*data_pipe| is set appropriately) and false on |
| 89 // failure (in which case |*data_pipe| may or may not be set to null). | 89 // failure (in which case |*data_pipe| may or may not be set to null). |
| 90 static bool ProducerDeserialize(Channel* channel, | 90 static bool ProducerDeserialize(Channel* channel, |
| 91 const void* source, | 91 const void* source, |
| 92 size_t size, | 92 size_t size, |
| 93 RefPtr<DataPipe>* data_pipe); | 93 util::RefPtr<DataPipe>* data_pipe); |
| 94 | 94 |
| 95 // Used by |DataPipeConsumerDispatcher::Deserialize()|. Returns true on | 95 // Used by |DataPipeConsumerDispatcher::Deserialize()|. Returns true on |
| 96 // success (in which case, |*data_pipe| is set appropriately) and false on | 96 // success (in which case, |*data_pipe| is set appropriately) and false on |
| 97 // failure (in which case |*data_pipe| may or may not be set to null). | 97 // failure (in which case |*data_pipe| may or may not be set to null). |
| 98 static bool ConsumerDeserialize(Channel* channel, | 98 static bool ConsumerDeserialize(Channel* channel, |
| 99 const void* source, | 99 const void* source, |
| 100 size_t size, | 100 size_t size, |
| 101 RefPtr<DataPipe>* data_pipe); | 101 util::RefPtr<DataPipe>* data_pipe); |
| 102 | 102 |
| 103 // These are called by the producer dispatcher to implement its methods of | 103 // These are called by the producer dispatcher to implement its methods of |
| 104 // corresponding names. | 104 // corresponding names. |
| 105 void ProducerCancelAllAwakables(); | 105 void ProducerCancelAllAwakables(); |
| 106 void ProducerClose(); | 106 void ProducerClose(); |
| 107 MojoResult ProducerWriteData(UserPointer<const void> elements, | 107 MojoResult ProducerWriteData(UserPointer<const void> elements, |
| 108 UserPointer<uint32_t> num_bytes, | 108 UserPointer<uint32_t> num_bytes, |
| 109 bool all_or_none); | 109 bool all_or_none); |
| 110 MojoResult ProducerBeginWriteData(UserPointer<void*> buffer, | 110 MojoResult ProducerBeginWriteData(UserPointer<void*> buffer, |
| 111 UserPointer<uint32_t> buffer_num_bytes); | 111 UserPointer<uint32_t> buffer_num_bytes); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 uint32_t consumer_two_phase_max_num_bytes_read_ MOJO_GUARDED_BY(mutex_); | 277 uint32_t consumer_two_phase_max_num_bytes_read_ MOJO_GUARDED_BY(mutex_); |
| 278 std::unique_ptr<DataPipeImpl> impl_ MOJO_GUARDED_BY(mutex_); | 278 std::unique_ptr<DataPipeImpl> impl_ MOJO_GUARDED_BY(mutex_); |
| 279 | 279 |
| 280 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipe); | 280 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipe); |
| 281 }; | 281 }; |
| 282 | 282 |
| 283 } // namespace system | 283 } // namespace system |
| 284 } // namespace mojo | 284 } // namespace mojo |
| 285 | 285 |
| 286 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_H_ | 286 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_H_ |
| OLD | NEW |