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 #include "mojo/system/message_pipe.h" | 5 #include "mojo/system/message_pipe.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "mojo/system/channel.h" | 9 #include "mojo/system/channel.h" |
10 #include "mojo/system/local_message_pipe_endpoint.h" | 10 #include "mojo/system/local_message_pipe_endpoint.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 endpoints_[destination_port]->Close(); | 57 endpoints_[destination_port]->Close(); |
58 endpoints_[destination_port].reset(); | 58 endpoints_[destination_port].reset(); |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 // TODO(vtl): Support sending handles. | 62 // TODO(vtl): Support sending handles. |
63 // TODO(vtl): Handle flags. | 63 // TODO(vtl): Handle flags. |
64 MojoResult MessagePipe::WriteMessage( | 64 MojoResult MessagePipe::WriteMessage( |
65 unsigned port, | 65 unsigned port, |
66 const void* bytes, uint32_t num_bytes, | 66 const void* bytes, uint32_t num_bytes, |
67 const std::vector<Dispatcher*>* /*dispatchers*/, | 67 const std::vector<Dispatcher*>* dispatchers, |
68 MojoWriteMessageFlags flags) { | 68 MojoWriteMessageFlags flags) { |
69 DCHECK(port == 0 || port == 1); | 69 DCHECK(port == 0 || port == 1); |
70 return EnqueueMessage( | 70 return EnqueueMessage( |
71 GetPeerPort(port), | 71 GetPeerPort(port), |
72 MessageInTransit::Create( | 72 MessageInTransit::Create( |
73 MessageInTransit::kTypeMessagePipeEndpoint, | 73 MessageInTransit::kTypeMessagePipeEndpoint, |
74 MessageInTransit::kSubtypeMessagePipeEndpointData, | 74 MessageInTransit::kSubtypeMessagePipeEndpointData, |
75 bytes, num_bytes)); | 75 bytes, num_bytes), |
| 76 dispatchers); |
76 } | 77 } |
77 | 78 |
78 MojoResult MessagePipe::ReadMessage( | 79 MojoResult MessagePipe::ReadMessage( |
79 unsigned port, | 80 unsigned port, |
80 void* bytes, uint32_t* num_bytes, | 81 void* bytes, uint32_t* num_bytes, |
81 uint32_t max_num_dispatchers, | 82 uint32_t max_num_dispatchers, |
82 std::vector<scoped_refptr<Dispatcher> >* dispatchers, | 83 std::vector<scoped_refptr<Dispatcher> >* dispatchers, |
83 MojoReadMessageFlags flags) { | 84 MojoReadMessageFlags flags) { |
84 DCHECK(port == 0 || port == 1); | 85 DCHECK(port == 0 || port == 1); |
85 | 86 |
86 base::AutoLock locker(lock_); | 87 base::AutoLock locker(lock_); |
87 DCHECK(endpoints_[port].get()); | 88 DCHECK(endpoints_[port].get()); |
88 | 89 |
89 return endpoints_[port]->ReadMessage(bytes, num_bytes, | 90 return endpoints_[port]->ReadMessage(bytes, num_bytes, |
90 NULL, NULL, | 91 max_num_dispatchers, dispatchers, |
91 flags); | 92 flags); |
92 } | 93 } |
93 | 94 |
94 MojoResult MessagePipe::AddWaiter(unsigned port, | 95 MojoResult MessagePipe::AddWaiter(unsigned port, |
95 Waiter* waiter, | 96 Waiter* waiter, |
96 MojoWaitFlags flags, | 97 MojoWaitFlags flags, |
97 MojoResult wake_result) { | 98 MojoResult wake_result) { |
98 DCHECK(port == 0 || port == 1); | 99 DCHECK(port == 0 || port == 1); |
99 | 100 |
100 base::AutoLock locker(lock_); | 101 base::AutoLock locker(lock_); |
101 DCHECK(endpoints_[port].get()); | 102 DCHECK(endpoints_[port].get()); |
102 | 103 |
103 return endpoints_[port]->AddWaiter(waiter, flags, wake_result); | 104 return endpoints_[port]->AddWaiter(waiter, flags, wake_result); |
104 } | 105 } |
105 | 106 |
106 void MessagePipe::RemoveWaiter(unsigned port, Waiter* waiter) { | 107 void MessagePipe::RemoveWaiter(unsigned port, Waiter* waiter) { |
107 DCHECK(port == 0 || port == 1); | 108 DCHECK(port == 0 || port == 1); |
108 | 109 |
109 base::AutoLock locker(lock_); | 110 base::AutoLock locker(lock_); |
110 DCHECK(endpoints_[port].get()); | 111 DCHECK(endpoints_[port].get()); |
111 | 112 |
112 endpoints_[port]->RemoveWaiter(waiter); | 113 endpoints_[port]->RemoveWaiter(waiter); |
113 } | 114 } |
114 | 115 |
115 MojoResult MessagePipe::EnqueueMessage(unsigned port, | 116 MojoResult MessagePipe::EnqueueMessage( |
116 MessageInTransit* message) { | 117 unsigned port, |
| 118 MessageInTransit* message, |
| 119 const std::vector<Dispatcher*>* dispatchers) { |
117 DCHECK(port == 0 || port == 1); | 120 DCHECK(port == 0 || port == 1); |
118 DCHECK(message); | 121 DCHECK(message); |
119 | 122 |
120 if (message->type() == MessageInTransit::kTypeMessagePipe) | 123 if (message->type() == MessageInTransit::kTypeMessagePipe) { |
| 124 DCHECK(!dispatchers); |
121 return HandleControlMessage(port, message); | 125 return HandleControlMessage(port, message); |
| 126 } |
122 | 127 |
123 DCHECK_EQ(message->type(), MessageInTransit::kTypeMessagePipeEndpoint); | 128 DCHECK_EQ(message->type(), MessageInTransit::kTypeMessagePipeEndpoint); |
124 | 129 |
125 base::AutoLock locker(lock_); | 130 base::AutoLock locker(lock_); |
126 DCHECK(endpoints_[GetPeerPort(port)].get()); | 131 DCHECK(endpoints_[GetPeerPort(port)].get()); |
127 | 132 |
128 // The destination port need not be open, unlike the source port. | 133 // The destination port need not be open, unlike the source port. |
129 if (!endpoints_[port].get()) { | 134 if (!endpoints_[port].get()) { |
130 message->Destroy(); | 135 message->Destroy(); |
131 return MOJO_RESULT_FAILED_PRECONDITION; | 136 return MOJO_RESULT_FAILED_PRECONDITION; |
132 } | 137 } |
133 | 138 |
134 return endpoints_[port]->EnqueueMessage(message); | 139 return endpoints_[port]->EnqueueMessage(message, dispatchers); |
135 } | 140 } |
136 | 141 |
137 void MessagePipe::Attach(unsigned port, | 142 void MessagePipe::Attach(unsigned port, |
138 scoped_refptr<Channel> channel, | 143 scoped_refptr<Channel> channel, |
139 MessageInTransit::EndpointId local_id) { | 144 MessageInTransit::EndpointId local_id) { |
140 DCHECK(port == 0 || port == 1); | 145 DCHECK(port == 0 || port == 1); |
141 DCHECK(channel.get()); | 146 DCHECK(channel.get()); |
142 DCHECK_NE(local_id, MessageInTransit::kInvalidEndpointId); | 147 DCHECK_NE(local_id, MessageInTransit::kInvalidEndpointId); |
143 | 148 |
144 base::AutoLock locker(lock_); | 149 base::AutoLock locker(lock_); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 rv = MOJO_RESULT_UNKNOWN; | 200 rv = MOJO_RESULT_UNKNOWN; |
196 break; | 201 break; |
197 } | 202 } |
198 | 203 |
199 message->Destroy(); | 204 message->Destroy(); |
200 return rv; | 205 return rv; |
201 } | 206 } |
202 | 207 |
203 } // namespace system | 208 } // namespace system |
204 } // namespace mojo | 209 } // namespace mojo |
OLD | NEW |