| 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 <stdint.h> | 9 #include <stdint.h> |
| 9 | 10 |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "mojo/edk/embedder/platform_handle_vector.h" |
| 16 #include "mojo/edk/system/dispatcher.h" | 18 #include "mojo/edk/system/dispatcher.h" |
| 17 #include "mojo/edk/system/handle_signals_state.h" | 19 #include "mojo/edk/system/handle_signals_state.h" |
| 18 #include "mojo/edk/system/memory.h" | 20 #include "mojo/edk/system/memory.h" |
| 19 #include "mojo/edk/system/message_in_transit.h" | 21 #include "mojo/edk/system/message_in_transit.h" |
| 20 #include "mojo/edk/system/message_pipe_endpoint.h" | 22 #include "mojo/edk/system/message_pipe_endpoint.h" |
| 21 #include "mojo/edk/system/system_impl_export.h" | 23 #include "mojo/edk/system/system_impl_export.h" |
| 22 #include "mojo/public/c/system/message_pipe.h" | 24 #include "mojo/public/c/system/message_pipe.h" |
| 23 #include "mojo/public/c/system/types.h" | 25 #include "mojo/public/c/system/types.h" |
| 24 | 26 |
| 25 namespace mojo { | 27 namespace mojo { |
| 26 namespace system { | 28 namespace system { |
| 27 | 29 |
| 30 class Channel; |
| 28 class ChannelEndpoint; | 31 class ChannelEndpoint; |
| 29 class Waiter; | 32 class Waiter; |
| 30 | 33 |
| 31 // |MessagePipe| is the secondary object implementing a message pipe (see the | 34 // |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) | 35 // explanatory comment in core.cc). It is typically owned by the dispatcher(s) |
| 33 // corresponding to the local endpoints. This class is thread-safe. | 36 // corresponding to the local endpoints. This class is thread-safe. |
| 34 class MOJO_SYSTEM_IMPL_EXPORT MessagePipe | 37 class MOJO_SYSTEM_IMPL_EXPORT MessagePipe |
| 35 : public base::RefCountedThreadSafe<MessagePipe> { | 38 : public base::RefCountedThreadSafe<MessagePipe> { |
| 36 public: | 39 public: |
| 37 // Creates a |MessagePipe| with two new |LocalMessagePipeEndpoint|s. | 40 // Creates a |MessagePipe| with two new |LocalMessagePipeEndpoint|s. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 48 // (newly-created) |ChannelEndpoint| for the former. | 51 // (newly-created) |ChannelEndpoint| for the former. |
| 49 // Note: This is really only needed in tests (outside of tests, this | 52 // Note: This is really only needed in tests (outside of tests, this |
| 50 // configuration arises from a local message pipe having its port 0 | 53 // configuration arises from a local message pipe having its port 0 |
| 51 // "converted" using |ConvertLocalToProxy()|). | 54 // "converted" using |ConvertLocalToProxy()|). |
| 52 static MessagePipe* CreateProxyLocal( | 55 static MessagePipe* CreateProxyLocal( |
| 53 scoped_refptr<ChannelEndpoint>* channel_endpoint); | 56 scoped_refptr<ChannelEndpoint>* channel_endpoint); |
| 54 | 57 |
| 55 // Gets the other port number (i.e., 0 -> 1, 1 -> 0). | 58 // Gets the other port number (i.e., 0 -> 1, 1 -> 0). |
| 56 static unsigned GetPeerPort(unsigned port); | 59 static unsigned GetPeerPort(unsigned port); |
| 57 | 60 |
| 61 // Used by |MessagePipeDispatcher::Deserialize()|. Returns true on success (in |
| 62 // which case, |*message_pipe|/|*port| are set appropriately) and false on |
| 63 // failure (in which case |*message_pipe| may or may not be set to null). |
| 64 static bool Deserialize(Channel* channel, |
| 65 const void* source, |
| 66 size_t size, |
| 67 scoped_refptr<MessagePipe>* message_pipe, |
| 68 unsigned* port); |
| 69 |
| 58 // Gets the type of the endpoint (used for assertions, etc.). | 70 // Gets the type of the endpoint (used for assertions, etc.). |
| 59 MessagePipeEndpoint::Type GetType(unsigned port); | 71 MessagePipeEndpoint::Type GetType(unsigned port); |
| 60 | 72 |
| 61 // These are called by the dispatcher to implement its methods of | 73 // These are called by the dispatcher to implement its methods of |
| 62 // corresponding names. In all cases, the port |port| must be open. | 74 // corresponding names. In all cases, the port |port| must be open. |
| 63 void CancelAllWaiters(unsigned port); | 75 void CancelAllWaiters(unsigned port); |
| 64 void Close(unsigned port); | 76 void Close(unsigned port); |
| 65 // Unlike |MessagePipeDispatcher::WriteMessage()|, this does not validate its | 77 // Unlike |MessagePipeDispatcher::WriteMessage()|, this does not validate its |
| 66 // arguments. | 78 // arguments. |
| 67 MojoResult WriteMessage(unsigned port, | 79 MojoResult WriteMessage(unsigned port, |
| 68 UserPointer<const void> bytes, | 80 UserPointer<const void> bytes, |
| 69 uint32_t num_bytes, | 81 uint32_t num_bytes, |
| 70 std::vector<DispatcherTransport>* transports, | 82 std::vector<DispatcherTransport>* transports, |
| 71 MojoWriteMessageFlags flags); | 83 MojoWriteMessageFlags flags); |
| 72 MojoResult ReadMessage(unsigned port, | 84 MojoResult ReadMessage(unsigned port, |
| 73 UserPointer<void> bytes, | 85 UserPointer<void> bytes, |
| 74 UserPointer<uint32_t> num_bytes, | 86 UserPointer<uint32_t> num_bytes, |
| 75 DispatcherVector* dispatchers, | 87 DispatcherVector* dispatchers, |
| 76 uint32_t* num_dispatchers, | 88 uint32_t* num_dispatchers, |
| 77 MojoReadMessageFlags flags); | 89 MojoReadMessageFlags flags); |
| 78 HandleSignalsState GetHandleSignalsState(unsigned port) const; | 90 HandleSignalsState GetHandleSignalsState(unsigned port) const; |
| 79 MojoResult AddWaiter(unsigned port, | 91 MojoResult AddWaiter(unsigned port, |
| 80 Waiter* waiter, | 92 Waiter* waiter, |
| 81 MojoHandleSignals signals, | 93 MojoHandleSignals signals, |
| 82 uint32_t context, | 94 uint32_t context, |
| 83 HandleSignalsState* signals_state); | 95 HandleSignalsState* signals_state); |
| 84 void RemoveWaiter(unsigned port, | 96 void RemoveWaiter(unsigned port, |
| 85 Waiter* waiter, | 97 Waiter* waiter, |
| 86 HandleSignalsState* signals_state); | 98 HandleSignalsState* signals_state); |
| 99 void StartSerialize(unsigned port, |
| 100 Channel* channel, |
| 101 size_t* max_size, |
| 102 size_t* max_platform_handles); |
| 103 bool EndSerialize(unsigned port, |
| 104 Channel* channel, |
| 105 void* destination, |
| 106 size_t* actual_size, |
| 107 embedder::PlatformHandleVector* platform_handles); |
| 87 | 108 |
| 88 // This is called by the dispatcher to convert a local endpoint to a proxy | 109 // Used by |EndSerialize()|. TODO(vtl): Remove this (merge it into |
| 89 // endpoint. | 110 // |EndSerialize()|). |
| 90 scoped_refptr<ChannelEndpoint> ConvertLocalToProxy(unsigned port); | 111 scoped_refptr<ChannelEndpoint> ConvertLocalToProxy(unsigned port); |
| 91 | 112 |
| 92 // This is used by |Channel| to enqueue messages (typically to a | 113 // This is used by |Channel| to enqueue messages (typically to a |
| 93 // |LocalMessagePipeEndpoint|). Unlike |WriteMessage()|, |port| is the | 114 // |LocalMessagePipeEndpoint|). Unlike |WriteMessage()|, |port| is the |
| 94 // *destination* port. | 115 // *destination* port. |
| 95 MojoResult EnqueueMessage(unsigned port, | 116 MojoResult EnqueueMessage(unsigned port, |
| 96 scoped_ptr<MessageInTransit> message); | 117 scoped_ptr<MessageInTransit> message); |
| 97 | 118 |
| 98 private: | 119 private: |
| 99 MessagePipe(); | 120 MessagePipe(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 123 base::Lock lock_; // Protects the following members. | 144 base::Lock lock_; // Protects the following members. |
| 124 scoped_ptr<MessagePipeEndpoint> endpoints_[2]; | 145 scoped_ptr<MessagePipeEndpoint> endpoints_[2]; |
| 125 | 146 |
| 126 DISALLOW_COPY_AND_ASSIGN(MessagePipe); | 147 DISALLOW_COPY_AND_ASSIGN(MessagePipe); |
| 127 }; | 148 }; |
| 128 | 149 |
| 129 } // namespace system | 150 } // namespace system |
| 130 } // namespace mojo | 151 } // namespace mojo |
| 131 | 152 |
| 132 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_H_ | 153 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_H_ |
| OLD | NEW |