| 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 11 matching lines...) Expand all Loading... |
| 22 #include "mojo/edk/system/system_impl_export.h" | 22 #include "mojo/edk/system/system_impl_export.h" |
| 23 #include "mojo/edk/system/watch.h" | 23 #include "mojo/edk/system/watch.h" |
| 24 #include "mojo/public/c/system/buffer.h" | 24 #include "mojo/public/c/system/buffer.h" |
| 25 #include "mojo/public/c/system/data_pipe.h" | 25 #include "mojo/public/c/system/data_pipe.h" |
| 26 #include "mojo/public/c/system/message_pipe.h" | 26 #include "mojo/public/c/system/message_pipe.h" |
| 27 #include "mojo/public/c/system/types.h" | 27 #include "mojo/public/c/system/types.h" |
| 28 | 28 |
| 29 namespace mojo { | 29 namespace mojo { |
| 30 namespace edk { | 30 namespace edk { |
| 31 | 31 |
| 32 class Awakable; | |
| 33 class Dispatcher; | 32 class Dispatcher; |
| 34 class MessageForTransit; | 33 class MessageForTransit; |
| 35 | 34 |
| 36 using DispatcherVector = std::vector<scoped_refptr<Dispatcher>>; | 35 using DispatcherVector = std::vector<scoped_refptr<Dispatcher>>; |
| 37 | 36 |
| 38 // A |Dispatcher| implements Mojo EDK calls that are associated with a | 37 // A |Dispatcher| implements Mojo EDK calls that are associated with a |
| 39 // particular MojoHandle, with the exception of MojoWait and MojoWaitMany ( | 38 // particular MojoHandle. |
| 40 // which are implemented directly in Core.). | |
| 41 class MOJO_SYSTEM_IMPL_EXPORT Dispatcher | 39 class MOJO_SYSTEM_IMPL_EXPORT Dispatcher |
| 42 : public base::RefCountedThreadSafe<Dispatcher> { | 40 : public base::RefCountedThreadSafe<Dispatcher> { |
| 43 public: | 41 public: |
| 44 struct DispatcherInTransit { | 42 struct DispatcherInTransit { |
| 45 DispatcherInTransit(); | 43 DispatcherInTransit(); |
| 46 DispatcherInTransit(const DispatcherInTransit& other); | 44 DispatcherInTransit(const DispatcherInTransit& other); |
| 47 ~DispatcherInTransit(); | 45 ~DispatcherInTransit(); |
| 48 | 46 |
| 49 scoped_refptr<Dispatcher> dispatcher; | 47 scoped_refptr<Dispatcher> dispatcher; |
| 50 MojoHandle local_handle; | 48 MojoHandle local_handle; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 // The reference is associated with a |context| for disambiguation of | 165 // The reference is associated with a |context| for disambiguation of |
| 168 // removals. | 166 // removals. |
| 169 virtual MojoResult AddWatcherRef( | 167 virtual MojoResult AddWatcherRef( |
| 170 const scoped_refptr<WatcherDispatcher>& watcher, | 168 const scoped_refptr<WatcherDispatcher>& watcher, |
| 171 uintptr_t context); | 169 uintptr_t context); |
| 172 | 170 |
| 173 // Removes a WatcherDispatcher reference from this dispatcher. | 171 // Removes a WatcherDispatcher reference from this dispatcher. |
| 174 virtual MojoResult RemoveWatcherRef(WatcherDispatcher* watcher, | 172 virtual MojoResult RemoveWatcherRef(WatcherDispatcher* watcher, |
| 175 uintptr_t context); | 173 uintptr_t context); |
| 176 | 174 |
| 177 // Adds an awakable to this dispatcher, which will be woken up when this | |
| 178 // object changes state to satisfy |signals| with context |context|. It will | |
| 179 // also be woken up when it becomes impossible for the object to ever satisfy | |
| 180 // |signals| with a suitable error status. | |
| 181 // | |
| 182 // If |signals_state| is non-null, on *failure* |*signals_state| will be set | |
| 183 // to the current handle signals state (on success, it is left untouched). | |
| 184 // | |
| 185 // Returns: | |
| 186 // - |MOJO_RESULT_OK| if the awakable was added; | |
| 187 // - |MOJO_RESULT_ALREADY_EXISTS| if |signals| is already satisfied; | |
| 188 // - |MOJO_RESULT_INVALID_ARGUMENT| if the dispatcher has been closed; and | |
| 189 // - |MOJO_RESULT_FAILED_PRECONDITION| if it is not (or no longer) possible | |
| 190 // that |signals| will ever be satisfied. | |
| 191 virtual MojoResult AddAwakable(Awakable* awakable, | |
| 192 MojoHandleSignals signals, | |
| 193 uintptr_t context, | |
| 194 HandleSignalsState* signals_state); | |
| 195 | |
| 196 // Removes an awakable from this dispatcher. (It is valid to call this | |
| 197 // multiple times for the same |awakable| on the same object, so long as | |
| 198 // |AddAwakable()| was called at most once.) If |signals_state| is non-null, | |
| 199 // |*signals_state| will be set to the current handle signals state. | |
| 200 virtual void RemoveAwakable(Awakable* awakable, | |
| 201 HandleSignalsState* signals_state); | |
| 202 | |
| 203 // Informs the caller of the total serialized size (in bytes) and the total | 175 // Informs the caller of the total serialized size (in bytes) and the total |
| 204 // number of platform handles and ports needed to transfer this dispatcher | 176 // number of platform handles and ports needed to transfer this dispatcher |
| 205 // across a message pipe. | 177 // across a message pipe. |
| 206 // | 178 // |
| 207 // Must eventually be followed by a call to EndSerializeAndClose(). Note that | 179 // Must eventually be followed by a call to EndSerializeAndClose(). Note that |
| 208 // StartSerialize() and EndSerialize() are always called in sequence, and | 180 // StartSerialize() and EndSerialize() are always called in sequence, and |
| 209 // only between calls to BeginTransit() and either (but not both) | 181 // only between calls to BeginTransit() and either (but not both) |
| 210 // CompleteTransitAndClose() or CancelTransit(). | 182 // CompleteTransitAndClose() or CancelTransit(). |
| 211 // | 183 // |
| 212 // For this reason it is IMPERATIVE that the implementation ensure a | 184 // For this reason it is IMPERATIVE that the implementation ensure a |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 // So logging macros and |DCHECK_EQ()|, etc. work. | 237 // So logging macros and |DCHECK_EQ()|, etc. work. |
| 266 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<(std::ostream& out, | 238 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<(std::ostream& out, |
| 267 Dispatcher::Type type) { | 239 Dispatcher::Type type) { |
| 268 return out << static_cast<int>(type); | 240 return out << static_cast<int>(type); |
| 269 } | 241 } |
| 270 | 242 |
| 271 } // namespace edk | 243 } // namespace edk |
| 272 } // namespace mojo | 244 } // namespace mojo |
| 273 | 245 |
| 274 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ | 246 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ |
| OLD | NEW |