| 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_DATA_PIPE_PRODUCER_DISPATCHER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_ |
| 6 #define MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_ | 6 #define MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_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 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "mojo/edk/embedder/platform_handle_vector.h" | 16 #include "mojo/edk/embedder/platform_handle_vector.h" |
| 17 #include "mojo/edk/embedder/platform_shared_buffer.h" | 17 #include "mojo/edk/embedder/platform_shared_buffer.h" |
| 18 #include "mojo/edk/system/awakable_list.h" | 18 #include "mojo/edk/system/awakable_list.h" |
| 19 #include "mojo/edk/system/dispatcher.h" | 19 #include "mojo/edk/system/dispatcher.h" |
| 20 #include "mojo/edk/system/ports/port_ref.h" | 20 #include "mojo/edk/system/ports/port_ref.h" |
| 21 #include "mojo/edk/system/system_impl_export.h" | 21 #include "mojo/edk/system/system_impl_export.h" |
| 22 #include "mojo/edk/system/watcher_set.h" |
| 22 | 23 |
| 23 namespace mojo { | 24 namespace mojo { |
| 24 namespace edk { | 25 namespace edk { |
| 25 | 26 |
| 26 struct DataPipeControlMessage; | 27 struct DataPipeControlMessage; |
| 27 class NodeController; | 28 class NodeController; |
| 28 | 29 |
| 29 // This is the Dispatcher implementation for the producer handle for data | 30 // This is the Dispatcher implementation for the producer handle for data |
| 30 // pipes created by the Mojo primitive MojoCreateDataPipe(). This class is | 31 // pipes created by the Mojo primitive MojoCreateDataPipe(). This class is |
| 31 // thread-safe. | 32 // thread-safe. |
| 32 class MOJO_SYSTEM_IMPL_EXPORT DataPipeProducerDispatcher final | 33 class MOJO_SYSTEM_IMPL_EXPORT DataPipeProducerDispatcher final |
| 33 : public Dispatcher { | 34 : public Dispatcher { |
| 34 public: | 35 public: |
| 35 DataPipeProducerDispatcher( | 36 DataPipeProducerDispatcher( |
| 36 NodeController* node_controller, | 37 NodeController* node_controller, |
| 37 const ports::PortRef& port, | 38 const ports::PortRef& port, |
| 38 scoped_refptr<PlatformSharedBuffer> shared_ring_buffer, | 39 scoped_refptr<PlatformSharedBuffer> shared_ring_buffer, |
| 39 const MojoCreateDataPipeOptions& options, | 40 const MojoCreateDataPipeOptions& options, |
| 40 bool initialized, | 41 bool initialized, |
| 41 uint64_t pipe_id); | 42 uint64_t pipe_id); |
| 42 | 43 |
| 43 // Dispatcher: | 44 // Dispatcher: |
| 44 Type GetType() const override; | 45 Type GetType() const override; |
| 45 MojoResult Close() override; | 46 MojoResult Close() override; |
| 46 MojoResult Watch(MojoHandleSignals signals, | 47 MojoResult RegisterWatcher(MojoHandleSignals signals, |
| 47 const Watcher::WatchCallback& callback, | 48 const Watcher::WatchCallback& callback, |
| 48 uintptr_t context) override; | 49 uintptr_t context) override; |
| 49 MojoResult CancelWatch(uintptr_t context) override; | 50 MojoResult ArmWatcher(uintptr_t context) override; |
| 51 MojoResult UnregisterWatcher(uintptr_t context) override; |
| 50 MojoResult WriteData(const void* elements, | 52 MojoResult WriteData(const void* elements, |
| 51 uint32_t* num_bytes, | 53 uint32_t* num_bytes, |
| 52 MojoReadDataFlags flags) override; | 54 MojoReadDataFlags flags) override; |
| 53 MojoResult BeginWriteData(void** buffer, | 55 MojoResult BeginWriteData(void** buffer, |
| 54 uint32_t* buffer_num_bytes, | 56 uint32_t* buffer_num_bytes, |
| 55 MojoWriteDataFlags flags) override; | 57 MojoWriteDataFlags flags) override; |
| 56 MojoResult EndWriteData(uint32_t num_bytes_written) override; | 58 MojoResult EndWriteData(uint32_t num_bytes_written) override; |
| 57 HandleSignalsState GetHandleSignalsState() const override; | 59 HandleSignalsState GetHandleSignalsState() const override; |
| 58 MojoResult AddAwakable(Awakable* awakable, | 60 MojoResult AddAwakable(Awakable* awakable, |
| 59 MojoHandleSignals signals, | 61 MojoHandleSignals signals, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 99 |
| 98 const MojoCreateDataPipeOptions options_; | 100 const MojoCreateDataPipeOptions options_; |
| 99 NodeController* const node_controller_; | 101 NodeController* const node_controller_; |
| 100 const ports::PortRef control_port_; | 102 const ports::PortRef control_port_; |
| 101 const uint64_t pipe_id_; | 103 const uint64_t pipe_id_; |
| 102 | 104 |
| 103 // Guards access to the fields below. | 105 // Guards access to the fields below. |
| 104 mutable base::Lock lock_; | 106 mutable base::Lock lock_; |
| 105 | 107 |
| 106 AwakableList awakable_list_; | 108 AwakableList awakable_list_; |
| 109 WatcherSet watchers_; |
| 107 | 110 |
| 108 bool buffer_requested_ = false; | 111 bool buffer_requested_ = false; |
| 109 | 112 |
| 110 scoped_refptr<PlatformSharedBuffer> shared_ring_buffer_; | 113 scoped_refptr<PlatformSharedBuffer> shared_ring_buffer_; |
| 111 std::unique_ptr<PlatformSharedBufferMapping> ring_buffer_mapping_; | 114 std::unique_ptr<PlatformSharedBufferMapping> ring_buffer_mapping_; |
| 112 ScopedPlatformHandle buffer_handle_for_transit_; | 115 ScopedPlatformHandle buffer_handle_for_transit_; |
| 113 | 116 |
| 114 bool in_transit_ = false; | 117 bool in_transit_ = false; |
| 115 bool is_closed_ = false; | 118 bool is_closed_ = false; |
| 116 bool peer_closed_ = false; | 119 bool peer_closed_ = false; |
| 117 bool transferred_ = false; | 120 bool transferred_ = false; |
| 118 bool in_two_phase_write_ = false; | 121 bool in_two_phase_write_ = false; |
| 119 | 122 |
| 120 uint32_t write_offset_ = 0; | 123 uint32_t write_offset_ = 0; |
| 121 uint32_t available_capacity_; | 124 uint32_t available_capacity_; |
| 122 | 125 |
| 123 DISALLOW_COPY_AND_ASSIGN(DataPipeProducerDispatcher); | 126 DISALLOW_COPY_AND_ASSIGN(DataPipeProducerDispatcher); |
| 124 }; | 127 }; |
| 125 | 128 |
| 126 } // namespace edk | 129 } // namespace edk |
| 127 } // namespace mojo | 130 } // namespace mojo |
| 128 | 131 |
| 129 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_ | 132 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_ |
| OLD | NEW |