| 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_SYSTEM_MESSAGE_PIPE_H_ | 5 #ifndef MOJO_SYSTEM_MESSAGE_PIPE_H_ |
| 6 #define MOJO_SYSTEM_MESSAGE_PIPE_H_ | 6 #define MOJO_SYSTEM_MESSAGE_PIPE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 class ChannelEndpoint; | 28 class ChannelEndpoint; |
| 29 class Waiter; | 29 class Waiter; |
| 30 | 30 |
| 31 // |MessagePipe| is the secondary object implementing a message pipe (see the | 31 // |MessagePipe| is the secondary object implementing a message pipe (see the |
| 32 // explanatory comment in core.cc). It is typically owned by the dispatcher(s) | 32 // explanatory comment in core.cc). It is typically owned by the dispatcher(s) |
| 33 // corresponding to the local endpoints. This class is thread-safe. | 33 // corresponding to the local endpoints. This class is thread-safe. |
| 34 class MOJO_SYSTEM_IMPL_EXPORT MessagePipe | 34 class MOJO_SYSTEM_IMPL_EXPORT MessagePipe |
| 35 : public base::RefCountedThreadSafe<MessagePipe> { | 35 : public base::RefCountedThreadSafe<MessagePipe> { |
| 36 public: | 36 public: |
| 37 MessagePipe(scoped_ptr<MessagePipeEndpoint> endpoint0, | |
| 38 scoped_ptr<MessagePipeEndpoint> endpoint1); | |
| 39 | |
| 40 // Creates a |MessagePipe| with two new |LocalMessagePipeEndpoint|s. | 37 // Creates a |MessagePipe| with two new |LocalMessagePipeEndpoint|s. |
| 41 static MessagePipe* CreateLocalLocal(); | 38 static MessagePipe* CreateLocalLocal(); |
| 42 | 39 |
| 43 // Creates a |MessagePipe| with a |LocalMessagePipeEndpoint| on port 0 and a | 40 // Creates a |MessagePipe| with a |LocalMessagePipeEndpoint| on port 0 and a |
| 44 // |ProxyMessagePipeEndpoint| on port 1. | 41 // |ProxyMessagePipeEndpoint| on port 1. |*channel_endpoint| is set to the |
| 45 static MessagePipe* CreateLocalProxy(); | 42 // (newly-created) |ChannelEndpoint| for the latter. |
| 43 static MessagePipe* CreateLocalProxy( |
| 44 scoped_refptr<ChannelEndpoint>* channel_endpoint); |
| 46 | 45 |
| 47 // Creates a |MessagePipe| with a |ProxyMessagePipeEndpoint| on port 0 and a | 46 // Creates a |MessagePipe| with a |ProxyMessagePipeEndpoint| on port 0 and a |
| 48 // |LocalMessagePipeEndpoint| on port 1. | 47 // |LocalMessagePipeEndpoint| on port 1. |*channel_endpoint| is set to the |
| 48 // (newly-created) |ChannelEndpoint| for the former. |
| 49 // Note: This is really only needed in tests (outside of tests, this | 49 // Note: This is really only needed in tests (outside of tests, this |
| 50 // configuration arises from a local message pipe having its port 0 | 50 // configuration arises from a local message pipe having its port 0 |
| 51 // "converted" using |ConvertLocalToProxy()|). | 51 // "converted" using |ConvertLocalToProxy()|). |
| 52 static MessagePipe* CreateProxyLocal(); | 52 static MessagePipe* CreateProxyLocal( |
| 53 scoped_refptr<ChannelEndpoint>* channel_endpoint); |
| 53 | 54 |
| 54 // Gets the other port number (i.e., 0 -> 1, 1 -> 0). | 55 // Gets the other port number (i.e., 0 -> 1, 1 -> 0). |
| 55 static unsigned GetPeerPort(unsigned port); | 56 static unsigned GetPeerPort(unsigned port); |
| 56 | 57 |
| 57 // Gets the type of the endpoint (used for assertions, etc.). | 58 // Gets the type of the endpoint (used for assertions, etc.). |
| 58 MessagePipeEndpoint::Type GetType(unsigned port); | 59 MessagePipeEndpoint::Type GetType(unsigned port); |
| 59 | 60 |
| 60 // These are called by the dispatcher to implement its methods of | 61 // These are called by the dispatcher to implement its methods of |
| 61 // corresponding names. In all cases, the port |port| must be open. | 62 // corresponding names. In all cases, the port |port| must be open. |
| 62 void CancelAllWaiters(unsigned port); | 63 void CancelAllWaiters(unsigned port); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 88 // endpoint. | 89 // endpoint. |
| 89 scoped_refptr<ChannelEndpoint> ConvertLocalToProxy(unsigned port); | 90 scoped_refptr<ChannelEndpoint> ConvertLocalToProxy(unsigned port); |
| 90 | 91 |
| 91 // This is used by |Channel| to enqueue messages (typically to a | 92 // This is used by |Channel| to enqueue messages (typically to a |
| 92 // |LocalMessagePipeEndpoint|). Unlike |WriteMessage()|, |port| is the | 93 // |LocalMessagePipeEndpoint|). Unlike |WriteMessage()|, |port| is the |
| 93 // *destination* port. | 94 // *destination* port. |
| 94 MojoResult EnqueueMessage(unsigned port, | 95 MojoResult EnqueueMessage(unsigned port, |
| 95 scoped_ptr<MessageInTransit> message); | 96 scoped_ptr<MessageInTransit> message); |
| 96 | 97 |
| 97 // These are used by |Channel|. | 98 // These are used by |Channel|. |
| 99 // TODO(vtl): Remove |Attach()|. |
| 98 bool Attach(unsigned port, ChannelEndpoint* channel_endpoint); | 100 bool Attach(unsigned port, ChannelEndpoint* channel_endpoint); |
| 99 void Run(unsigned port); | 101 void Run(unsigned port); |
| 100 void OnRemove(unsigned port); | 102 void OnRemove(unsigned port); |
| 101 | 103 |
| 102 private: | 104 private: |
| 105 MessagePipe(); |
| 106 |
| 103 friend class base::RefCountedThreadSafe<MessagePipe>; | 107 friend class base::RefCountedThreadSafe<MessagePipe>; |
| 104 virtual ~MessagePipe(); | 108 virtual ~MessagePipe(); |
| 105 | 109 |
| 106 // This is used internally by |WriteMessage()| and by |EnqueueMessage()|. | 110 // This is used internally by |WriteMessage()| and by |EnqueueMessage()|. |
| 107 // |transports| may be non-null only if it's nonempty and |message| has no | 111 // |transports| may be non-null only if it's nonempty and |message| has no |
| 108 // dispatchers attached. | 112 // dispatchers attached. |
| 109 MojoResult EnqueueMessageInternal( | 113 MojoResult EnqueueMessageInternal( |
| 110 unsigned port, | 114 unsigned port, |
| 111 scoped_ptr<MessageInTransit> message, | 115 scoped_ptr<MessageInTransit> message, |
| 112 std::vector<DispatcherTransport>* transports); | 116 std::vector<DispatcherTransport>* transports); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 125 base::Lock lock_; // Protects the following members. | 129 base::Lock lock_; // Protects the following members. |
| 126 scoped_ptr<MessagePipeEndpoint> endpoints_[2]; | 130 scoped_ptr<MessagePipeEndpoint> endpoints_[2]; |
| 127 | 131 |
| 128 DISALLOW_COPY_AND_ASSIGN(MessagePipe); | 132 DISALLOW_COPY_AND_ASSIGN(MessagePipe); |
| 129 }; | 133 }; |
| 130 | 134 |
| 131 } // namespace system | 135 } // namespace system |
| 132 } // namespace mojo | 136 } // namespace mojo |
| 133 | 137 |
| 134 #endif // MOJO_SYSTEM_MESSAGE_PIPE_H_ | 138 #endif // MOJO_SYSTEM_MESSAGE_PIPE_H_ |
| OLD | NEW |