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 |
11 #include <memory> | 11 #include <memory> |
12 #include <ostream> | 12 #include <ostream> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "mojo/edk/embedder/platform_handle.h" | 18 #include "mojo/edk/embedder/platform_handle.h" |
19 #include "mojo/edk/embedder/platform_shared_buffer.h" | 19 #include "mojo/edk/embedder/platform_shared_buffer.h" |
20 #include "mojo/edk/system/handle_signals_state.h" | 20 #include "mojo/edk/system/handle_signals_state.h" |
21 #include "mojo/edk/system/ports/name.h" | 21 #include "mojo/edk/system/ports/name.h" |
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/watcher.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; | 32 class Awakable; |
33 class Dispatcher; | 33 class Dispatcher; |
(...skipping 16 matching lines...) Expand all Loading... |
50 MojoHandle local_handle; | 50 MojoHandle local_handle; |
51 }; | 51 }; |
52 | 52 |
53 enum class Type { | 53 enum class Type { |
54 UNKNOWN = 0, | 54 UNKNOWN = 0, |
55 MESSAGE_PIPE, | 55 MESSAGE_PIPE, |
56 DATA_PIPE_PRODUCER, | 56 DATA_PIPE_PRODUCER, |
57 DATA_PIPE_CONSUMER, | 57 DATA_PIPE_CONSUMER, |
58 SHARED_BUFFER, | 58 SHARED_BUFFER, |
59 WAIT_SET, | 59 WAIT_SET, |
60 WATCHER, | |
61 | 60 |
62 // "Private" types (not exposed via the public interface): | 61 // "Private" types (not exposed via the public interface): |
63 PLATFORM_HANDLE = -1, | 62 PLATFORM_HANDLE = -1, |
64 }; | 63 }; |
65 | 64 |
66 // All Dispatchers must minimally implement these methods. | 65 // All Dispatchers must minimally implement these methods. |
67 | 66 |
68 virtual Type GetType() const = 0; | 67 virtual Type GetType() const = 0; |
69 virtual MojoResult Close() = 0; | 68 virtual MojoResult Close() = 0; |
70 | 69 |
71 ///////////// Watcher API //////////////////// | 70 ///////////// Watch API //////////////////// |
72 | 71 |
73 virtual MojoResult WatchDispatcher(scoped_refptr<Dispatcher> dispatcher, | 72 virtual MojoResult Watch(MojoHandleSignals signals, |
74 MojoHandleSignals signals, | 73 const Watcher::WatchCallback& callback, |
75 uintptr_t context); | 74 uintptr_t context); |
| 75 |
76 virtual MojoResult CancelWatch(uintptr_t context); | 76 virtual MojoResult CancelWatch(uintptr_t context); |
77 virtual MojoResult Arm(uint32_t* num_ready_contexts, | |
78 uintptr_t* ready_contexts, | |
79 MojoResult* ready_results, | |
80 MojoHandleSignalsState* ready_signals_states); | |
81 | 77 |
82 ///////////// Message pipe API ///////////// | 78 ///////////// Message pipe API ///////////// |
83 | 79 |
84 virtual MojoResult WriteMessage(std::unique_ptr<MessageForTransit> message, | 80 virtual MojoResult WriteMessage(std::unique_ptr<MessageForTransit> message, |
85 MojoWriteMessageFlags flags); | 81 MojoWriteMessageFlags flags); |
86 | 82 |
87 virtual MojoResult ReadMessage(std::unique_ptr<MessageForTransit>* message, | 83 virtual MojoResult ReadMessage(std::unique_ptr<MessageForTransit>* message, |
88 uint32_t* num_bytes, | 84 uint32_t* num_bytes, |
89 MojoHandle* handles, | 85 MojoHandle* handles, |
90 uint32_t* num_handles, | 86 uint32_t* num_handles, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 uintptr_t* contexts); | 151 uintptr_t* contexts); |
156 | 152 |
157 ///////////// General-purpose API for all handle types ///////// | 153 ///////////// General-purpose API for all handle types ///////// |
158 | 154 |
159 // Gets the current handle signals state. (The default implementation simply | 155 // Gets the current handle signals state. (The default implementation simply |
160 // returns a default-constructed |HandleSignalsState|, i.e., no signals | 156 // returns a default-constructed |HandleSignalsState|, i.e., no signals |
161 // satisfied or satisfiable.) Note: The state is subject to change from other | 157 // satisfied or satisfiable.) Note: The state is subject to change from other |
162 // threads. | 158 // threads. |
163 virtual HandleSignalsState GetHandleSignalsState() const; | 159 virtual HandleSignalsState GetHandleSignalsState() const; |
164 | 160 |
165 // Adds a WatcherDispatcher reference to this dispatcher, to be notified of | |
166 // all subsequent changes to handle state including signal changes or closure. | |
167 // The reference is associated with a |context| for disambiguation of | |
168 // removals. | |
169 virtual MojoResult AddWatcherRef( | |
170 const scoped_refptr<WatcherDispatcher>& watcher, | |
171 uintptr_t context); | |
172 | |
173 // Removes a WatcherDispatcher reference from this dispatcher. | |
174 virtual MojoResult RemoveWatcherRef(WatcherDispatcher* watcher, | |
175 uintptr_t context); | |
176 | |
177 // Adds an awakable to this dispatcher, which will be woken up when this | 161 // 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 | 162 // 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 | 163 // also be woken up when it becomes impossible for the object to ever satisfy |
180 // |signals| with a suitable error status. | 164 // |signals| with a suitable error status. |
181 // | 165 // |
182 // If |signals_state| is non-null, on *failure* |*signals_state| will be set | 166 // 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). | 167 // to the current handle signals state (on success, it is left untouched). |
184 // | 168 // |
185 // Returns: | 169 // Returns: |
186 // - |MOJO_RESULT_OK| if the awakable was added; | 170 // - |MOJO_RESULT_OK| if the awakable was added; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 // So logging macros and |DCHECK_EQ()|, etc. work. | 249 // So logging macros and |DCHECK_EQ()|, etc. work. |
266 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<(std::ostream& out, | 250 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<(std::ostream& out, |
267 Dispatcher::Type type) { | 251 Dispatcher::Type type) { |
268 return out << static_cast<int>(type); | 252 return out << static_cast<int>(type); |
269 } | 253 } |
270 | 254 |
271 } // namespace edk | 255 } // namespace edk |
272 } // namespace mojo | 256 } // namespace mojo |
273 | 257 |
274 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ | 258 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ |
OLD | NEW |