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_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ |
7 | 7 |
8 #include "mojo/public/c/environment/async_waiter.h" | 8 #include "mojo/public/c/environment/async_waiter.h" |
9 #include "mojo/public/cpp/bindings/lib/message_queue.h" | 9 #include "mojo/public/cpp/bindings/lib/message_queue.h" |
10 #include "mojo/public/cpp/bindings/message.h" | 10 #include "mojo/public/cpp/bindings/message.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // MessageReceiver interface assigned as its incoming receiver. | 22 // MessageReceiver interface assigned as its incoming receiver. |
23 // | 23 // |
24 // NOTE: MessagePipe I/O is non-blocking. | 24 // NOTE: MessagePipe I/O is non-blocking. |
25 // | 25 // |
26 class Connector : public MessageReceiver { | 26 class Connector : public MessageReceiver { |
27 public: | 27 public: |
28 // The Connector takes ownership of |message_pipe|. | 28 // The Connector takes ownership of |message_pipe|. |
29 explicit Connector( | 29 explicit Connector( |
30 ScopedMessagePipeHandle message_pipe, | 30 ScopedMessagePipeHandle message_pipe, |
31 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()); | 31 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()); |
32 virtual ~Connector(); | 32 ~Connector() override; |
33 | 33 |
34 // Sets the receiver to handle messages read from the message pipe. The | 34 // Sets the receiver to handle messages read from the message pipe. The |
35 // Connector will read messages from the pipe regardless of whether or not an | 35 // Connector will read messages from the pipe regardless of whether or not an |
36 // incoming receiver has been set. | 36 // incoming receiver has been set. |
37 void set_incoming_receiver(MessageReceiver* receiver) { | 37 void set_incoming_receiver(MessageReceiver* receiver) { |
38 incoming_receiver_ = receiver; | 38 incoming_receiver_ = receiver; |
39 } | 39 } |
40 | 40 |
41 // Errors from incoming receivers will force the connector into an error | 41 // Errors from incoming receivers will force the connector into an error |
42 // state, where no more messages will be processed. This method is used | 42 // state, where no more messages will be processed. This method is used |
(...skipping 19 matching lines...) Expand all Loading... |
62 // Releases the pipe, not triggering the error state. Connector is put into | 62 // Releases the pipe, not triggering the error state. Connector is put into |
63 // a quiescent state. | 63 // a quiescent state. |
64 ScopedMessagePipeHandle PassMessagePipe(); | 64 ScopedMessagePipeHandle PassMessagePipe(); |
65 | 65 |
66 // Waits for the next message on the pipe, blocking until one arrives or an | 66 // Waits for the next message on the pipe, blocking until one arrives or an |
67 // error happens. Returns |true| if a message has been delivered, |false| | 67 // error happens. Returns |true| if a message has been delivered, |false| |
68 // otherwise. | 68 // otherwise. |
69 bool WaitForIncomingMessage(); | 69 bool WaitForIncomingMessage(); |
70 | 70 |
71 // MessageReceiver implementation: | 71 // MessageReceiver implementation: |
72 virtual bool Accept(Message* message) override; | 72 bool Accept(Message* message) override; |
73 | 73 |
74 private: | 74 private: |
75 static void CallOnHandleReady(void* closure, MojoResult result); | 75 static void CallOnHandleReady(void* closure, MojoResult result); |
76 void OnHandleReady(MojoResult result); | 76 void OnHandleReady(MojoResult result); |
77 | 77 |
78 void WaitToReadMore(); | 78 void WaitToReadMore(); |
79 | 79 |
80 // Returns false if |this| was destroyed during message dispatch. | 80 // Returns false if |this| was destroyed during message dispatch. |
81 MOJO_WARN_UNUSED_RESULT bool ReadSingleMessage(MojoResult* read_result); | 81 MOJO_WARN_UNUSED_RESULT bool ReadSingleMessage(MojoResult* read_result); |
82 | 82 |
(...skipping 21 matching lines...) Expand all Loading... |
104 // of dispatching an incoming message. | 104 // of dispatching an incoming message. |
105 bool* destroyed_flag_; | 105 bool* destroyed_flag_; |
106 | 106 |
107 MOJO_DISALLOW_COPY_AND_ASSIGN(Connector); | 107 MOJO_DISALLOW_COPY_AND_ASSIGN(Connector); |
108 }; | 108 }; |
109 | 109 |
110 } // namespace internal | 110 } // namespace internal |
111 } // namespace mojo | 111 } // namespace mojo |
112 | 112 |
113 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ | 113 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ |
OLD | NEW |