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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // |lock()| method). | 53 // |lock()| method). |
54 class MOJO_SYSTEM_IMPL_EXPORT Dispatcher | 54 class MOJO_SYSTEM_IMPL_EXPORT Dispatcher |
55 : public base::RefCountedThreadSafe<Dispatcher> { | 55 : public base::RefCountedThreadSafe<Dispatcher> { |
56 public: | 56 public: |
57 enum class Type { | 57 enum class Type { |
58 UNKNOWN = 0, | 58 UNKNOWN = 0, |
59 MESSAGE_PIPE, | 59 MESSAGE_PIPE, |
60 DATA_PIPE_PRODUCER, | 60 DATA_PIPE_PRODUCER, |
61 DATA_PIPE_CONSUMER, | 61 DATA_PIPE_CONSUMER, |
62 SHARED_BUFFER, | 62 SHARED_BUFFER, |
| 63 WAIT_SET, |
63 | 64 |
64 // "Private" types (not exposed via the public interface): | 65 // "Private" types (not exposed via the public interface): |
65 PLATFORM_HANDLE = -1 | 66 PLATFORM_HANDLE = -1 |
66 }; | 67 }; |
67 virtual Type GetType() const = 0; | 68 virtual Type GetType() const = 0; |
68 | 69 |
69 // These methods implement the various primitives named |Mojo...()|. These | 70 // These methods implement the various primitives named |Mojo...()|. These |
70 // take |lock_| and handle races with |Close()|. Then they call out to | 71 // take |lock_| and handle races with |Close()|. Then they call out to |
71 // subclasses' |...ImplNoLock()| methods (still under |lock_|), which actually | 72 // subclasses' |...ImplNoLock()| methods (still under |lock_|), which actually |
72 // implement the primitives. | 73 // implement the primitives. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 MojoResult AddAwakable(Awakable* awakable, | 141 MojoResult AddAwakable(Awakable* awakable, |
141 MojoHandleSignals signals, | 142 MojoHandleSignals signals, |
142 uintptr_t context, | 143 uintptr_t context, |
143 HandleSignalsState* signals_state); | 144 HandleSignalsState* signals_state); |
144 // Removes an awakable from this dispatcher. (It is valid to call this | 145 // Removes an awakable from this dispatcher. (It is valid to call this |
145 // multiple times for the same |awakable| on the same object, so long as | 146 // multiple times for the same |awakable| on the same object, so long as |
146 // |AddAwakable()| was called at most once.) If |signals_state| is non-null, | 147 // |AddAwakable()| was called at most once.) If |signals_state| is non-null, |
147 // |*signals_state| will be set to the current handle signals state. | 148 // |*signals_state| will be set to the current handle signals state. |
148 void RemoveAwakable(Awakable* awakable, HandleSignalsState* signals_state); | 149 void RemoveAwakable(Awakable* awakable, HandleSignalsState* signals_state); |
149 | 150 |
| 151 // Adds a dispatcher to wait on. When the dispatcher satisfies |signals|, it |
| 152 // will be returned in the next call to |GetReadyDispatchers()|. If |
| 153 // |dispatcher| has been added, it must be removed before adding again, |
| 154 // otherwise |MOJO_RESULT_ALREADY_EXISTS| will be returned. |
| 155 MojoResult AddWaitingDispatcher(const scoped_refptr<Dispatcher>& dispatcher, |
| 156 MojoHandleSignals signals, |
| 157 uintptr_t context); |
| 158 // Removes a dispatcher to wait on. If |dispatcher| has not been added, |
| 159 // |MOJO_RESULT_NOT_FOUND| will be returned. |
| 160 MojoResult RemoveWaitingDispatcher( |
| 161 const scoped_refptr<Dispatcher>& dispatcher); |
| 162 // Returns a set of ready dispatchers. |*count| is the maximum number of |
| 163 // dispatchers to return, and will contain the number of dispatchers returned |
| 164 // in |dispatchers| on completion. |
| 165 MojoResult GetReadyDispatchers(uint32_t* count, |
| 166 DispatcherVector* dispatchers, |
| 167 MojoResult* results, |
| 168 uintptr_t* contexts); |
| 169 |
150 // A dispatcher must be put into a special state in order to be sent across a | 170 // A dispatcher must be put into a special state in order to be sent across a |
151 // message pipe. Outside of tests, only |HandleTableAccess| is allowed to do | 171 // message pipe. Outside of tests, only |HandleTableAccess| is allowed to do |
152 // this, since there are requirements on the handle table (see below). | 172 // this, since there are requirements on the handle table (see below). |
153 // | 173 // |
154 // In this special state, only a restricted set of operations is allowed. | 174 // In this special state, only a restricted set of operations is allowed. |
155 // These are the ones available as |DispatcherTransport| methods. Other | 175 // These are the ones available as |DispatcherTransport| methods. Other |
156 // |Dispatcher| methods must not be called until |DispatcherTransport::End()| | 176 // |Dispatcher| methods must not be called until |DispatcherTransport::End()| |
157 // has been called. | 177 // has been called. |
158 class HandleTableAccess { | 178 class HandleTableAccess { |
159 private: | 179 private: |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 uint64_t num_bytes, | 278 uint64_t num_bytes, |
259 MojoMapBufferFlags flags, | 279 MojoMapBufferFlags flags, |
260 scoped_ptr<PlatformSharedBufferMapping>* mapping); | 280 scoped_ptr<PlatformSharedBufferMapping>* mapping); |
261 virtual HandleSignalsState GetHandleSignalsStateImplNoLock() const; | 281 virtual HandleSignalsState GetHandleSignalsStateImplNoLock() const; |
262 virtual MojoResult AddAwakableImplNoLock(Awakable* awakable, | 282 virtual MojoResult AddAwakableImplNoLock(Awakable* awakable, |
263 MojoHandleSignals signals, | 283 MojoHandleSignals signals, |
264 uintptr_t context, | 284 uintptr_t context, |
265 HandleSignalsState* signals_state); | 285 HandleSignalsState* signals_state); |
266 virtual void RemoveAwakableImplNoLock(Awakable* awakable, | 286 virtual void RemoveAwakableImplNoLock(Awakable* awakable, |
267 HandleSignalsState* signals_state); | 287 HandleSignalsState* signals_state); |
| 288 virtual MojoResult AddWaitingDispatcherImplNoLock( |
| 289 const scoped_refptr<Dispatcher>& dispatcher, |
| 290 MojoHandleSignals signals, |
| 291 uintptr_t context); |
| 292 virtual MojoResult RemoveWaitingDispatcherImplNoLock( |
| 293 const scoped_refptr<Dispatcher>& dispatcher); |
| 294 virtual MojoResult GetReadyDispatchersImplNoLock( |
| 295 uint32_t* count, |
| 296 DispatcherVector* dispatchers, |
| 297 MojoResult* results, |
| 298 uintptr_t* contexts); |
268 | 299 |
269 // These implement the API used to serialize dispatchers (described below). | 300 // These implement the API used to serialize dispatchers (described below). |
270 // They will only be called on a dispatcher that's attached to and "owned" by | 301 // They will only be called on a dispatcher that's attached to and "owned" by |
271 // a |MessageInTransit|. See the non-"impl" versions for more information. | 302 // a |MessageInTransit|. See the non-"impl" versions for more information. |
272 // | 303 // |
273 // TODO(vtl): Consider making these pure virtual once most things support | 304 // TODO(vtl): Consider making these pure virtual once most things support |
274 // being passed over a message pipe. | 305 // being passed over a message pipe. |
275 virtual void StartSerializeImplNoLock(size_t* max_size, | 306 virtual void StartSerializeImplNoLock(size_t* max_size, |
276 size_t* max_platform_handles); | 307 size_t* max_platform_handles); |
277 virtual bool EndSerializeAndCloseImplNoLock( | 308 virtual bool EndSerializeAndCloseImplNoLock( |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 // So logging macros and |DCHECK_EQ()|, etc. work. | 424 // So logging macros and |DCHECK_EQ()|, etc. work. |
394 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<(std::ostream& out, | 425 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<(std::ostream& out, |
395 Dispatcher::Type type) { | 426 Dispatcher::Type type) { |
396 return out << static_cast<int>(type); | 427 return out << static_cast<int>(type); |
397 } | 428 } |
398 | 429 |
399 } // namespace edk | 430 } // namespace edk |
400 } // namespace mojo | 431 } // namespace mojo |
401 | 432 |
402 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ | 433 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ |
OLD | NEW |