| 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_CONSUMER_DISPATCHER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_DATA_PIPE_CONSUMER_DISPATCHER_H_ |
| 6 #define MOJO_EDK_SYSTEM_DATA_PIPE_CONSUMER_DISPATCHER_H_ | 6 #define MOJO_EDK_SYSTEM_DATA_PIPE_CONSUMER_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/embedder/scoped_platform_handle.h" | 18 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 19 #include "mojo/edk/system/awakable_list.h" | 19 #include "mojo/edk/system/awakable_list.h" |
| 20 #include "mojo/edk/system/dispatcher.h" | 20 #include "mojo/edk/system/dispatcher.h" |
| 21 #include "mojo/edk/system/ports/port_ref.h" | 21 #include "mojo/edk/system/ports/port_ref.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_set.h" | |
| 24 | 23 |
| 25 namespace mojo { | 24 namespace mojo { |
| 26 namespace edk { | 25 namespace edk { |
| 27 | 26 |
| 28 class NodeController; | 27 class NodeController; |
| 29 | 28 |
| 30 // This is the Dispatcher implementation for the consumer handle for data | 29 // This is the Dispatcher implementation for the consumer handle for data |
| 31 // pipes created by the Mojo primitive MojoCreateDataPipe(). This class is | 30 // pipes created by the Mojo primitive MojoCreateDataPipe(). This class is |
| 32 // thread-safe. | 31 // thread-safe. |
| 33 class MOJO_SYSTEM_IMPL_EXPORT DataPipeConsumerDispatcher final | 32 class MOJO_SYSTEM_IMPL_EXPORT DataPipeConsumerDispatcher final |
| 34 : public Dispatcher { | 33 : public Dispatcher { |
| 35 public: | 34 public: |
| 36 DataPipeConsumerDispatcher( | 35 DataPipeConsumerDispatcher( |
| 37 NodeController* node_controller, | 36 NodeController* node_controller, |
| 38 const ports::PortRef& control_port, | 37 const ports::PortRef& control_port, |
| 39 scoped_refptr<PlatformSharedBuffer> shared_ring_buffer, | 38 scoped_refptr<PlatformSharedBuffer> shared_ring_buffer, |
| 40 const MojoCreateDataPipeOptions& options, | 39 const MojoCreateDataPipeOptions& options, |
| 41 bool initialized, | 40 bool initialized, |
| 42 uint64_t pipe_id); | 41 uint64_t pipe_id); |
| 43 | 42 |
| 44 // Dispatcher: | 43 // Dispatcher: |
| 45 Type GetType() const override; | 44 Type GetType() const override; |
| 46 MojoResult Close() override; | 45 MojoResult Close() override; |
| 46 MojoResult Watch(MojoHandleSignals signals, |
| 47 const Watcher::WatchCallback& callback, |
| 48 uintptr_t context) override; |
| 49 MojoResult CancelWatch(uintptr_t context) override; |
| 47 MojoResult ReadData(void* elements, | 50 MojoResult ReadData(void* elements, |
| 48 uint32_t* num_bytes, | 51 uint32_t* num_bytes, |
| 49 MojoReadDataFlags flags) override; | 52 MojoReadDataFlags flags) override; |
| 50 MojoResult BeginReadData(const void** buffer, | 53 MojoResult BeginReadData(const void** buffer, |
| 51 uint32_t* buffer_num_bytes, | 54 uint32_t* buffer_num_bytes, |
| 52 MojoReadDataFlags flags) override; | 55 MojoReadDataFlags flags) override; |
| 53 MojoResult EndReadData(uint32_t num_bytes_read) override; | 56 MojoResult EndReadData(uint32_t num_bytes_read) override; |
| 54 HandleSignalsState GetHandleSignalsState() const override; | 57 HandleSignalsState GetHandleSignalsState() const override; |
| 55 MojoResult AddWatcherRef(const scoped_refptr<WatcherDispatcher>& watcher, | |
| 56 uintptr_t context) override; | |
| 57 MojoResult RemoveWatcherRef(WatcherDispatcher* watcher, | |
| 58 uintptr_t context) override; | |
| 59 MojoResult AddAwakable(Awakable* awakable, | 58 MojoResult AddAwakable(Awakable* awakable, |
| 60 MojoHandleSignals signals, | 59 MojoHandleSignals signals, |
| 61 uintptr_t context, | 60 uintptr_t context, |
| 62 HandleSignalsState* signals_state) override; | 61 HandleSignalsState* signals_state) override; |
| 63 void RemoveAwakable(Awakable* awakable, | 62 void RemoveAwakable(Awakable* awakable, |
| 64 HandleSignalsState* signals_state) override; | 63 HandleSignalsState* signals_state) override; |
| 65 void StartSerialize(uint32_t* num_bytes, | 64 void StartSerialize(uint32_t* num_bytes, |
| 66 uint32_t* num_ports, | 65 uint32_t* num_ports, |
| 67 uint32_t* num_handles) override; | 66 uint32_t* num_handles) override; |
| 68 bool EndSerialize(void* destination, | 67 bool EndSerialize(void* destination, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 95 | 94 |
| 96 const MojoCreateDataPipeOptions options_; | 95 const MojoCreateDataPipeOptions options_; |
| 97 NodeController* const node_controller_; | 96 NodeController* const node_controller_; |
| 98 const ports::PortRef control_port_; | 97 const ports::PortRef control_port_; |
| 99 const uint64_t pipe_id_; | 98 const uint64_t pipe_id_; |
| 100 | 99 |
| 101 // Guards access to the fields below. | 100 // Guards access to the fields below. |
| 102 mutable base::Lock lock_; | 101 mutable base::Lock lock_; |
| 103 | 102 |
| 104 AwakableList awakable_list_; | 103 AwakableList awakable_list_; |
| 105 WatcherSet watchers_; | |
| 106 | 104 |
| 107 scoped_refptr<PlatformSharedBuffer> shared_ring_buffer_; | 105 scoped_refptr<PlatformSharedBuffer> shared_ring_buffer_; |
| 108 std::unique_ptr<PlatformSharedBufferMapping> ring_buffer_mapping_; | 106 std::unique_ptr<PlatformSharedBufferMapping> ring_buffer_mapping_; |
| 109 ScopedPlatformHandle buffer_handle_for_transit_; | 107 ScopedPlatformHandle buffer_handle_for_transit_; |
| 110 | 108 |
| 111 bool in_two_phase_read_ = false; | 109 bool in_two_phase_read_ = false; |
| 112 uint32_t two_phase_max_bytes_read_ = 0; | 110 uint32_t two_phase_max_bytes_read_ = 0; |
| 113 | 111 |
| 114 bool in_transit_ = false; | 112 bool in_transit_ = false; |
| 115 bool is_closed_ = false; | 113 bool is_closed_ = false; |
| 116 bool peer_closed_ = false; | 114 bool peer_closed_ = false; |
| 117 bool transferred_ = false; | 115 bool transferred_ = false; |
| 118 | 116 |
| 119 uint32_t read_offset_ = 0; | 117 uint32_t read_offset_ = 0; |
| 120 uint32_t bytes_available_ = 0; | 118 uint32_t bytes_available_ = 0; |
| 121 | 119 |
| 122 // Indicates whether any new data is available since the last read attempt. | 120 // Indicates whether any new data is available since the last read attempt. |
| 123 bool new_data_available_ = false; | 121 bool new_data_available_ = false; |
| 124 | 122 |
| 125 DISALLOW_COPY_AND_ASSIGN(DataPipeConsumerDispatcher); | 123 DISALLOW_COPY_AND_ASSIGN(DataPipeConsumerDispatcher); |
| 126 }; | 124 }; |
| 127 | 125 |
| 128 } // namespace edk | 126 } // namespace edk |
| 129 } // namespace mojo | 127 } // namespace mojo |
| 130 | 128 |
| 131 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_CONSUMER_DISPATCHER_H_ | 129 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_CONSUMER_DISPATCHER_H_ |
| OLD | NEW |