| 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 <vector> |
| 9 |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | 11 #include "base/callback.h" |
| 10 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 13 #include "mojo/public/system/core.h" | 15 #include "mojo/public/system/core.h" |
| 14 #include "mojo/public/system/system_export.h" | 16 #include "mojo/public/system/system_export.h" |
| 15 #include "mojo/system/message_in_transit.h" | 17 #include "mojo/system/message_in_transit.h" |
| 16 | 18 |
| 17 namespace mojo { | 19 namespace mojo { |
| 18 namespace system { | 20 namespace system { |
| 19 | 21 |
| 20 class Channel; | 22 class Channel; |
| 23 class Dispatcher; |
| 21 class MessagePipeEndpoint; | 24 class MessagePipeEndpoint; |
| 22 class Waiter; | 25 class Waiter; |
| 23 | 26 |
| 24 // |MessagePipe| is the secondary object implementing a message pipe (see the | 27 // |MessagePipe| is the secondary object implementing a message pipe (see the |
| 25 // explanatory comment in core_impl.cc). It is typically owned by the | 28 // explanatory comment in core_impl.cc). It is typically owned by the |
| 26 // dispatcher(s) corresponding to the local endpoints. This class is | 29 // dispatcher(s) corresponding to the local endpoints. This class is |
| 27 // thread-safe. | 30 // thread-safe. |
| 28 class MOJO_SYSTEM_EXPORT MessagePipe : | 31 class MOJO_SYSTEM_EXPORT MessagePipe : |
| 29 public base::RefCountedThreadSafe<MessagePipe> { | 32 public base::RefCountedThreadSafe<MessagePipe> { |
| 30 public: | 33 public: |
| 31 MessagePipe(scoped_ptr<MessagePipeEndpoint> endpoint_0, | 34 MessagePipe(scoped_ptr<MessagePipeEndpoint> endpoint_0, |
| 32 scoped_ptr<MessagePipeEndpoint> endpoint_1); | 35 scoped_ptr<MessagePipeEndpoint> endpoint_1); |
| 33 | 36 |
| 34 // Convenience constructor that constructs a |MessagePipe| with two new | 37 // Convenience constructor that constructs a |MessagePipe| with two new |
| 35 // |LocalMessagePipeEndpoint|s. | 38 // |LocalMessagePipeEndpoint|s. |
| 36 MessagePipe(); | 39 MessagePipe(); |
| 37 | 40 |
| 38 // Gets the other port number (i.e., 0 -> 1, 1 -> 0). | 41 // Gets the other port number (i.e., 0 -> 1, 1 -> 0). |
| 39 static unsigned GetPeerPort(unsigned port); | 42 static unsigned GetPeerPort(unsigned port); |
| 40 | 43 |
| 41 // These are called by the dispatcher to implement its methods of | 44 // These are called by the dispatcher to implement its methods of |
| 42 // corresponding names. In all cases, the port |port| must be open. | 45 // corresponding names. In all cases, the port |port| must be open. |
| 43 void CancelAllWaiters(unsigned port); | 46 void CancelAllWaiters(unsigned port); |
| 44 void Close(unsigned port); | 47 void Close(unsigned port); |
| 45 // Unlike |MessagePipeDispatcher::WriteMessage()|, this does not validate its | 48 // Unlike |MessagePipeDispatcher::WriteMessage()|, this does not validate its |
| 46 // arguments. |bytes|/|num_bytes| and |handles|/|num_handles| must be valid. | 49 // arguments. |
| 47 MojoResult WriteMessage(unsigned port, | 50 MojoResult WriteMessage(unsigned port, |
| 48 const void* bytes, uint32_t num_bytes, | 51 const void* bytes, uint32_t num_bytes, |
| 49 const MojoHandle* handles, uint32_t num_handles, | 52 const std::vector<Dispatcher*>* dispatchers, |
| 50 MojoWriteMessageFlags flags); | 53 MojoWriteMessageFlags flags); |
| 51 // Unlike |MessagePipeDispatcher::ReadMessage()|, this does not validate its | 54 // Unlike |MessagePipeDispatcher::ReadMessage()|, this does not validate its |
| 52 // arguments. |bytes|/|num_bytes| and |handles|/|num_handles| must be valid. | 55 // arguments. |
| 53 MojoResult ReadMessage(unsigned port, | 56 MojoResult ReadMessage(unsigned port, |
| 54 void* bytes, uint32_t* num_bytes, | 57 void* bytes, uint32_t* num_bytes, |
| 55 MojoHandle* handles, uint32_t* num_handles, | 58 uint32_t max_num_dispatchers, |
| 59 std::vector<scoped_refptr<Dispatcher> >* dispatchers, |
| 56 MojoReadMessageFlags flags); | 60 MojoReadMessageFlags flags); |
| 57 MojoResult AddWaiter(unsigned port, | 61 MojoResult AddWaiter(unsigned port, |
| 58 Waiter* waiter, | 62 Waiter* waiter, |
| 59 MojoWaitFlags flags, | 63 MojoWaitFlags flags, |
| 60 MojoResult wake_result); | 64 MojoResult wake_result); |
| 61 void RemoveWaiter(unsigned port, Waiter* waiter); | 65 void RemoveWaiter(unsigned port, Waiter* waiter); |
| 62 | 66 |
| 63 // This is used internally by |WriteMessage()| and by |Channel| to enqueue | 67 // This is used internally by |WriteMessage()| and by |Channel| to enqueue |
| 64 // messages (typically to a |LocalMessagePipeEndpoint|). Unlike | 68 // messages (typically to a |LocalMessagePipeEndpoint|). Unlike |
| 65 // |WriteMessage()|, |port| is the *destination* port. Takes ownership of | 69 // |WriteMessage()|, |port| is the *destination* port. Takes ownership of |
| (...skipping 17 matching lines...) Expand all Loading... |
| 83 base::Lock lock_; // Protects the following members. | 87 base::Lock lock_; // Protects the following members. |
| 84 scoped_ptr<MessagePipeEndpoint> endpoints_[2]; | 88 scoped_ptr<MessagePipeEndpoint> endpoints_[2]; |
| 85 | 89 |
| 86 DISALLOW_COPY_AND_ASSIGN(MessagePipe); | 90 DISALLOW_COPY_AND_ASSIGN(MessagePipe); |
| 87 }; | 91 }; |
| 88 | 92 |
| 89 } // namespace system | 93 } // namespace system |
| 90 } // namespace mojo | 94 } // namespace mojo |
| 91 | 95 |
| 92 #endif // MOJO_SYSTEM_MESSAGE_PIPE_H_ | 96 #endif // MOJO_SYSTEM_MESSAGE_PIPE_H_ |
| OLD | NEW |