| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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_PUBLIC_CPP_BINDINGS_LIB_SYNCHRONOUS_CONNECTOR_H_ | |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_SYNCHRONOUS_CONNECTOR_H_ | |
| 7 | |
| 8 #include "mojo/public/cpp/bindings/message.h" | |
| 9 #include "mojo/public/cpp/system/macros.h" | |
| 10 #include "mojo/public/cpp/system/message_pipe.h" | |
| 11 | |
| 12 namespace mojo { | |
| 13 namespace internal { | |
| 14 | |
| 15 // This class is responsible for performing synchronous read/write operations on | |
| 16 // a MessagePipe. Notably, this interface allows us to make synchronous | |
| 17 // request/response operations on messages: write a message (that expects a | |
| 18 // response message), wait on the message pipe, and read the response. | |
| 19 class SynchronousConnector { | |
| 20 public: | |
| 21 explicit SynchronousConnector(ScopedMessagePipeHandle handle); | |
| 22 ~SynchronousConnector(); | |
| 23 | |
| 24 // This will mutate the message by moving the handles out of it. |msg_to_send| | |
| 25 // must be non-null. Returns true on a successful write. | |
| 26 bool Write(Message* msg_to_send); | |
| 27 | |
| 28 // This method blocks indefinitely until a message is received. |received_msg| | |
| 29 // must be non-null and be empty. Returns true on a successful read. | |
| 30 // TODO(vardhan): Add a timeout mechanism. | |
| 31 bool BlockingRead(Message* received_msg); | |
| 32 | |
| 33 ScopedMessagePipeHandle PassHandle() { return std::move(handle_); } | |
| 34 | |
| 35 // Returns true if the underlying MessagePipe is valid. | |
| 36 bool is_valid() const { return handle_.is_valid(); } | |
| 37 | |
| 38 private: | |
| 39 ScopedMessagePipeHandle handle_; | |
| 40 | |
| 41 MOJO_DISALLOW_COPY_AND_ASSIGN(SynchronousConnector); | |
| 42 }; | |
| 43 | |
| 44 } // namespace internal | |
| 45 } // namespace mojo | |
| 46 | |
| 47 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_SYNCHRONOUS_CONNECTOR_H_ | |
| OLD | NEW |