OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_MESSAGE_PIPE_DISPATCHER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ |
6 #define MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ | 6 #define MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <queue> | 11 #include <queue> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "mojo/edk/system/atomic_flag.h" | 14 #include "mojo/edk/system/atomic_flag.h" |
15 #include "mojo/edk/system/awakable_list.h" | 15 #include "mojo/edk/system/awakable_list.h" |
16 #include "mojo/edk/system/dispatcher.h" | 16 #include "mojo/edk/system/dispatcher.h" |
17 #include "mojo/edk/system/message_for_transit.h" | 17 #include "mojo/edk/system/message_for_transit.h" |
18 #include "mojo/edk/system/ports/port_ref.h" | 18 #include "mojo/edk/system/ports/port_ref.h" |
19 #include "mojo/edk/system/watcher_set.h" | |
20 | 19 |
21 namespace mojo { | 20 namespace mojo { |
22 namespace edk { | 21 namespace edk { |
23 | 22 |
24 class NodeController; | 23 class NodeController; |
25 | 24 |
26 class MessagePipeDispatcher : public Dispatcher { | 25 class MessagePipeDispatcher : public Dispatcher { |
27 public: | 26 public: |
28 // Constructs a MessagePipeDispatcher permanently tied to a specific port. | 27 // Constructs a MessagePipeDispatcher permanently tied to a specific port. |
29 // |connected| must indicate the state of the port at construction time; if | 28 // |connected| must indicate the state of the port at construction time; if |
(...skipping 12 matching lines...) Expand all Loading... |
42 int endpoint); | 41 int endpoint); |
43 | 42 |
44 // Fuses this pipe with |other|. Returns |true| on success or |false| on | 43 // Fuses this pipe with |other|. Returns |true| on success or |false| on |
45 // failure. Regardless of the return value, both dispatchers are closed by | 44 // failure. Regardless of the return value, both dispatchers are closed by |
46 // this call. | 45 // this call. |
47 bool Fuse(MessagePipeDispatcher* other); | 46 bool Fuse(MessagePipeDispatcher* other); |
48 | 47 |
49 // Dispatcher: | 48 // Dispatcher: |
50 Type GetType() const override; | 49 Type GetType() const override; |
51 MojoResult Close() override; | 50 MojoResult Close() override; |
| 51 MojoResult Watch(MojoHandleSignals signals, |
| 52 const Watcher::WatchCallback& callback, |
| 53 uintptr_t context) override; |
| 54 MojoResult CancelWatch(uintptr_t context) override; |
52 MojoResult WriteMessage(std::unique_ptr<MessageForTransit> message, | 55 MojoResult WriteMessage(std::unique_ptr<MessageForTransit> message, |
53 MojoWriteMessageFlags flags) override; | 56 MojoWriteMessageFlags flags) override; |
54 MojoResult ReadMessage(std::unique_ptr<MessageForTransit>* message, | 57 MojoResult ReadMessage(std::unique_ptr<MessageForTransit>* message, |
55 uint32_t* num_bytes, | 58 uint32_t* num_bytes, |
56 MojoHandle* handles, | 59 MojoHandle* handles, |
57 uint32_t* num_handles, | 60 uint32_t* num_handles, |
58 MojoReadMessageFlags flags, | 61 MojoReadMessageFlags flags, |
59 bool read_any_size) override; | 62 bool read_any_size) override; |
60 HandleSignalsState GetHandleSignalsState() const override; | 63 HandleSignalsState GetHandleSignalsState() const override; |
61 MojoResult AddWatcherRef(const scoped_refptr<WatcherDispatcher>& watcher, | |
62 uintptr_t context) override; | |
63 MojoResult RemoveWatcherRef(WatcherDispatcher* watcher, | |
64 uintptr_t context) override; | |
65 MojoResult AddAwakable(Awakable* awakable, | 64 MojoResult AddAwakable(Awakable* awakable, |
66 MojoHandleSignals signals, | 65 MojoHandleSignals signals, |
67 uintptr_t context, | 66 uintptr_t context, |
68 HandleSignalsState* signals_state) override; | 67 HandleSignalsState* signals_state) override; |
69 void RemoveAwakable(Awakable* awakable, | 68 void RemoveAwakable(Awakable* awakable, |
70 HandleSignalsState* signals_state) override; | 69 HandleSignalsState* signals_state) override; |
71 void StartSerialize(uint32_t* num_bytes, | 70 void StartSerialize(uint32_t* num_bytes, |
72 uint32_t* num_ports, | 71 uint32_t* num_ports, |
73 uint32_t* num_handles) override; | 72 uint32_t* num_handles) override; |
74 bool EndSerialize(void* destination, | 73 bool EndSerialize(void* destination, |
(...skipping 30 matching lines...) Expand all Loading... |
105 // Guards access to all the fields below. | 104 // Guards access to all the fields below. |
106 mutable base::Lock signal_lock_; | 105 mutable base::Lock signal_lock_; |
107 | 106 |
108 // This is not the same is |port_transferred_|. It's only held true between | 107 // This is not the same is |port_transferred_|. It's only held true between |
109 // BeginTransit() and Complete/CancelTransit(). | 108 // BeginTransit() and Complete/CancelTransit(). |
110 AtomicFlag in_transit_; | 109 AtomicFlag in_transit_; |
111 | 110 |
112 bool port_transferred_ = false; | 111 bool port_transferred_ = false; |
113 AtomicFlag port_closed_; | 112 AtomicFlag port_closed_; |
114 AwakableList awakables_; | 113 AwakableList awakables_; |
115 WatcherSet watchers_; | |
116 | 114 |
117 DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher); | 115 DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher); |
118 }; | 116 }; |
119 | 117 |
120 } // namespace edk | 118 } // namespace edk |
121 } // namespace mojo | 119 } // namespace mojo |
122 | 120 |
123 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ | 121 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ |
OLD | NEW |