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_DATA_PIPE_IMPL_H_ | 5 #ifndef MOJO_EDK_SYSTEM_DATA_PIPE_IMPL_H_ |
6 #define MOJO_EDK_SYSTEM_DATA_PIPE_IMPL_H_ | 6 #define MOJO_EDK_SYSTEM_DATA_PIPE_IMPL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
| 10 #include "base/compiler_specific.h" |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "mojo/edk/embedder/platform_handle_vector.h" | 12 #include "mojo/edk/embedder/platform_handle_vector.h" |
12 #include "mojo/edk/system/data_pipe.h" | 13 #include "mojo/edk/system/data_pipe.h" |
13 #include "mojo/edk/system/handle_signals_state.h" | 14 #include "mojo/edk/system/handle_signals_state.h" |
14 #include "mojo/edk/system/memory.h" | 15 #include "mojo/edk/system/memory.h" |
15 #include "mojo/edk/system/system_impl_export.h" | 16 #include "mojo/edk/system/system_impl_export.h" |
| 17 #include "mojo/public/c/system/data_pipe.h" |
16 #include "mojo/public/c/system/types.h" | 18 #include "mojo/public/c/system/types.h" |
17 | 19 |
18 namespace mojo { | 20 namespace mojo { |
19 namespace system { | 21 namespace system { |
20 | 22 |
21 class Channel; | 23 class Channel; |
| 24 class MessageInTransit; |
22 | 25 |
23 // Base class/interface for classes that "implement" |DataPipe| for various | 26 // Base class/interface for classes that "implement" |DataPipe| for various |
24 // situations (local versus remote). The methods, other than the constructor, | 27 // situations (local versus remote). The methods, other than the constructor, |
25 // |set_owner()|, and the destructor, are always protected by |DataPipe|'s | 28 // |set_owner()|, and the destructor, are always protected by |DataPipe|'s |
26 // |lock_|. | 29 // |lock_|. |
27 class MOJO_SYSTEM_IMPL_EXPORT DataPipeImpl { | 30 class MOJO_SYSTEM_IMPL_EXPORT DataPipeImpl { |
28 public: | 31 public: |
29 virtual ~DataPipeImpl() {} | 32 virtual ~DataPipeImpl() {} |
30 | 33 |
31 // This is only called by |DataPipe| during its construction. | 34 // This is only called by |DataPipe| during its construction. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 virtual HandleSignalsState ConsumerGetHandleSignalsState() const = 0; | 77 virtual HandleSignalsState ConsumerGetHandleSignalsState() const = 0; |
75 virtual void ConsumerStartSerialize(Channel* channel, | 78 virtual void ConsumerStartSerialize(Channel* channel, |
76 size_t* max_size, | 79 size_t* max_size, |
77 size_t* max_platform_handles) = 0; | 80 size_t* max_platform_handles) = 0; |
78 virtual bool ConsumerEndSerialize( | 81 virtual bool ConsumerEndSerialize( |
79 Channel* channel, | 82 Channel* channel, |
80 void* destination, | 83 void* destination, |
81 size_t* actual_size, | 84 size_t* actual_size, |
82 embedder::PlatformHandleVector* platform_handles) = 0; | 85 embedder::PlatformHandleVector* platform_handles) = 0; |
83 | 86 |
| 87 virtual bool OnReadMessage(unsigned port, MessageInTransit* message) = 0; |
| 88 virtual void OnDetachFromChannel(unsigned port) = 0; |
| 89 |
84 protected: | 90 protected: |
85 DataPipeImpl() : owner_() {} | 91 DataPipeImpl() : owner_() {} |
86 | 92 |
| 93 // Helper to convert the given circular buffer into messages. The input is a |
| 94 // circular buffer |buffer| (with appropriate element size and capacity), with |
| 95 // current contents starting at |start_index| of length |current_num_bytes|. |
| 96 // This will convert all of the contents. |
| 97 void ConvertDataToMessages(const char* buffer, |
| 98 size_t* start_index, |
| 99 size_t* current_num_bytes, |
| 100 MessageInTransitQueue* message_queue); |
| 101 |
87 DataPipe* owner() const { return owner_; } | 102 DataPipe* owner() const { return owner_; } |
88 | 103 |
89 bool may_discard() const { return owner_->may_discard(); } | 104 const MojoCreateDataPipeOptions& validated_options() const { |
| 105 return owner_->validated_options(); |
| 106 } |
90 size_t element_num_bytes() const { return owner_->element_num_bytes(); } | 107 size_t element_num_bytes() const { return owner_->element_num_bytes(); } |
91 size_t capacity_num_bytes() const { return owner_->capacity_num_bytes(); } | 108 size_t capacity_num_bytes() const { return owner_->capacity_num_bytes(); } |
92 bool producer_open() const { return owner_->producer_open_no_lock(); } | 109 bool producer_open() const { return owner_->producer_open_no_lock(); } |
93 bool consumer_open() const { return owner_->consumer_open_no_lock(); } | 110 bool consumer_open() const { return owner_->consumer_open_no_lock(); } |
94 uint32_t producer_two_phase_max_num_bytes_written() const { | 111 uint32_t producer_two_phase_max_num_bytes_written() const { |
95 return owner_->producer_two_phase_max_num_bytes_written_no_lock(); | 112 return owner_->producer_two_phase_max_num_bytes_written_no_lock(); |
96 } | 113 } |
97 uint32_t consumer_two_phase_max_num_bytes_read() const { | 114 uint32_t consumer_two_phase_max_num_bytes_read() const { |
98 return owner_->consumer_two_phase_max_num_bytes_read_no_lock(); | 115 return owner_->consumer_two_phase_max_num_bytes_read_no_lock(); |
99 } | 116 } |
100 void set_producer_two_phase_max_num_bytes_written(uint32_t num_bytes) { | 117 void set_producer_two_phase_max_num_bytes_written(uint32_t num_bytes) { |
101 owner_->set_producer_two_phase_max_num_bytes_written_no_lock(num_bytes); | 118 owner_->set_producer_two_phase_max_num_bytes_written_no_lock(num_bytes); |
102 } | 119 } |
103 void set_consumer_two_phase_max_num_bytes_read(uint32_t num_bytes) { | 120 void set_consumer_two_phase_max_num_bytes_read(uint32_t num_bytes) { |
104 owner_->set_consumer_two_phase_max_num_bytes_read_no_lock(num_bytes); | 121 owner_->set_consumer_two_phase_max_num_bytes_read_no_lock(num_bytes); |
105 } | 122 } |
106 bool producer_in_two_phase_write() const { | 123 bool producer_in_two_phase_write() const { |
107 return owner_->producer_in_two_phase_write_no_lock(); | 124 return owner_->producer_in_two_phase_write_no_lock(); |
108 } | 125 } |
109 bool consumer_in_two_phase_read() const { | 126 bool consumer_in_two_phase_read() const { |
110 return owner_->consumer_in_two_phase_read_no_lock(); | 127 return owner_->consumer_in_two_phase_read_no_lock(); |
111 } | 128 } |
112 | 129 |
113 private: | 130 private: |
114 DataPipe* owner_; | 131 DataPipe* owner_; |
115 | 132 |
116 DISALLOW_COPY_AND_ASSIGN(DataPipeImpl); | 133 DISALLOW_COPY_AND_ASSIGN(DataPipeImpl); |
117 }; | 134 }; |
118 | 135 |
| 136 // TODO(vtl): This is not the ideal place for the following structs; find |
| 137 // somewhere better. |
| 138 |
| 139 // Serialized form of a producer dispatcher. This will actually be followed by a |
| 140 // serialized |ChannelEndpoint|; we want to preserve alignment guarantees. |
| 141 struct ALIGNAS(8) SerializedDataPipeProducerDispatcher { |
| 142 // Only validated (and thus canonicalized) options should be serialized. |
| 143 // However, the deserializer must revalidate (as with everything received). |
| 144 MojoCreateDataPipeOptions validated_options; |
| 145 // Number of bytes already enqueued to the consumer. Set to |
| 146 // |static_cast<size_t>(-1)| if the consumer is already closed, in which case |
| 147 // this will *not* be followed by a serialized |ChannelEndpoint|. |
| 148 size_t consumer_num_bytes; |
| 149 }; |
| 150 |
| 151 // Serialized form of a consumer dispatcher. This will actually be followed by a |
| 152 // serialized |ChannelEndpoint|; we want to preserve alignment guarantees. |
| 153 struct ALIGNAS(8) SerializedDataPipeConsumerDispatcher { |
| 154 // Only validated (and thus canonicalized) options should be serialized. |
| 155 // However, the deserializer must revalidate (as with everything received). |
| 156 MojoCreateDataPipeOptions validated_options; |
| 157 }; |
| 158 |
119 } // namespace system | 159 } // namespace system |
120 } // namespace mojo | 160 } // namespace mojo |
121 | 161 |
122 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_IMPL_H_ | 162 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_IMPL_H_ |
OLD | NEW |