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