| 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 "mojo/edk/system/dispatcher.h" | 8 #include "mojo/edk/system/dispatcher.h" |
| 9 #include "mojo/edk/system/ref_ptr.h" | 9 #include "mojo/edk/util/ref_ptr.h" |
| 10 #include "mojo/public/cpp/system/macros.h" | 10 #include "mojo/public/cpp/system/macros.h" |
| 11 | 11 |
| 12 namespace mojo { | 12 namespace mojo { |
| 13 namespace system { | 13 namespace system { |
| 14 | 14 |
| 15 class DataPipe; | 15 class DataPipe; |
| 16 | 16 |
| 17 // This is the |Dispatcher| implementation for the consumer handle for data | 17 // This is the |Dispatcher| implementation for the consumer handle for data |
| 18 // pipes (created by the Mojo primitive |MojoCreateDataPipe()|). This class is | 18 // pipes (created by the Mojo primitive |MojoCreateDataPipe()|). This class is |
| 19 // thread-safe. | 19 // thread-safe. |
| 20 class DataPipeConsumerDispatcher final : public Dispatcher { | 20 class DataPipeConsumerDispatcher final : public Dispatcher { |
| 21 public: | 21 public: |
| 22 static RefPtr<DataPipeConsumerDispatcher> Create() { | 22 static util::RefPtr<DataPipeConsumerDispatcher> Create() { |
| 23 return AdoptRef(new DataPipeConsumerDispatcher()); | 23 return AdoptRef(new DataPipeConsumerDispatcher()); |
| 24 } | 24 } |
| 25 | 25 |
| 26 // Must be called before any other methods. | 26 // Must be called before any other methods. |
| 27 void Init(RefPtr<DataPipe>&& data_pipe) MOJO_NOT_THREAD_SAFE; | 27 void Init(util::RefPtr<DataPipe>&& data_pipe) MOJO_NOT_THREAD_SAFE; |
| 28 | 28 |
| 29 // |Dispatcher| public methods: | 29 // |Dispatcher| public methods: |
| 30 Type GetType() const override; | 30 Type GetType() const override; |
| 31 | 31 |
| 32 // The "opposite" of |SerializeAndClose()|. (Typically this is called by | 32 // The "opposite" of |SerializeAndClose()|. (Typically this is called by |
| 33 // |Dispatcher::Deserialize()|.) | 33 // |Dispatcher::Deserialize()|.) |
| 34 static RefPtr<DataPipeConsumerDispatcher> Deserialize(Channel* channel, | 34 static util::RefPtr<DataPipeConsumerDispatcher> |
| 35 const void* source, | 35 Deserialize(Channel* channel, const void* source, size_t size); |
| 36 size_t size); | |
| 37 | 36 |
| 38 // Get access to the |DataPipe| for testing. | 37 // Get access to the |DataPipe| for testing. |
| 39 DataPipe* GetDataPipeForTest(); | 38 DataPipe* GetDataPipeForTest(); |
| 40 | 39 |
| 41 private: | 40 private: |
| 42 DataPipeConsumerDispatcher(); | 41 DataPipeConsumerDispatcher(); |
| 43 ~DataPipeConsumerDispatcher() override; | 42 ~DataPipeConsumerDispatcher() override; |
| 44 | 43 |
| 45 // |Dispatcher| protected methods: | 44 // |Dispatcher| protected methods: |
| 46 void CancelAllAwakablesNoLock() override; | 45 void CancelAllAwakablesNoLock() override; |
| 47 void CloseImplNoLock() override; | 46 void CloseImplNoLock() override; |
| 48 RefPtr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() override; | 47 util::RefPtr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() |
| 48 override; |
| 49 MojoResult ReadDataImplNoLock(UserPointer<void> elements, | 49 MojoResult ReadDataImplNoLock(UserPointer<void> elements, |
| 50 UserPointer<uint32_t> num_bytes, | 50 UserPointer<uint32_t> num_bytes, |
| 51 MojoReadDataFlags flags) override; | 51 MojoReadDataFlags flags) override; |
| 52 MojoResult BeginReadDataImplNoLock(UserPointer<const void*> buffer, | 52 MojoResult BeginReadDataImplNoLock(UserPointer<const void*> buffer, |
| 53 UserPointer<uint32_t> buffer_num_bytes, | 53 UserPointer<uint32_t> buffer_num_bytes, |
| 54 MojoReadDataFlags flags) override; | 54 MojoReadDataFlags flags) override; |
| 55 MojoResult EndReadDataImplNoLock(uint32_t num_bytes_read) override; | 55 MojoResult EndReadDataImplNoLock(uint32_t num_bytes_read) override; |
| 56 HandleSignalsState GetHandleSignalsStateImplNoLock() const override; | 56 HandleSignalsState GetHandleSignalsStateImplNoLock() const override; |
| 57 MojoResult AddAwakableImplNoLock(Awakable* awakable, | 57 MojoResult AddAwakableImplNoLock(Awakable* awakable, |
| 58 MojoHandleSignals signals, | 58 MojoHandleSignals signals, |
| 59 uint32_t context, | 59 uint32_t context, |
| 60 HandleSignalsState* signals_state) override; | 60 HandleSignalsState* signals_state) override; |
| 61 void RemoveAwakableImplNoLock(Awakable* awakable, | 61 void RemoveAwakableImplNoLock(Awakable* awakable, |
| 62 HandleSignalsState* signals_state) override; | 62 HandleSignalsState* signals_state) override; |
| 63 void StartSerializeImplNoLock(Channel* channel, | 63 void StartSerializeImplNoLock(Channel* channel, |
| 64 size_t* max_size, | 64 size_t* max_size, |
| 65 size_t* max_platform_handles) override | 65 size_t* max_platform_handles) override |
| 66 MOJO_NOT_THREAD_SAFE; | 66 MOJO_NOT_THREAD_SAFE; |
| 67 bool EndSerializeAndCloseImplNoLock( | 67 bool EndSerializeAndCloseImplNoLock( |
| 68 Channel* channel, | 68 Channel* channel, |
| 69 void* destination, | 69 void* destination, |
| 70 size_t* actual_size, | 70 size_t* actual_size, |
| 71 embedder::PlatformHandleVector* platform_handles) override | 71 embedder::PlatformHandleVector* platform_handles) override |
| 72 MOJO_NOT_THREAD_SAFE; | 72 MOJO_NOT_THREAD_SAFE; |
| 73 bool IsBusyNoLock() const override; | 73 bool IsBusyNoLock() const override; |
| 74 | 74 |
| 75 // This will be null if closed. | 75 // This will be null if closed. |
| 76 RefPtr<DataPipe> data_pipe_ MOJO_GUARDED_BY(mutex()); | 76 util::RefPtr<DataPipe> data_pipe_ MOJO_GUARDED_BY(mutex()); |
| 77 | 77 |
| 78 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeConsumerDispatcher); | 78 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeConsumerDispatcher); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 } // namespace system | 81 } // namespace system |
| 82 } // namespace mojo | 82 } // namespace mojo |
| 83 | 83 |
| 84 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_CONSUMER_DISPATCHER_H_ | 84 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_CONSUMER_DISPATCHER_H_ |
| OLD | NEW |