Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: mojo/public/bindings/lib/connector.h

Issue 134253004: Mojo: AsyncWaiter and mojo/public/environment (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing files Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_BINDINGS_LIB_CONNECTOR_H_ 5 #ifndef MOJO_PUBLIC_BINDINGS_LIB_CONNECTOR_H_
6 #define MOJO_PUBLIC_BINDINGS_LIB_CONNECTOR_H_ 6 #define MOJO_PUBLIC_BINDINGS_LIB_CONNECTOR_H_
7 7
8 #include "mojo/public/bindings/lib/bindings_support.h"
9 #include "mojo/public/bindings/lib/message.h" 8 #include "mojo/public/bindings/lib/message.h"
10 #include "mojo/public/bindings/lib/message_queue.h" 9 #include "mojo/public/bindings/lib/message_queue.h"
10 #include "mojo/public/environment/default_async_waiter.h"
11 #include "mojo/public/system/core_cpp.h" 11 #include "mojo/public/system/core_cpp.h"
12 12
13 namespace mojo { 13 namespace mojo {
14 namespace internal { 14 namespace internal {
15 15
16 // The Connector class is responsible for performing read/write operations on a 16 // The Connector class is responsible for performing read/write operations on a
17 // MessagePipe. It writes messages it receives through the MessageReceiver 17 // MessagePipe. It writes messages it receives through the MessageReceiver
18 // interface that it subclasses, and it forwards messages it reads through the 18 // interface that it subclasses, and it forwards messages it reads through the
19 // MessageReceiver interface assigned as its incoming receiver. 19 // MessageReceiver interface assigned as its incoming receiver.
20 // 20 //
21 // NOTE: MessagePipe I/O is non-blocking. 21 // NOTE: MessagePipe I/O is non-blocking.
22 // 22 //
23 class Connector : public MessageReceiver { 23 class Connector : public MessageReceiver {
24 public: 24 public:
25 // The Connector takes ownership of |message_pipe|. 25 // The Connector takes ownership of |message_pipe|.
26 explicit Connector(ScopedMessagePipeHandle message_pipe); 26 explicit Connector(ScopedMessagePipeHandle message_pipe,
27 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter());
27 virtual ~Connector(); 28 virtual ~Connector();
28 29
29 // Sets the receiver to handle messages read from the message pipe. The 30 // Sets the receiver to handle messages read from the message pipe. The
30 // Connector will only read messages from the pipe if an incoming receiver 31 // Connector will only read messages from the pipe if an incoming receiver
31 // has been set. 32 // has been set.
32 void SetIncomingReceiver(MessageReceiver* receiver); 33 void SetIncomingReceiver(MessageReceiver* receiver);
33 34
34 // Returns true if an error was encountered while reading from or writing to 35 // Returns true if an error was encountered while reading from or writing to
35 // the message pipe. 36 // the message pipe.
36 bool encountered_error() const { return error_; } 37 bool encountered_error() const { return error_; }
37 38
38 // MessageReceiver implementation: 39 // MessageReceiver implementation:
39 virtual bool Accept(Message* message) MOJO_OVERRIDE; 40 virtual bool Accept(Message* message) MOJO_OVERRIDE;
40 41
41 private: 42 private:
42 class Callback : public BindingsSupport::AsyncWaitCallback { 43 class Callback {
43 public: 44 public:
44 Callback(); 45 Callback();
45 virtual ~Callback(); 46 ~Callback();
46 47
47 void SetOwnerToNotify(Connector* owner); 48 void SetOwnerToNotify(Connector* owner);
48 void SetAsyncWaitID(BindingsSupport::AsyncWaitID async_wait_id); 49 void SetAsyncWaitID(MojoAsyncWaitID async_wait_id);
49 50
50 virtual void OnHandleReady(MojoResult result) MOJO_OVERRIDE; 51 static void OnHandleReady(void* closure, MojoResult result);
51 52
52 private: 53 private:
53 Connector* owner_; 54 Connector* owner_;
54 BindingsSupport::AsyncWaitID async_wait_id_; 55 MojoAsyncWaitID async_wait_id_;
55 }; 56 };
56 friend class Callback; 57 friend class Callback;
57 58
58 void OnHandleReady(Callback* callback, MojoResult result); 59 void OnHandleReady(Callback* callback, MojoResult result);
59 void WaitToReadMore(); 60 void WaitToReadMore();
60 void WaitToWriteMore(); 61 void WaitToWriteMore();
62 void CallAsyncWait(MojoWaitFlags flags, Callback* callback);
63 void CallCancelWait(MojoAsyncWaitID async_wait_id);
61 void ReadMore(); 64 void ReadMore();
62 void WriteMore(); 65 void WriteMore();
63 void WriteOne(Message* message, bool* wait_to_write); 66 void WriteOne(Message* message, bool* wait_to_write);
64 67
68 MojoAsyncWaiter* waiter_;
69
65 ScopedMessagePipeHandle message_pipe_; 70 ScopedMessagePipeHandle message_pipe_;
66 MessageReceiver* incoming_receiver_; 71 MessageReceiver* incoming_receiver_;
67 MessageQueue write_queue_; 72 MessageQueue write_queue_;
68 73
69 Callback read_callback_; 74 Callback read_callback_;
70 Callback write_callback_; 75 Callback write_callback_;
71 76
72 bool error_; 77 bool error_;
73 78
74 MOJO_DISALLOW_COPY_AND_ASSIGN(Connector); 79 MOJO_DISALLOW_COPY_AND_ASSIGN(Connector);
75 }; 80 };
76 81
77 } // namespace internal 82 } // namespace internal
78 } // namespace mojo 83 } // namespace mojo
79 84
80 #endif // MOJO_PUBLIC_BINDINGS_LIB_CONNECTOR_H_ 85 #endif // MOJO_PUBLIC_BINDINGS_LIB_CONNECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698