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 10 matching lines...) Expand all Loading... |
21 #include "mojo/edk/system/memory.h" | 21 #include "mojo/edk/system/memory.h" |
22 #include "mojo/edk/system/message_in_transit.h" | 22 #include "mojo/edk/system/message_in_transit.h" |
23 #include "mojo/edk/system/message_pipe_endpoint.h" | 23 #include "mojo/edk/system/message_pipe_endpoint.h" |
24 #include "mojo/edk/system/system_impl_export.h" | 24 #include "mojo/edk/system/system_impl_export.h" |
25 #include "mojo/public/c/system/message_pipe.h" | 25 #include "mojo/public/c/system/message_pipe.h" |
26 #include "mojo/public/c/system/types.h" | 26 #include "mojo/public/c/system/types.h" |
27 | 27 |
28 namespace mojo { | 28 namespace mojo { |
29 namespace system { | 29 namespace system { |
30 | 30 |
| 31 class Awakable; |
31 class Channel; | 32 class Channel; |
32 class ChannelEndpoint; | 33 class ChannelEndpoint; |
33 class Waiter; | |
34 | 34 |
35 // |MessagePipe| is the secondary object implementing a message pipe (see the | 35 // |MessagePipe| is the secondary object implementing a message pipe (see the |
36 // explanatory comment in core.cc). It is typically owned by the dispatcher(s) | 36 // explanatory comment in core.cc). It is typically owned by the dispatcher(s) |
37 // corresponding to the local endpoints. This class is thread-safe. | 37 // corresponding to the local endpoints. This class is thread-safe. |
38 class MOJO_SYSTEM_IMPL_EXPORT MessagePipe : public ChannelEndpointClient { | 38 class MOJO_SYSTEM_IMPL_EXPORT MessagePipe : public ChannelEndpointClient { |
39 public: | 39 public: |
40 // Creates a |MessagePipe| with two new |LocalMessagePipeEndpoint|s. | 40 // Creates a |MessagePipe| with two new |LocalMessagePipeEndpoint|s. |
41 static MessagePipe* CreateLocalLocal(); | 41 static MessagePipe* CreateLocalLocal(); |
42 | 42 |
43 // Creates a |MessagePipe| with a |LocalMessagePipeEndpoint| on port 0 and a | 43 // Creates a |MessagePipe| with a |LocalMessagePipeEndpoint| on port 0 and a |
(...skipping 21 matching lines...) Expand all Loading... |
65 const void* source, | 65 const void* source, |
66 size_t size, | 66 size_t size, |
67 scoped_refptr<MessagePipe>* message_pipe, | 67 scoped_refptr<MessagePipe>* message_pipe, |
68 unsigned* port); | 68 unsigned* port); |
69 | 69 |
70 // Gets the type of the endpoint (used for assertions, etc.). | 70 // Gets the type of the endpoint (used for assertions, etc.). |
71 MessagePipeEndpoint::Type GetType(unsigned port); | 71 MessagePipeEndpoint::Type GetType(unsigned port); |
72 | 72 |
73 // These are called by the dispatcher to implement its methods of | 73 // These are called by the dispatcher to implement its methods of |
74 // corresponding names. In all cases, the port |port| must be open. | 74 // corresponding names. In all cases, the port |port| must be open. |
75 void CancelAllWaiters(unsigned port); | 75 void CancelAllAwakables(unsigned port); |
76 void Close(unsigned port); | 76 void Close(unsigned port); |
77 // Unlike |MessagePipeDispatcher::WriteMessage()|, this does not validate its | 77 // Unlike |MessagePipeDispatcher::WriteMessage()|, this does not validate its |
78 // arguments. | 78 // arguments. |
79 MojoResult WriteMessage(unsigned port, | 79 MojoResult WriteMessage(unsigned port, |
80 UserPointer<const void> bytes, | 80 UserPointer<const void> bytes, |
81 uint32_t num_bytes, | 81 uint32_t num_bytes, |
82 std::vector<DispatcherTransport>* transports, | 82 std::vector<DispatcherTransport>* transports, |
83 MojoWriteMessageFlags flags); | 83 MojoWriteMessageFlags flags); |
84 MojoResult ReadMessage(unsigned port, | 84 MojoResult ReadMessage(unsigned port, |
85 UserPointer<void> bytes, | 85 UserPointer<void> bytes, |
86 UserPointer<uint32_t> num_bytes, | 86 UserPointer<uint32_t> num_bytes, |
87 DispatcherVector* dispatchers, | 87 DispatcherVector* dispatchers, |
88 uint32_t* num_dispatchers, | 88 uint32_t* num_dispatchers, |
89 MojoReadMessageFlags flags); | 89 MojoReadMessageFlags flags); |
90 HandleSignalsState GetHandleSignalsState(unsigned port) const; | 90 HandleSignalsState GetHandleSignalsState(unsigned port) const; |
91 MojoResult AddWaiter(unsigned port, | 91 MojoResult AddAwakable(unsigned port, |
92 Waiter* waiter, | 92 Awakable* awakable, |
93 MojoHandleSignals signals, | 93 MojoHandleSignals signals, |
94 uint32_t context, | 94 uint32_t context, |
95 HandleSignalsState* signals_state); | 95 HandleSignalsState* signals_state); |
96 void RemoveWaiter(unsigned port, | 96 void RemoveAwakable(unsigned port, |
97 Waiter* waiter, | 97 Awakable* awakable, |
98 HandleSignalsState* signals_state); | 98 HandleSignalsState* signals_state); |
99 void StartSerialize(unsigned port, | 99 void StartSerialize(unsigned port, |
100 Channel* channel, | 100 Channel* channel, |
101 size_t* max_size, | 101 size_t* max_size, |
102 size_t* max_platform_handles); | 102 size_t* max_platform_handles); |
103 bool EndSerialize(unsigned port, | 103 bool EndSerialize(unsigned port, |
104 Channel* channel, | 104 Channel* channel, |
105 void* destination, | 105 void* destination, |
106 size_t* actual_size, | 106 size_t* actual_size, |
107 embedder::PlatformHandleVector* platform_handles); | 107 embedder::PlatformHandleVector* platform_handles); |
108 | 108 |
109 // |ChannelEndpointClient| methods: | 109 // |ChannelEndpointClient| methods: |
110 void OnReadMessage(unsigned port, | 110 bool OnReadMessage(unsigned port, MessageInTransit* message) override; |
111 scoped_ptr<MessageInTransit> message) override; | |
112 void OnDetachFromChannel(unsigned port) override; | 111 void OnDetachFromChannel(unsigned port) override; |
113 | 112 |
114 private: | 113 private: |
115 MessagePipe(); | 114 MessagePipe(); |
116 virtual ~MessagePipe(); | 115 virtual ~MessagePipe(); |
117 | 116 |
118 // This is used internally by |WriteMessage()| and by |OnReadMessage()|. | 117 // This is used internally by |WriteMessage()| and by |OnReadMessage()|. |
119 // |transports| may be non-null only if it's nonempty and |message| has no | 118 // |transports| may be non-null only if it's nonempty and |message| has no |
120 // dispatchers attached. | 119 // dispatchers attached. Must be called with |lock_| held. |
121 MojoResult EnqueueMessage(unsigned port, | 120 MojoResult EnqueueMessageNoLock(unsigned port, |
122 scoped_ptr<MessageInTransit> message, | 121 scoped_ptr<MessageInTransit> message, |
123 std::vector<DispatcherTransport>* transports); | 122 std::vector<DispatcherTransport>* transports); |
124 | 123 |
125 // Helper for |EnqueueMessage()|. Must be called with |lock_| held. | 124 // Helper for |EnqueueMessageNoLock()|. Must be called with |lock_| held. |
126 MojoResult AttachTransportsNoLock( | 125 MojoResult AttachTransportsNoLock( |
127 unsigned port, | 126 unsigned port, |
128 MessageInTransit* message, | 127 MessageInTransit* message, |
129 std::vector<DispatcherTransport>* transports); | 128 std::vector<DispatcherTransport>* transports); |
130 | 129 |
131 base::Lock lock_; // Protects the following members. | 130 base::Lock lock_; // Protects the following members. |
132 scoped_ptr<MessagePipeEndpoint> endpoints_[2]; | 131 scoped_ptr<MessagePipeEndpoint> endpoints_[2]; |
133 | 132 |
134 DISALLOW_COPY_AND_ASSIGN(MessagePipe); | 133 DISALLOW_COPY_AND_ASSIGN(MessagePipe); |
135 }; | 134 }; |
136 | 135 |
137 } // namespace system | 136 } // namespace system |
138 } // namespace mojo | 137 } // namespace mojo |
139 | 138 |
140 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_H_ | 139 #endif // MOJO_EDK_SYSTEM_MESSAGE_PIPE_H_ |
OLD | NEW |