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_ENDPOINT_H_ | 5 #ifndef MOJO_SYSTEM_MESSAGE_PIPE_ENDPOINT_H_ |
6 #define MOJO_SYSTEM_MESSAGE_PIPE_ENDPOINT_H_ | 6 #define MOJO_SYSTEM_MESSAGE_PIPE_ENDPOINT_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/ref_counted.h" |
9 #include "mojo/public/system/core.h" | 10 #include "mojo/public/system/core.h" |
| 11 #include "mojo/system/message_in_transit.h" |
10 | 12 |
11 namespace mojo { | 13 namespace mojo { |
12 namespace system { | 14 namespace system { |
13 | 15 |
| 16 class Channel; |
14 class Waiter; | 17 class Waiter; |
15 | 18 |
16 // This is an interface to one of the ends of a message pipe, and is used by | 19 // This is an interface to one of the ends of a message pipe, and is used by |
17 // |MessagePipe|. Its most important role is to provide a sink for messages | 20 // |MessagePipe|. Its most important role is to provide a sink for messages |
18 // (i.e., a place where messages can be sent). It has a secondary role: When the | 21 // (i.e., a place where messages can be sent). It has a secondary role: When the |
19 // endpoint is local (i.e., in the current process), there'll be a dispatcher | 22 // endpoint is local (i.e., in the current process), there'll be a dispatcher |
20 // corresponding to the endpoint. In that case, the implementation of | 23 // corresponding to the endpoint. In that case, the implementation of |
21 // |MessagePipeEndpoint| also implements the functionality required by the | 24 // |MessagePipeEndpoint| also implements the functionality required by the |
22 // dispatcher, e.g., to read messages and to wait. Implementations of this class | 25 // dispatcher, e.g., to read messages and to wait. Implementations of this class |
23 // are not thread-safe; instances are protected by |MesssagePipe|'s lock. | 26 // are not thread-safe; instances are protected by |MesssagePipe|'s lock. |
24 class MessagePipeEndpoint { | 27 class MessagePipeEndpoint { |
25 public: | 28 public: |
26 virtual ~MessagePipeEndpoint() {} | 29 virtual ~MessagePipeEndpoint() {} |
27 | 30 |
28 // All implementations must implement these. | 31 // All implementations must implement these. |
29 virtual void OnPeerClose() = 0; | 32 virtual void Close() = 0; |
30 virtual MojoResult EnqueueMessage( | 33 // Returns false if the endpoint should be closed and destroyed, else true. |
31 const void* bytes, uint32_t num_bytes, | 34 virtual bool OnPeerClose() = 0; |
32 const MojoHandle* handles, uint32_t num_handles, | 35 // Takes ownership of |message|. |
33 MojoWriteMessageFlags flags) = 0; | 36 virtual MojoResult EnqueueMessage(MessageInTransit* message) = 0; |
34 | 37 |
35 // Implementations must override these if they represent a local endpoint, | 38 // Implementations must override these if they represent a local endpoint, |
36 // i.e., one for which there's a |MessagePipeDispatcher| (and thus a handle). | 39 // i.e., one for which there's a |MessagePipeDispatcher| (and thus a handle). |
37 // An implementation for a remote endpoint (for which there's no dispatcher) | 40 // An implementation for a proxy endpoint (for which there's no dispatcher) |
38 // needs not override these methods, since they should never be called. | 41 // needs not override these methods, since they should never be called. |
39 // | 42 // |
40 // These methods implement the methods of the same name in |MessagePipe|, | 43 // These methods implement the methods of the same name in |MessagePipe|, |
41 // though |MessagePipe|'s implementation may have to do a little more if the | 44 // though |MessagePipe|'s implementation may have to do a little more if the |
42 // operation involves both endpoints. | 45 // operation involves both endpoints. |
43 virtual void CancelAllWaiters(); | 46 virtual void CancelAllWaiters(); |
44 virtual void Close(); | |
45 virtual MojoResult ReadMessage(void* bytes, uint32_t* num_bytes, | 47 virtual MojoResult ReadMessage(void* bytes, uint32_t* num_bytes, |
46 MojoHandle* handles, uint32_t* num_handles, | 48 MojoHandle* handles, uint32_t* num_handles, |
47 MojoReadMessageFlags flags); | 49 MojoReadMessageFlags flags); |
48 virtual MojoResult AddWaiter(Waiter* waiter, | 50 virtual MojoResult AddWaiter(Waiter* waiter, |
49 MojoWaitFlags flags, | 51 MojoWaitFlags flags, |
50 MojoResult wake_result); | 52 MojoResult wake_result); |
51 virtual void RemoveWaiter(Waiter* waiter); | 53 virtual void RemoveWaiter(Waiter* waiter); |
52 | 54 |
| 55 // Implementations must override these if they represent a proxy endpoint. An |
| 56 // implementation for a local endpoint needs not override these methods, since |
| 57 // they should never be called. |
| 58 virtual void Attach(scoped_refptr<Channel> channel, |
| 59 MessageInTransit::EndpointId local_id); |
| 60 // Returns false if the endpoint should be closed and destroyed, else true. |
| 61 virtual bool Run(MessageInTransit::EndpointId remote_id); |
| 62 |
53 protected: | 63 protected: |
54 MessagePipeEndpoint() {} | 64 MessagePipeEndpoint() {} |
55 | 65 |
56 private: | 66 private: |
57 DISALLOW_COPY_AND_ASSIGN(MessagePipeEndpoint); | 67 DISALLOW_COPY_AND_ASSIGN(MessagePipeEndpoint); |
58 }; | 68 }; |
59 | 69 |
60 } // namespace system | 70 } // namespace system |
61 } // namespace mojo | 71 } // namespace mojo |
62 | 72 |
63 #endif // MOJO_SYSTEM_MESSAGE_PIPE_ENDPOINT_H_ | 73 #endif // MOJO_SYSTEM_MESSAGE_PIPE_ENDPOINT_H_ |
OLD | NEW |