| 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/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "mojo/edk/embedder/platform_handle_vector.h" | 16 #include "mojo/edk/embedder/platform_handle_vector.h" |
| 17 #include "mojo/edk/system/handle_signals_state.h" | 17 #include "mojo/edk/system/handle_signals_state.h" |
| 18 #include "mojo/edk/system/memory.h" | 18 #include "mojo/edk/system/memory.h" |
| 19 #include "mojo/edk/system/mutex.h" | 19 #include "mojo/edk/system/mutex.h" |
| 20 #include "mojo/edk/system/system_impl_export.h" | |
| 21 #include "mojo/public/c/system/buffer.h" | 20 #include "mojo/public/c/system/buffer.h" |
| 22 #include "mojo/public/c/system/data_pipe.h" | 21 #include "mojo/public/c/system/data_pipe.h" |
| 23 #include "mojo/public/c/system/message_pipe.h" | 22 #include "mojo/public/c/system/message_pipe.h" |
| 24 #include "mojo/public/c/system/types.h" | 23 #include "mojo/public/c/system/types.h" |
| 25 #include "mojo/public/cpp/system/macros.h" | 24 #include "mojo/public/cpp/system/macros.h" |
| 26 | 25 |
| 27 namespace mojo { | 26 namespace mojo { |
| 28 | 27 |
| 29 namespace embedder { | 28 namespace embedder { |
| 30 class PlatformSharedBufferMapping; | 29 class PlatformSharedBufferMapping; |
| 31 } | 30 } |
| 32 | 31 |
| 33 namespace system { | 32 namespace system { |
| 34 | 33 |
| 35 class Channel; | 34 class Channel; |
| 36 class Core; | 35 class Core; |
| 37 class Dispatcher; | 36 class Dispatcher; |
| 38 class DispatcherTransport; | 37 class DispatcherTransport; |
| 39 class HandleTable; | 38 class HandleTable; |
| 40 class LocalMessagePipeEndpoint; | 39 class LocalMessagePipeEndpoint; |
| 41 class ProxyMessagePipeEndpoint; | 40 class ProxyMessagePipeEndpoint; |
| 42 class TransportData; | 41 class TransportData; |
| 43 class Awakable; | 42 class Awakable; |
| 44 | 43 |
| 45 using DispatcherVector = std::vector<scoped_refptr<Dispatcher>>; | 44 using DispatcherVector = std::vector<scoped_refptr<Dispatcher>>; |
| 46 | 45 |
| 47 namespace test { | 46 namespace test { |
| 48 | 47 |
| 49 // Test helper. We need to declare it here so we can friend it. | 48 // Test helper. We need to declare it here so we can friend it. |
| 50 MOJO_SYSTEM_IMPL_EXPORT DispatcherTransport | 49 DispatcherTransport DispatcherTryStartTransport(Dispatcher* dispatcher); |
| 51 DispatcherTryStartTransport(Dispatcher* dispatcher); | |
| 52 | 50 |
| 53 } // namespace test | 51 } // namespace test |
| 54 | 52 |
| 55 // A |Dispatcher| implements Mojo primitives that are "attached" to a particular | 53 // A |Dispatcher| implements Mojo primitives that are "attached" to a particular |
| 56 // handle. This includes most (all?) primitives except for |MojoWait...()|. This | 54 // handle. This includes most (all?) primitives except for |MojoWait...()|. This |
| 57 // object is thread-safe, with its state being protected by a single mutex | 55 // object is thread-safe, with its state being protected by a single mutex |
| 58 // |mutex_|, which is also made available to implementation subclasses (via the | 56 // |mutex_|, which is also made available to implementation subclasses (via the |
| 59 // |mutex()| method). | 57 // |mutex()| method). |
| 60 class MOJO_SYSTEM_IMPL_EXPORT Dispatcher | 58 class Dispatcher : public base::RefCountedThreadSafe<Dispatcher> { |
| 61 : public base::RefCountedThreadSafe<Dispatcher> { | |
| 62 public: | 59 public: |
| 63 enum class Type { | 60 enum class Type { |
| 64 UNKNOWN = 0, | 61 UNKNOWN = 0, |
| 65 MESSAGE_PIPE, | 62 MESSAGE_PIPE, |
| 66 DATA_PIPE_PRODUCER, | 63 DATA_PIPE_PRODUCER, |
| 67 DATA_PIPE_CONSUMER, | 64 DATA_PIPE_CONSUMER, |
| 68 SHARED_BUFFER, | 65 SHARED_BUFFER, |
| 69 | 66 |
| 70 // "Private" types (not exposed via the public interface): | 67 // "Private" types (not exposed via the public interface): |
| 71 PLATFORM_HANDLE = -1 | 68 PLATFORM_HANDLE = -1 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 380 |
| 384 MOJO_DISALLOW_COPY_AND_ASSIGN(Dispatcher); | 381 MOJO_DISALLOW_COPY_AND_ASSIGN(Dispatcher); |
| 385 }; | 382 }; |
| 386 | 383 |
| 387 // Wrapper around a |Dispatcher| pointer, while it's being processed to be | 384 // Wrapper around a |Dispatcher| pointer, while it's being processed to be |
| 388 // passed in a message pipe. See the comment about | 385 // passed in a message pipe. See the comment about |
| 389 // |Dispatcher::HandleTableAccess| for more details. | 386 // |Dispatcher::HandleTableAccess| for more details. |
| 390 // | 387 // |
| 391 // Note: This class is deliberately "thin" -- no more expensive than a | 388 // Note: This class is deliberately "thin" -- no more expensive than a |
| 392 // |Dispatcher*|. | 389 // |Dispatcher*|. |
| 393 class MOJO_SYSTEM_IMPL_EXPORT DispatcherTransport { | 390 class DispatcherTransport { |
| 394 public: | 391 public: |
| 395 DispatcherTransport() : dispatcher_(nullptr) {} | 392 DispatcherTransport() : dispatcher_(nullptr) {} |
| 396 | 393 |
| 397 void End() MOJO_NOT_THREAD_SAFE; | 394 void End() MOJO_NOT_THREAD_SAFE; |
| 398 | 395 |
| 399 Dispatcher::Type GetType() const { return dispatcher_->GetType(); } | 396 Dispatcher::Type GetType() const { return dispatcher_->GetType(); } |
| 400 bool IsBusy() const MOJO_NOT_THREAD_SAFE { | 397 bool IsBusy() const MOJO_NOT_THREAD_SAFE { |
| 401 return dispatcher_->IsBusyNoLock(); | 398 return dispatcher_->IsBusyNoLock(); |
| 402 } | 399 } |
| 403 void Close() MOJO_NOT_THREAD_SAFE { dispatcher_->CloseNoLock(); } | 400 void Close() MOJO_NOT_THREAD_SAFE { dispatcher_->CloseNoLock(); } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 416 | 413 |
| 417 explicit DispatcherTransport(Dispatcher* dispatcher) | 414 explicit DispatcherTransport(Dispatcher* dispatcher) |
| 418 : dispatcher_(dispatcher) {} | 415 : dispatcher_(dispatcher) {} |
| 419 | 416 |
| 420 Dispatcher* dispatcher_; | 417 Dispatcher* dispatcher_; |
| 421 | 418 |
| 422 // Copy and assign allowed. | 419 // Copy and assign allowed. |
| 423 }; | 420 }; |
| 424 | 421 |
| 425 // So logging macros and |DCHECK_EQ()|, etc. work. | 422 // So logging macros and |DCHECK_EQ()|, etc. work. |
| 426 MOJO_SYSTEM_IMPL_EXPORT inline std::ostream& operator<<(std::ostream& out, | 423 inline std::ostream& operator<<(std::ostream& out, Dispatcher::Type type) { |
| 427 Dispatcher::Type type) { | |
| 428 return out << static_cast<int>(type); | 424 return out << static_cast<int>(type); |
| 429 } | 425 } |
| 430 | 426 |
| 431 } // namespace system | 427 } // namespace system |
| 432 } // namespace mojo | 428 } // namespace mojo |
| 433 | 429 |
| 434 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ | 430 #endif // MOJO_EDK_SYSTEM_DISPATCHER_H_ |
| OLD | NEW |