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