| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_EDK_SYSTEM_PORTS_NODE_H_ | 5 #ifndef MOJO_EDK_SYSTEM_PORTS_NODE_H_ |
| 6 #define MOJO_EDK_SYSTEM_PORTS_NODE_H_ | 6 #define MOJO_EDK_SYSTEM_PORTS_NODE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 ERROR_PORT_CANNOT_SEND_PEER = -15, | 37 ERROR_PORT_CANNOT_SEND_PEER = -15, |
| 38 ERROR_NOT_IMPLEMENTED = -100, | 38 ERROR_NOT_IMPLEMENTED = -100, |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 struct PortStatus { | 41 struct PortStatus { |
| 42 bool has_messages; | 42 bool has_messages; |
| 43 bool receiving_messages; | 43 bool receiving_messages; |
| 44 bool peer_closed; | 44 bool peer_closed; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 class MessageFilter; |
| 47 class NodeDelegate; | 48 class NodeDelegate; |
| 48 | 49 |
| 49 class Node { | 50 class Node { |
| 50 public: | 51 public: |
| 51 enum class ShutdownPolicy { | 52 enum class ShutdownPolicy { |
| 52 DONT_ALLOW_LOCAL_PORTS, | 53 DONT_ALLOW_LOCAL_PORTS, |
| 53 ALLOW_LOCAL_PORTS, | 54 ALLOW_LOCAL_PORTS, |
| 54 }; | 55 }; |
| 55 | 56 |
| 56 // Does not take ownership of the delegate. | 57 // Does not take ownership of the delegate. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 int ClosePort(const PortRef& port_ref); | 101 int ClosePort(const PortRef& port_ref); |
| 101 | 102 |
| 102 // Returns the current status of the port. | 103 // Returns the current status of the port. |
| 103 int GetStatus(const PortRef& port_ref, PortStatus* port_status); | 104 int GetStatus(const PortRef& port_ref, PortStatus* port_status); |
| 104 | 105 |
| 105 // Returns the next available message on the specified port or returns a null | 106 // Returns the next available message on the specified port or returns a null |
| 106 // message if there are none available. Returns ERROR_PORT_PEER_CLOSED to | 107 // message if there are none available. Returns ERROR_PORT_PEER_CLOSED to |
| 107 // indicate that this port's peer has closed. In such cases GetMessage may | 108 // indicate that this port's peer has closed. In such cases GetMessage may |
| 108 // be called until it yields a null message, indicating that no more messages | 109 // be called until it yields a null message, indicating that no more messages |
| 109 // may be read from the port. | 110 // may be read from the port. |
| 110 int GetMessage(const PortRef& port_ref, ScopedMessage* message); | 111 // |
| 111 | 112 // If |filter| is non-null, the next available message is returned only if it |
| 112 // Like GetMessage, but the caller may optionally supply a selector function | 113 // is matched by the filter. If the provided filter does not match the next |
| 113 // that decides whether or not to return the message. If |selector| is a | 114 // available message, GetMessage() behaves as if there is no message |
| 114 // nullptr, then GetMessageIf acts just like GetMessage. The |selector| may | 115 // available. Ownership of |filter| is not taken, and it must outlive the |
| 115 // not call any Node methods. | 116 // extent of this call. |
| 116 int GetMessageIf(const PortRef& port_ref, | 117 int GetMessage(const PortRef& port_ref, |
| 117 std::function<bool(const Message&)> selector, | 118 ScopedMessage* message, |
| 118 ScopedMessage* message); | 119 MessageFilter* filter); |
| 119 | 120 |
| 120 // Sends a message from the specified port to its peer. Note that the message | 121 // Sends a message from the specified port to its peer. Note that the message |
| 121 // notification may arrive synchronously (via PortStatusChanged() on the | 122 // notification may arrive synchronously (via PortStatusChanged() on the |
| 122 // delegate) if the peer is local to this Node. | 123 // delegate) if the peer is local to this Node. |
| 123 int SendMessage(const PortRef& port_ref, ScopedMessage message); | 124 int SendMessage(const PortRef& port_ref, ScopedMessage message); |
| 124 | 125 |
| 125 // Corresponding to NodeDelegate::ForwardMessage. | 126 // Corresponding to NodeDelegate::ForwardMessage. |
| 126 int AcceptMessage(ScopedMessage message); | 127 int AcceptMessage(ScopedMessage message); |
| 127 | 128 |
| 128 // Called to merge two ports with each other. If you have two independent | 129 // Called to merge two ports with each other. If you have two independent |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 std::unordered_map<PortName, scoped_refptr<Port>> ports_; | 221 std::unordered_map<PortName, scoped_refptr<Port>> ports_; |
| 221 | 222 |
| 222 DISALLOW_COPY_AND_ASSIGN(Node); | 223 DISALLOW_COPY_AND_ASSIGN(Node); |
| 223 }; | 224 }; |
| 224 | 225 |
| 225 } // namespace ports | 226 } // namespace ports |
| 226 } // namespace edk | 227 } // namespace edk |
| 227 } // namespace mojo | 228 } // namespace mojo |
| 228 | 229 |
| 229 #endif // MOJO_EDK_SYSTEM_PORTS_NODE_H_ | 230 #endif // MOJO_EDK_SYSTEM_PORTS_NODE_H_ |
| OLD | NEW |