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_DISPATCHER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_DISPATCHER_H_ |
6 #define MOJO_EDK_SYSTEM_DISPATCHER_H_ | 6 #define MOJO_EDK_SYSTEM_DISPATCHER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 namespace system { | 32 namespace system { |
33 | 33 |
34 class Channel; | 34 class Channel; |
35 class Core; | 35 class Core; |
36 class Dispatcher; | 36 class Dispatcher; |
37 class DispatcherTransport; | 37 class DispatcherTransport; |
38 class HandleTable; | 38 class HandleTable; |
39 class LocalMessagePipeEndpoint; | 39 class LocalMessagePipeEndpoint; |
40 class ProxyMessagePipeEndpoint; | 40 class ProxyMessagePipeEndpoint; |
41 class TransportData; | 41 class TransportData; |
42 class Waiter; | 42 class Awakable; |
43 | 43 |
44 typedef std::vector<scoped_refptr<Dispatcher>> DispatcherVector; | 44 typedef std::vector<scoped_refptr<Dispatcher>> DispatcherVector; |
45 | 45 |
46 namespace test { | 46 namespace test { |
47 | 47 |
48 // Test helper. We need to declare it here so we can friend it. | 48 // Test helper. We need to declare it here so we can friend it. |
49 MOJO_SYSTEM_IMPL_EXPORT DispatcherTransport | 49 MOJO_SYSTEM_IMPL_EXPORT DispatcherTransport |
50 DispatcherTryStartTransport(Dispatcher* dispatcher); | 50 DispatcherTryStartTransport(Dispatcher* dispatcher); |
51 | 51 |
52 } // namespace test | 52 } // namespace test |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 uint64_t num_bytes, | 121 uint64_t num_bytes, |
122 MojoMapBufferFlags flags, | 122 MojoMapBufferFlags flags, |
123 scoped_ptr<embedder::PlatformSharedBufferMapping>* mapping); | 123 scoped_ptr<embedder::PlatformSharedBufferMapping>* mapping); |
124 | 124 |
125 // Gets the current handle signals state. (The default implementation simply | 125 // Gets the current handle signals state. (The default implementation simply |
126 // returns a default-constructed |HandleSignalsState|, i.e., no signals | 126 // returns a default-constructed |HandleSignalsState|, i.e., no signals |
127 // satisfied or satisfiable.) Note: The state is subject to change from other | 127 // satisfied or satisfiable.) Note: The state is subject to change from other |
128 // threads. | 128 // threads. |
129 HandleSignalsState GetHandleSignalsState() const; | 129 HandleSignalsState GetHandleSignalsState() const; |
130 | 130 |
131 // Adds a waiter to this dispatcher. The waiter will be woken up when this | 131 // Adds an awakable to this dispatcher, which will be woken up when this |
132 // object changes state to satisfy |signals| with context |context|. It will | 132 // object changes state to satisfy |signals| with context |context|. It will |
133 // also be woken up when it becomes impossible for the object to ever satisfy | 133 // also be woken up when it becomes impossible for the object to ever satisfy |
134 // |signals| with a suitable error status. | 134 // |signals| with a suitable error status. |
135 // | 135 // |
136 // If |signals_state| is non-null, on *failure* |*signals_state| will be set | 136 // If |signals_state| is non-null, on *failure* |*signals_state| will be set |
137 // to the current handle signals state (on success, it is left untouched). | 137 // to the current handle signals state (on success, it is left untouched). |
138 // | 138 // |
139 // Returns: | 139 // Returns: |
140 // - |MOJO_RESULT_OK| if the waiter was added; | 140 // - |MOJO_RESULT_OK| if the awakable was added; |
141 // - |MOJO_RESULT_ALREADY_EXISTS| if |signals| is already satisfied; | 141 // - |MOJO_RESULT_ALREADY_EXISTS| if |signals| is already satisfied; |
142 // - |MOJO_RESULT_INVALID_ARGUMENT| if the dispatcher has been closed; and | 142 // - |MOJO_RESULT_INVALID_ARGUMENT| if the dispatcher has been closed; and |
143 // - |MOJO_RESULT_FAILED_PRECONDITION| if it is not (or no longer) possible | 143 // - |MOJO_RESULT_FAILED_PRECONDITION| if it is not (or no longer) possible |
144 // that |signals| will ever be satisfied. | 144 // that |signals| will ever be satisfied. |
145 MojoResult AddWaiter(Waiter* waiter, | 145 MojoResult AddAwakable(Awakable* awakable, |
146 MojoHandleSignals signals, | 146 MojoHandleSignals signals, |
147 uint32_t context, | 147 uint32_t context, |
148 HandleSignalsState* signals_state); | 148 HandleSignalsState* signals_state); |
149 // Removes a waiter from this dispatcher. (It is valid to call this multiple | 149 // Removes an awakable from this dispatcher. (It is valid to call this |
150 // times for the same |waiter| on the same object, so long as |AddWaiter()| | 150 // multiple times for the same |awakable| on the same object, so long as |
151 // was called at most once.) If |signals_state| is non-null, |*signals_state| | 151 // |AddAwakable()| was called at most once.) If |signals_state| is non-null, |
152 // will be set to the current handle signals state. | 152 // |*signals_state| will be set to the current handle signals state. |
153 void RemoveWaiter(Waiter* waiter, HandleSignalsState* signals_state); | 153 void RemoveAwakable(Awakable* awakable, HandleSignalsState* signals_state); |
154 | 154 |
155 // A dispatcher must be put into a special state in order to be sent across a | 155 // A dispatcher must be put into a special state in order to be sent across a |
156 // message pipe. Outside of tests, only |HandleTableAccess| is allowed to do | 156 // message pipe. Outside of tests, only |HandleTableAccess| is allowed to do |
157 // this, since there are requirements on the handle table (see below). | 157 // this, since there are requirements on the handle table (see below). |
158 // | 158 // |
159 // In this special state, only a restricted set of operations is allowed. | 159 // In this special state, only a restricted set of operations is allowed. |
160 // These are the ones available as |DispatcherTransport| methods. Other | 160 // These are the ones available as |DispatcherTransport| methods. Other |
161 // |Dispatcher| methods must not be called until |DispatcherTransport::End()| | 161 // |Dispatcher| methods must not be called until |DispatcherTransport::End()| |
162 // has been called. | 162 // has been called. |
163 class HandleTableAccess { | 163 class HandleTableAccess { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 embedder::PlatformHandleVector* platform_handles); | 213 embedder::PlatformHandleVector* platform_handles); |
214 }; | 214 }; |
215 | 215 |
216 protected: | 216 protected: |
217 friend class base::RefCountedThreadSafe<Dispatcher>; | 217 friend class base::RefCountedThreadSafe<Dispatcher>; |
218 | 218 |
219 Dispatcher(); | 219 Dispatcher(); |
220 virtual ~Dispatcher(); | 220 virtual ~Dispatcher(); |
221 | 221 |
222 // These are to be overridden by subclasses (if necessary). They are called | 222 // These are to be overridden by subclasses (if necessary). They are called |
223 // exactly once -- first |CancelAllWaitersNoLock()|, then |CloseImplNoLock()|, | 223 // exactly once -- first |CancelAllAwakablesNoLock()|, then |
| 224 // |CloseImplNoLock()|, |
224 // when the dispatcher is being closed. They are called under |lock_|. | 225 // when the dispatcher is being closed. They are called under |lock_|. |
225 virtual void CancelAllWaitersNoLock(); | 226 virtual void CancelAllAwakablesNoLock(); |
226 virtual void CloseImplNoLock(); | 227 virtual void CloseImplNoLock(); |
227 virtual scoped_refptr<Dispatcher> | 228 virtual scoped_refptr<Dispatcher> |
228 CreateEquivalentDispatcherAndCloseImplNoLock() = 0; | 229 CreateEquivalentDispatcherAndCloseImplNoLock() = 0; |
229 | 230 |
230 // These are to be overridden by subclasses (if necessary). They are never | 231 // These are to be overridden by subclasses (if necessary). They are never |
231 // called after the dispatcher has been closed. They are called under |lock_|. | 232 // called after the dispatcher has been closed. They are called under |lock_|. |
232 // See the descriptions of the methods without the "ImplNoLock" for more | 233 // See the descriptions of the methods without the "ImplNoLock" for more |
233 // information. | 234 // information. |
234 virtual MojoResult WriteMessageImplNoLock( | 235 virtual MojoResult WriteMessageImplNoLock( |
235 UserPointer<const void> bytes, | 236 UserPointer<const void> bytes, |
(...skipping 23 matching lines...) Expand all Loading... |
259 virtual MojoResult EndReadDataImplNoLock(uint32_t num_bytes_read); | 260 virtual MojoResult EndReadDataImplNoLock(uint32_t num_bytes_read); |
260 virtual MojoResult DuplicateBufferHandleImplNoLock( | 261 virtual MojoResult DuplicateBufferHandleImplNoLock( |
261 UserPointer<const MojoDuplicateBufferHandleOptions> options, | 262 UserPointer<const MojoDuplicateBufferHandleOptions> options, |
262 scoped_refptr<Dispatcher>* new_dispatcher); | 263 scoped_refptr<Dispatcher>* new_dispatcher); |
263 virtual MojoResult MapBufferImplNoLock( | 264 virtual MojoResult MapBufferImplNoLock( |
264 uint64_t offset, | 265 uint64_t offset, |
265 uint64_t num_bytes, | 266 uint64_t num_bytes, |
266 MojoMapBufferFlags flags, | 267 MojoMapBufferFlags flags, |
267 scoped_ptr<embedder::PlatformSharedBufferMapping>* mapping); | 268 scoped_ptr<embedder::PlatformSharedBufferMapping>* mapping); |
268 virtual HandleSignalsState GetHandleSignalsStateImplNoLock() const; | 269 virtual HandleSignalsState GetHandleSignalsStateImplNoLock() const; |
269 virtual MojoResult AddWaiterImplNoLock(Waiter* waiter, | 270 virtual MojoResult AddAwakableImplNoLock(Awakable* awakable, |
270 MojoHandleSignals signals, | 271 MojoHandleSignals signals, |
271 uint32_t context, | 272 uint32_t context, |
272 HandleSignalsState* signals_state); | 273 HandleSignalsState* signals_state); |
273 virtual void RemoveWaiterImplNoLock(Waiter* waiter, | 274 virtual void RemoveAwakableImplNoLock(Awakable* awakable, |
274 HandleSignalsState* signals_state); | 275 HandleSignalsState* signals_state); |
275 | 276 |
276 // These implement the API used to serialize dispatchers to a |Channel| | 277 // These implement the API used to serialize dispatchers to a |Channel| |
277 // (described below). They will only be called on a dispatcher that's attached | 278 // (described below). They will only be called on a dispatcher that's attached |
278 // to and "owned" by a |MessageInTransit|. See the non-"impl" versions for | 279 // to and "owned" by a |MessageInTransit|. See the non-"impl" versions for |
279 // more information. | 280 // more information. |
280 // | 281 // |
281 // Note: |StartSerializeImplNoLock()| is actually called with |lock_| NOT | 282 // Note: |StartSerializeImplNoLock()| is actually called with |lock_| NOT |
282 // held, since the dispatcher should only be accessible to the calling thread. | 283 // held, since the dispatcher should only be accessible to the calling thread. |
283 // On Debug builds, |EndSerializeAndCloseImplNoLock()| is called with |lock_| | 284 // On Debug builds, |EndSerializeAndCloseImplNoLock()| is called with |lock_| |
284 // held, to satisfy any |lock_.AssertAcquired()| (e.g., in |CloseImplNoLock()| | 285 // held, to satisfy any |lock_.AssertAcquired()| (e.g., in |CloseImplNoLock()| |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 | 396 |
396 Dispatcher* dispatcher_; | 397 Dispatcher* dispatcher_; |
397 | 398 |
398 // Copy and assign allowed. | 399 // Copy and assign allowed. |
399 }; | 400 }; |
400 | 401 |
401 } // namespace system | 402 } // namespace system |
402 } // namespace mojo | 403 } // namespace mojo |
403 | 404 |
404 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ | 405 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ |
OLD | NEW |