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_EDK_SYSTEM_PORTS_NODE_DELEGATE_H_ 6 #define MOJO_EDK_SYSTEM_PORTS_NODE_DELEGATE_H_ 7 8 #include <stddef.h> 9 10 #include "mojo/edk/system/ports/message.h" 11 #include "mojo/edk/system/ports/name.h" 12 #include "mojo/edk/system/ports/port_ref.h" 13 14 namespace mojo { 15 namespace edk { 16 namespace ports { 17 18 class NodeDelegate { 19 public: ~NodeDelegate()20 virtual ~NodeDelegate() {} 21 22 // Port names should be difficult to guess. 23 virtual void GenerateRandomPortName(PortName* port_name) = 0; 24 25 // Allocate a message, including a header that can be used by the Node 26 // implementation. |num_header_bytes| will be aligned. The newly allocated 27 // memory need not be zero-filled. 28 virtual void AllocMessage(size_t num_header_bytes, 29 ScopedMessage* message) = 0; 30 31 // Forward a message asynchronously to the specified node. This method MUST 32 // NOT synchronously call any methods on Node. 33 virtual void ForwardMessage(const NodeName& node, ScopedMessage message) = 0; 34 35 // Broadcast a message to all nodes. 36 virtual void BroadcastMessage(ScopedMessage message) = 0; 37 38 // Indicates that the port's status has changed recently. Use Node::GetStatus 39 // to query the latest status of the port. Note, this event could be spurious 40 // if another thread is simultaneously modifying the status of the port. 41 virtual void PortStatusChanged(const PortRef& port_ref) = 0; 42 }; 43 44 } // namespace ports 45 } // namespace edk 46 } // namespace mojo 47 48 #endif // MOJO_EDK_SYSTEM_PORTS_NODE_DELEGATE_H_ 49