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 "mojo/edk/embedder/scoped_platform_handle.h" | 15 #include "mojo/edk/platform/scoped_platform_handle.h" |
16 #include "mojo/edk/system/handle_signals_state.h" | 16 #include "mojo/edk/system/handle_signals_state.h" |
17 #include "mojo/edk/system/memory.h" | 17 #include "mojo/edk/system/memory.h" |
18 #include "mojo/edk/util/mutex.h" | 18 #include "mojo/edk/util/mutex.h" |
19 #include "mojo/edk/util/ref_counted.h" | 19 #include "mojo/edk/util/ref_counted.h" |
20 #include "mojo/edk/util/ref_ptr.h" | 20 #include "mojo/edk/util/ref_ptr.h" |
21 #include "mojo/edk/util/thread_annotations.h" | 21 #include "mojo/edk/util/thread_annotations.h" |
22 #include "mojo/public/c/system/buffer.h" | 22 #include "mojo/public/c/system/buffer.h" |
23 #include "mojo/public/c/system/data_pipe.h" | 23 #include "mojo/public/c/system/data_pipe.h" |
24 #include "mojo/public/c/system/message_pipe.h" | 24 #include "mojo/public/c/system/message_pipe.h" |
25 #include "mojo/public/c/system/types.h" | 25 #include "mojo/public/c/system/types.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 // details. | 193 // details. |
194 static void StartSerialize(Dispatcher* dispatcher, | 194 static void StartSerialize(Dispatcher* dispatcher, |
195 Channel* channel, | 195 Channel* channel, |
196 size_t* max_size, | 196 size_t* max_size, |
197 size_t* max_platform_handles); | 197 size_t* max_platform_handles); |
198 static bool EndSerializeAndClose( | 198 static bool EndSerializeAndClose( |
199 Dispatcher* dispatcher, | 199 Dispatcher* dispatcher, |
200 Channel* channel, | 200 Channel* channel, |
201 void* destination, | 201 void* destination, |
202 size_t* actual_size, | 202 size_t* actual_size, |
203 std::vector<embedder::ScopedPlatformHandle>* platform_handles); | 203 std::vector<platform::ScopedPlatformHandle>* platform_handles); |
204 | 204 |
205 // Deserialization API. | 205 // Deserialization API. |
206 // Note: This "clears" (i.e., reset to the invalid handle) any platform | 206 // Note: This "clears" (i.e., reset to the invalid handle) any platform |
207 // handles that it takes ownership of. | 207 // handles that it takes ownership of. |
208 static util::RefPtr<Dispatcher> Deserialize( | 208 static util::RefPtr<Dispatcher> Deserialize( |
209 Channel* channel, | 209 Channel* channel, |
210 int32_t type, | 210 int32_t type, |
211 const void* source, | 211 const void* source, |
212 size_t size, | 212 size_t size, |
213 std::vector<embedder::ScopedPlatformHandle>* platform_handles); | 213 std::vector<platform::ScopedPlatformHandle>* platform_handles); |
214 }; | 214 }; |
215 | 215 |
216 protected: | 216 protected: |
217 Dispatcher(); | 217 Dispatcher(); |
218 virtual ~Dispatcher(); | 218 virtual ~Dispatcher(); |
219 | 219 |
220 // These are to be overridden by subclasses (if necessary). They are called | 220 // These are to be overridden by subclasses (if necessary). They are called |
221 // exactly once (first |CancelAllAwakablesNoLock()|, then |CloseImplNoLock()|) | 221 // exactly once (first |CancelAllAwakablesNoLock()|, then |CloseImplNoLock()|) |
222 // when the dispatcher is being closed. | 222 // when the dispatcher is being closed. |
223 virtual void CancelAllAwakablesNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); | 223 virtual void CancelAllAwakablesNoLock() MOJO_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 // TODO(vtl): Consider making these pure virtual once most things support | 297 // TODO(vtl): Consider making these pure virtual once most things support |
298 // being passed over a message pipe. | 298 // being passed over a message pipe. |
299 virtual void StartSerializeImplNoLock(Channel* channel, | 299 virtual void StartSerializeImplNoLock(Channel* channel, |
300 size_t* max_size, | 300 size_t* max_size, |
301 size_t* max_platform_handles) | 301 size_t* max_platform_handles) |
302 MOJO_NOT_THREAD_SAFE; | 302 MOJO_NOT_THREAD_SAFE; |
303 virtual bool EndSerializeAndCloseImplNoLock( | 303 virtual bool EndSerializeAndCloseImplNoLock( |
304 Channel* channel, | 304 Channel* channel, |
305 void* destination, | 305 void* destination, |
306 size_t* actual_size, | 306 size_t* actual_size, |
307 std::vector<embedder::ScopedPlatformHandle>* platform_handles) | 307 std::vector<platform::ScopedPlatformHandle>* platform_handles) |
308 MOJO_NOT_THREAD_SAFE; | 308 MOJO_NOT_THREAD_SAFE; |
309 | 309 |
310 // This should be overridden to return true if/when there's an ongoing | 310 // This should be overridden to return true if/when there's an ongoing |
311 // operation (e.g., two-phase read/writes on data pipes) that should prevent a | 311 // operation (e.g., two-phase read/writes on data pipes) that should prevent a |
312 // handle from being sent over a message pipe (with status "busy"). | 312 // handle from being sent over a message pipe (with status "busy"). |
313 virtual bool IsBusyNoLock() const MOJO_SHARED_LOCKS_REQUIRED(mutex_); | 313 virtual bool IsBusyNoLock() const MOJO_SHARED_LOCKS_REQUIRED(mutex_); |
314 | 314 |
315 util::Mutex& mutex() const MOJO_LOCK_RETURNED(mutex_) { return mutex_; } | 315 util::Mutex& mutex() const MOJO_LOCK_RETURNED(mutex_) { return mutex_; } |
316 | 316 |
317 private: | 317 private: |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 // |platform_handles| (which may be null if no platform handles were indicated | 365 // |platform_handles| (which may be null if no platform handles were indicated |
366 // to be required to |StartSerialize()|). This may write no more than the | 366 // to be required to |StartSerialize()|). This may write no more than the |
367 // amount indicated by |StartSerialize()|. (WARNING: Beware of races, e.g., if | 367 // amount indicated by |StartSerialize()|. (WARNING: Beware of races, e.g., if |
368 // something can be mutated between the two calls!) Returns true on success, | 368 // something can be mutated between the two calls!) Returns true on success, |
369 // in which case |*actual_size| is set to the amount it actually wrote to | 369 // in which case |*actual_size| is set to the amount it actually wrote to |
370 // |destination|. On failure, |*actual_size| should not be modified; however, | 370 // |destination|. On failure, |*actual_size| should not be modified; however, |
371 // the dispatcher will still be closed. | 371 // the dispatcher will still be closed. |
372 bool EndSerializeAndClose(Channel* channel, | 372 bool EndSerializeAndClose(Channel* channel, |
373 void* destination, | 373 void* destination, |
374 size_t* actual_size, | 374 size_t* actual_size, |
375 std::vector<embedder::ScopedPlatformHandle>* | 375 std::vector<platform::ScopedPlatformHandle>* |
376 platform_handles) MOJO_NOT_THREAD_SAFE; | 376 platform_handles) MOJO_NOT_THREAD_SAFE; |
377 | 377 |
378 // This protects the following members as well as any state added by | 378 // This protects the following members as well as any state added by |
379 // subclasses. | 379 // subclasses. |
380 mutable util::Mutex mutex_; | 380 mutable util::Mutex mutex_; |
381 bool is_closed_ MOJO_GUARDED_BY(mutex_); | 381 bool is_closed_ MOJO_GUARDED_BY(mutex_); |
382 | 382 |
383 MOJO_DISALLOW_COPY_AND_ASSIGN(Dispatcher); | 383 MOJO_DISALLOW_COPY_AND_ASSIGN(Dispatcher); |
384 }; | 384 }; |
385 | 385 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 423 |
424 // So logging macros and |DCHECK_EQ()|, etc. work. | 424 // So logging macros and |DCHECK_EQ()|, etc. work. |
425 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { | 425 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { |
426 return out << static_cast<int>(type); | 426 return out << static_cast<int>(type); |
427 } | 427 } |
428 | 428 |
429 } // namespace system | 429 } // namespace system |
430 } // namespace mojo | 430 } // namespace mojo |
431 | 431 |
432 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ | 432 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ |
OLD | NEW |