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

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

Issue 1174073002: C++ bindings: support using a callback as connection error handler. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 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
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_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/callback.h"
9 #include "mojo/public/cpp/bindings/lib/message_queue.h" 10 #include "mojo/public/cpp/bindings/lib/message_queue.h"
10 #include "mojo/public/cpp/bindings/message.h" 11 #include "mojo/public/cpp/bindings/message.h"
11 #include "mojo/public/cpp/environment/environment.h" 12 #include "mojo/public/cpp/environment/environment.h"
12 #include "mojo/public/cpp/system/core.h" 13 #include "mojo/public/cpp/system/core.h"
13 14
14 namespace mojo { 15 namespace mojo {
15 class ErrorHandler; 16 class ErrorHandler;
16 17
17 namespace internal { 18 namespace internal {
18 19
(...skipping 21 matching lines...) Expand all
40 41
41 // Errors from incoming receivers will force the connector into an error 42 // Errors from incoming receivers will force the connector into an error
42 // state, where no more messages will be processed. This method is used 43 // state, where no more messages will be processed. This method is used
43 // during testing to prevent that from happening. 44 // during testing to prevent that from happening.
44 void set_enforce_errors_from_incoming_receiver(bool enforce) { 45 void set_enforce_errors_from_incoming_receiver(bool enforce) {
45 enforce_errors_from_incoming_receiver_ = enforce; 46 enforce_errors_from_incoming_receiver_ = enforce;
46 } 47 }
47 48
48 // Sets the error handler to receive notifications when an error is 49 // Sets the error handler to receive notifications when an error is
49 // encountered while reading from the pipe or waiting to read from the pipe. 50 // encountered while reading from the pipe or waiting to read from the pipe.
50 void set_error_handler(ErrorHandler* error_handler) { 51 void set_connection_error_handler(const Closure& error_handler) {
51 error_handler_ = error_handler; 52 connection_error_handler_ = error_handler;
52 } 53 }
53 54
54 // Returns true if an error was encountered while reading from the pipe or 55 // Returns true if an error was encountered while reading from the pipe or
55 // waiting to read from the pipe. 56 // waiting to read from the pipe.
56 bool encountered_error() const { return error_; } 57 bool encountered_error() const { return error_; }
57 58
58 // Closes the pipe, triggering the error state. Connector is put into a 59 // Closes the pipe, triggering the error state. Connector is put into a
59 // quiescent state. 60 // quiescent state.
60 void CloseMessagePipe(); 61 void CloseMessagePipe();
61 62
(...skipping 24 matching lines...) Expand all
86 MOJO_WARN_UNUSED_RESULT bool ReadSingleMessage(MojoResult* read_result); 87 MOJO_WARN_UNUSED_RESULT bool ReadSingleMessage(MojoResult* read_result);
87 88
88 // |this| can be destroyed during message dispatch. 89 // |this| can be destroyed during message dispatch.
89 void ReadAllAvailableMessages(); 90 void ReadAllAvailableMessages();
90 91
91 void NotifyError(); 92 void NotifyError();
92 93
93 // Cancels any calls made to |waiter_|. 94 // Cancels any calls made to |waiter_|.
94 void CancelWait(); 95 void CancelWait();
95 96
96 ErrorHandler* error_handler_; 97 Closure connection_error_handler_;
97 const MojoAsyncWaiter* waiter_; 98 const MojoAsyncWaiter* waiter_;
98 99
99 ScopedMessagePipeHandle message_pipe_; 100 ScopedMessagePipeHandle message_pipe_;
100 MessageReceiver* incoming_receiver_; 101 MessageReceiver* incoming_receiver_;
101 102
102 MojoAsyncWaitID async_wait_id_; 103 MojoAsyncWaitID async_wait_id_;
103 bool error_; 104 bool error_;
104 bool drop_writes_; 105 bool drop_writes_;
105 bool enforce_errors_from_incoming_receiver_; 106 bool enforce_errors_from_incoming_receiver_;
106 107
107 // If non-null, this will be set to true when the Connector is destroyed. We 108 // If non-null, this will be set to true when the Connector is destroyed. We
108 // use this flag to allow for the Connector to be destroyed as a side-effect 109 // use this flag to allow for the Connector to be destroyed as a side-effect
109 // of dispatching an incoming message. 110 // of dispatching an incoming message.
110 bool* destroyed_flag_; 111 bool* destroyed_flag_;
111 112
112 MOJO_DISALLOW_COPY_AND_ASSIGN(Connector); 113 MOJO_DISALLOW_COPY_AND_ASSIGN(Connector);
113 }; 114 };
114 115
115 } // namespace internal 116 } // namespace internal
116 } // namespace mojo 117 } // namespace mojo
117 118
118 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ 119 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698