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_MESSAGE_PIPE_H_ | 5 #ifndef MOJO_EDK_SYSTEM_MESSAGE_PIPE_H_ |
6 #define MOJO_EDK_SYSTEM_MESSAGE_PIPE_H_ | 6 #define MOJO_EDK_SYSTEM_MESSAGE_PIPE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 class Channel; | 32 class Channel; |
33 class ChannelEndpoint; | 33 class ChannelEndpoint; |
34 class MessageInTransitQueue; | 34 class MessageInTransitQueue; |
35 | 35 |
36 // |MessagePipe| is the secondary object implementing a message pipe (see the | 36 // |MessagePipe| is the secondary object implementing a message pipe (see the |
37 // explanatory comment in core.cc). It is typically owned by the dispatcher(s) | 37 // explanatory comment in core.cc). It is typically owned by the dispatcher(s) |
38 // corresponding to the local endpoints. This class is thread-safe. | 38 // corresponding to the local endpoints. This class is thread-safe. |
39 class MessagePipe final : public ChannelEndpointClient { | 39 class MessagePipe final : public ChannelEndpointClient { |
40 public: | 40 public: |
41 // Creates a |MessagePipe| with two new |LocalMessagePipeEndpoint|s. | 41 // Creates a |MessagePipe| with two new |LocalMessagePipeEndpoint|s. |
42 static MessagePipe* CreateLocalLocal(); | 42 static RefPtr<MessagePipe> CreateLocalLocal(); |
43 | 43 |
44 // Creates a |MessagePipe| with a |LocalMessagePipeEndpoint| on port 0 and a | 44 // Creates a |MessagePipe| with a |LocalMessagePipeEndpoint| on port 0 and a |
45 // |ProxyMessagePipeEndpoint| on port 1. |*channel_endpoint| is set to the | 45 // |ProxyMessagePipeEndpoint| on port 1. |*channel_endpoint| is set to the |
46 // (newly-created) |ChannelEndpoint| for the latter. | 46 // (newly-created) |ChannelEndpoint| for the latter. |
47 static MessagePipe* CreateLocalProxy( | 47 static RefPtr<MessagePipe> CreateLocalProxy( |
48 RefPtr<ChannelEndpoint>* channel_endpoint); | 48 RefPtr<ChannelEndpoint>* channel_endpoint); |
49 | 49 |
50 // Similar to |CreateLocalProxy()|, except that it'll do so from an existing | 50 // Similar to |CreateLocalProxy()|, except that it'll do so from an existing |
51 // |ChannelEndpoint| (whose |ReplaceClient()| it'll call) and take | 51 // |ChannelEndpoint| (whose |ReplaceClient()| it'll call) and take |
52 // |message_queue|'s contents as already-received incoming messages. If | 52 // |message_queue|'s contents as already-received incoming messages. If |
53 // |channel_endpoint| is null, this will create a "half-open" message pipe. | 53 // |channel_endpoint| is null, this will create a "half-open" message pipe. |
54 static MessagePipe* CreateLocalProxyFromExisting( | 54 static RefPtr<MessagePipe> CreateLocalProxyFromExisting( |
55 MessageInTransitQueue* message_queue, | 55 MessageInTransitQueue* message_queue, |
56 RefPtr<ChannelEndpoint>&& channel_endpoint); | 56 RefPtr<ChannelEndpoint>&& channel_endpoint); |
57 | 57 |
58 // Creates a |MessagePipe| with a |ProxyMessagePipeEndpoint| on port 0 and a | 58 // Creates a |MessagePipe| with a |ProxyMessagePipeEndpoint| on port 0 and a |
59 // |LocalMessagePipeEndpoint| on port 1. |*channel_endpoint| is set to the | 59 // |LocalMessagePipeEndpoint| on port 1. |*channel_endpoint| is set to the |
60 // (newly-created) |ChannelEndpoint| for the former. | 60 // (newly-created) |ChannelEndpoint| for the former. |
61 // Note: This is really only needed in tests (outside of tests, this | 61 // Note: This is really only needed in tests (outside of tests, this |
62 // configuration arises from a local message pipe having its port 0 | 62 // configuration arises from a local message pipe having its port 0 |
63 // "converted" using |ConvertLocalToProxy()|). | 63 // "converted" using |ConvertLocalToProxy()|). |
64 static MessagePipe* CreateProxyLocal( | 64 static RefPtr<MessagePipe> CreateProxyLocal( |
65 RefPtr<ChannelEndpoint>* channel_endpoint); | 65 RefPtr<ChannelEndpoint>* channel_endpoint); |
66 | 66 |
67 // Gets the other port number (i.e., 0 -> 1, 1 -> 0). | 67 // Gets the other port number (i.e., 0 -> 1, 1 -> 0). |
68 static unsigned GetPeerPort(unsigned port); | 68 static unsigned GetPeerPort(unsigned port); |
69 | 69 |
70 // Used by |MessagePipeDispatcher::Deserialize()|. Returns true on success (in | 70 // Used by |MessagePipeDispatcher::Deserialize()|. Returns true on success (in |
71 // which case, |*message_pipe|/|*port| are set appropriately) and false on | 71 // which case, |*message_pipe|/|*port| are set appropriately) and false on |
72 // failure (in which case |*message_pipe| may or may not be set to null). | 72 // failure (in which case |*message_pipe| may or may not be set to null). |
73 static bool Deserialize(Channel* channel, | 73 static bool Deserialize(Channel* channel, |
74 const void* source, | 74 const void* source, |
75 size_t size, | 75 size_t size, |
76 scoped_refptr<MessagePipe>* message_pipe, | 76 RefPtr<MessagePipe>* message_pipe, |
77 unsigned* port); | 77 unsigned* port); |
78 | 78 |
79 // Gets the type of the endpoint (used for assertions, etc.). | 79 // Gets the type of the endpoint (used for assertions, etc.). |
80 MessagePipeEndpoint::Type GetType(unsigned port); | 80 MessagePipeEndpoint::Type GetType(unsigned port); |
81 | 81 |
82 // These are called by the dispatcher to implement its methods of | 82 // These are called by the dispatcher to implement its methods of |
83 // corresponding names. In all cases, the port |port| must be open. | 83 // corresponding names. In all cases, the port |port| must be open. |
84 void CancelAllAwakables(unsigned port); | 84 void CancelAllAwakables(unsigned port); |
85 void Close(unsigned port); | 85 void Close(unsigned port); |
86 // Unlike |MessagePipeDispatcher::WriteMessage()|, this does not validate its | 86 // Unlike |MessagePipeDispatcher::WriteMessage()|, this does not validate its |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 mutable Mutex mutex_; | 141 mutable Mutex mutex_; |
142 std::unique_ptr<MessagePipeEndpoint> endpoints_[2] MOJO_GUARDED_BY(mutex_); | 142 std::unique_ptr<MessagePipeEndpoint> endpoints_[2] MOJO_GUARDED_BY(mutex_); |
143 | 143 |
144 MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipe); | 144 MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipe); |
145 }; | 145 }; |
146 | 146 |
147 } // namespace system | 147 } // namespace system |
148 } // namespace mojo | 148 } // namespace mojo |
149 | 149 |
150 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_H_ | 150 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_H_ |
OLD | NEW |