OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MOJO_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_ |
| 6 #define MOJO_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <deque> |
| 11 |
| 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/ref_counted.h" |
| 15 #include "mojo/public/system/core.h" |
| 16 #include "mojo/public/system/system_export.h" |
| 17 #include "mojo/system/message_in_transit.h" |
| 18 #include "mojo/system/message_pipe_endpoint.h" |
| 19 |
| 20 namespace mojo { |
| 21 namespace system { |
| 22 |
| 23 class Channel; |
| 24 |
| 25 // A |ProxyMessagePipeEndpoint| connects an end of a |MessagePipe| to a |
| 26 // |Channel|, over which it transmits and receives data (to/from another |
| 27 // |ProxyMessagePipeEndpoint|). So a |MessagePipe| with one endpoint local and |
| 28 // the other endpoint remote consists of a |LocalMessagePipeEndpoint| and a |
| 29 // |ProxyMessagePipeEndpoint|, with only the local endpoint being accessible via |
| 30 // a |MessagePipeDispatcher|. |
| 31 // |
| 32 // Like any |MessagePipeEndpoint|, a |ProxyMessagePipeEndpoint| is owned by a |
| 33 // |MessagePipe|. |
| 34 // - A |ProxyMessagePipeEndpoint| starts out *detached*, i.e., not associated |
| 35 // to any |Channel|. When *attached*, it gets a reference to a |Channel| and |
| 36 // is assigned a local ID. A |ProxyMessagePipeEndpoint| must be detached |
| 37 // before destruction; this is done inside |Close()|. |
| 38 // - When attached, a |ProxyMessagePipeEndpoint| starts out not running. When |
| 39 // run, it gets a remote ID. |
| 40 class MOJO_SYSTEM_EXPORT ProxyMessagePipeEndpoint : public MessagePipeEndpoint { |
| 41 public: |
| 42 ProxyMessagePipeEndpoint(); |
| 43 virtual ~ProxyMessagePipeEndpoint(); |
| 44 |
| 45 // |MessagePipeEndpoint| implementation: |
| 46 virtual void Close() OVERRIDE; |
| 47 virtual bool OnPeerClose() OVERRIDE; |
| 48 virtual MojoResult EnqueueMessage(MessageInTransit* message) OVERRIDE; |
| 49 virtual void Attach(scoped_refptr<Channel> channel, |
| 50 MessageInTransit::EndpointId local_id) OVERRIDE; |
| 51 virtual bool Run(MessageInTransit::EndpointId remote_id) OVERRIDE; |
| 52 |
| 53 private: |
| 54 bool is_attached() const { |
| 55 return !!channel_.get(); |
| 56 } |
| 57 |
| 58 bool is_running() const { |
| 59 return remote_id_ != MessageInTransit::kInvalidEndpointId; |
| 60 } |
| 61 |
| 62 #ifdef NDEBUG |
| 63 void AssertConsistentState() const {} |
| 64 #else |
| 65 void AssertConsistentState() const; |
| 66 #endif |
| 67 |
| 68 // This should only be set if we're attached. |
| 69 scoped_refptr<Channel> channel_; |
| 70 |
| 71 // |local_id_| should be set to something other than |
| 72 // |MessageInTransit::kInvalidEndpointId| when we're attached. |
| 73 MessageInTransit::EndpointId local_id_; |
| 74 |
| 75 // |remote_id_| being set to anything other than |
| 76 // |MessageInTransit::kInvalidEndpointId| indicates that we're "running", |
| 77 // i.e., actively able to send messages. We should only ever be running if |
| 78 // we're attached. |
| 79 MessageInTransit::EndpointId remote_id_; |
| 80 |
| 81 bool is_open_; |
| 82 bool is_peer_open_; |
| 83 |
| 84 // This queue is only used while we're detached, to store messages while we're |
| 85 // not ready to send them yet. |
| 86 std::deque<MessageInTransit*> paused_message_queue_; |
| 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(ProxyMessagePipeEndpoint); |
| 89 }; |
| 90 |
| 91 } // namespace system |
| 92 } // namespace mojo |
| 93 |
| 94 #endif // MOJO_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_ |
OLD | NEW |