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" |
19 | 20 |
20 namespace mojo { | 21 namespace mojo { |
21 namespace edk { | 22 namespace edk { |
22 | 23 |
23 class NodeController; | 24 class NodeController; |
24 | 25 |
25 class MessagePipeDispatcher : public Dispatcher { | 26 class MessagePipeDispatcher : public Dispatcher { |
26 public: | 27 public: |
27 // Constructs a MessagePipeDispatcher permanently tied to a specific port. | 28 // Constructs a MessagePipeDispatcher permanently tied to a specific port. |
28 // |connected| must indicate the state of the port at construction time; if | 29 // |connected| must indicate the state of the port at construction time; if |
(...skipping 12 matching lines...) Expand all Loading... |
41 int endpoint); | 42 int endpoint); |
42 | 43 |
43 // Fuses this pipe with |other|. Returns |true| on success or |false| on | 44 // Fuses this pipe with |other|. Returns |true| on success or |false| on |
44 // failure. Regardless of the return value, both dispatchers are closed by | 45 // failure. Regardless of the return value, both dispatchers are closed by |
45 // this call. | 46 // this call. |
46 bool Fuse(MessagePipeDispatcher* other); | 47 bool Fuse(MessagePipeDispatcher* other); |
47 | 48 |
48 // Dispatcher: | 49 // Dispatcher: |
49 Type GetType() const override; | 50 Type GetType() const override; |
50 MojoResult Close() override; | 51 MojoResult Close() override; |
51 MojoResult Watch(MojoHandleSignals signals, | 52 MojoResult RegisterWatcher(MojoHandleSignals signals, |
52 const Watcher::WatchCallback& callback, | 53 const Watcher::WatchCallback& callback, |
53 uintptr_t context) override; | 54 uintptr_t context) override; |
54 MojoResult CancelWatch(uintptr_t context) override; | 55 MojoResult ArmWatcher(uintptr_t context) override; |
| 56 MojoResult UnregisterWatcher(uintptr_t context) override; |
55 MojoResult WriteMessage(std::unique_ptr<MessageForTransit> message, | 57 MojoResult WriteMessage(std::unique_ptr<MessageForTransit> message, |
56 MojoWriteMessageFlags flags) override; | 58 MojoWriteMessageFlags flags) override; |
57 MojoResult ReadMessage(std::unique_ptr<MessageForTransit>* message, | 59 MojoResult ReadMessage(std::unique_ptr<MessageForTransit>* message, |
58 uint32_t* num_bytes, | 60 uint32_t* num_bytes, |
59 MojoHandle* handles, | 61 MojoHandle* handles, |
60 uint32_t* num_handles, | 62 uint32_t* num_handles, |
61 MojoReadMessageFlags flags, | 63 MojoReadMessageFlags flags, |
62 bool read_any_size) override; | 64 bool read_any_size) override; |
63 HandleSignalsState GetHandleSignalsState() const override; | 65 HandleSignalsState GetHandleSignalsState() const override; |
64 MojoResult AddAwakable(Awakable* awakable, | 66 MojoResult AddAwakable(Awakable* awakable, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // Guards access to all the fields below. | 106 // Guards access to all the fields below. |
105 mutable base::Lock signal_lock_; | 107 mutable base::Lock signal_lock_; |
106 | 108 |
107 // This is not the same is |port_transferred_|. It's only held true between | 109 // This is not the same is |port_transferred_|. It's only held true between |
108 // BeginTransit() and Complete/CancelTransit(). | 110 // BeginTransit() and Complete/CancelTransit(). |
109 AtomicFlag in_transit_; | 111 AtomicFlag in_transit_; |
110 | 112 |
111 bool port_transferred_ = false; | 113 bool port_transferred_ = false; |
112 AtomicFlag port_closed_; | 114 AtomicFlag port_closed_; |
113 AwakableList awakables_; | 115 AwakableList awakables_; |
| 116 WatcherSet watchers_; |
114 | 117 |
115 DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher); | 118 DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher); |
116 }; | 119 }; |
117 | 120 |
118 } // namespace edk | 121 } // namespace edk |
119 } // namespace mojo | 122 } // namespace mojo |
120 | 123 |
121 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ | 124 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ |
OLD | NEW |