Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: mojo/edk/system/dispatcher.h

Issue 2725133002: Mojo: Armed Watchers (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/watcher.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; 32 class Awakable;
33 class Dispatcher; 33 class Dispatcher;
(...skipping 16 matching lines...) Expand all
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,
60 61
61 // "Private" types (not exposed via the public interface): 62 // "Private" types (not exposed via the public interface):
62 PLATFORM_HANDLE = -1, 63 PLATFORM_HANDLE = -1,
63 }; 64 };
64 65
65 // All Dispatchers must minimally implement these methods. 66 // All Dispatchers must minimally implement these methods.
66 67
67 virtual Type GetType() const = 0; 68 virtual Type GetType() const = 0;
68 virtual MojoResult Close() = 0; 69 virtual MojoResult Close() = 0;
69 70
70 ///////////// Watch API //////////////////// 71 ///////////// Watcher API ////////////////////
71 72
72 virtual MojoResult Watch(MojoHandleSignals signals, 73 virtual MojoResult WatchDispatcher(scoped_refptr<Dispatcher> dispatcher,
73 const Watcher::WatchCallback& callback, 74 MojoHandleSignals signals,
74 uintptr_t context); 75 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);
77 81
78 ///////////// Message pipe API ///////////// 82 ///////////// Message pipe API /////////////
79 83
80 virtual MojoResult WriteMessage(std::unique_ptr<MessageForTransit> message, 84 virtual MojoResult WriteMessage(std::unique_ptr<MessageForTransit> message,
81 MojoWriteMessageFlags flags); 85 MojoWriteMessageFlags flags);
82 86
83 virtual MojoResult ReadMessage(std::unique_ptr<MessageForTransit>* message, 87 virtual MojoResult ReadMessage(std::unique_ptr<MessageForTransit>* message,
84 uint32_t* num_bytes, 88 uint32_t* num_bytes,
85 MojoHandle* handles, 89 MojoHandle* handles,
86 uint32_t* num_handles, 90 uint32_t* num_handles,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 uintptr_t* contexts); 155 uintptr_t* contexts);
152 156
153 ///////////// General-purpose API for all handle types ///////// 157 ///////////// General-purpose API for all handle types /////////
154 158
155 // Gets the current handle signals state. (The default implementation simply 159 // Gets the current handle signals state. (The default implementation simply
156 // returns a default-constructed |HandleSignalsState|, i.e., no signals 160 // returns a default-constructed |HandleSignalsState|, i.e., no signals
157 // satisfied or satisfiable.) Note: The state is subject to change from other 161 // satisfied or satisfiable.) Note: The state is subject to change from other
158 // threads. 162 // threads.
159 virtual HandleSignalsState GetHandleSignalsState() const; 163 virtual HandleSignalsState GetHandleSignalsState() const;
160 164
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
161 // Adds an awakable to this dispatcher, which will be woken up when this 177 // Adds an awakable to this dispatcher, which will be woken up when this
162 // object changes state to satisfy |signals| with context |context|. It will 178 // object changes state to satisfy |signals| with context |context|. It will
163 // also be woken up when it becomes impossible for the object to ever satisfy 179 // also be woken up when it becomes impossible for the object to ever satisfy
164 // |signals| with a suitable error status. 180 // |signals| with a suitable error status.
165 // 181 //
166 // If |signals_state| is non-null, on *failure* |*signals_state| will be set 182 // If |signals_state| is non-null, on *failure* |*signals_state| will be set
167 // to the current handle signals state (on success, it is left untouched). 183 // to the current handle signals state (on success, it is left untouched).
168 // 184 //
169 // Returns: 185 // Returns:
170 // - |MOJO_RESULT_OK| if the awakable was added; 186 // - |MOJO_RESULT_OK| if the awakable was added;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // So logging macros and |DCHECK_EQ()|, etc. work. 265 // So logging macros and |DCHECK_EQ()|, etc. work.
250 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<(std::ostream& out, 266 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<(std::ostream& out,
251 Dispatcher::Type type) { 267 Dispatcher::Type type) {
252 return out << static_cast<int>(type); 268 return out << static_cast<int>(type);
253 } 269 }
254 270
255 } // namespace edk 271 } // namespace edk
256 } // namespace mojo 272 } // namespace mojo
257 273
258 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ 274 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698