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_MESSAGE_H__ 6 #define MOJO_EDK_SYSTEM_PORTS_MESSAGE_H__ 7 8 #include <memory> 9 #include <utility> 10 11 #include "mojo/edk/embedder/platform_handle_vector.h" 12 #include "mojo/edk/system/channel.h" 13 #include "mojo/edk/system/ports/message.h" 14 #include "mojo/edk/system/ports/name.h" 15 16 namespace mojo { 17 namespace edk { 18 19 class NodeController; 20 21 class PortsMessage : public ports::Message { 22 public: 23 static std::unique_ptr<PortsMessage> NewUserMessage(size_t num_payload_bytes, 24 size_t num_ports, 25 size_t num_handles); 26 27 ~PortsMessage() override; 28 num_handles()29 size_t num_handles() const { return channel_message_->num_handles(); } has_handles()30 bool has_handles() const { return channel_message_->has_handles(); } 31 SetHandles(ScopedPlatformHandleVectorPtr handles)32 void SetHandles(ScopedPlatformHandleVectorPtr handles) { 33 channel_message_->SetHandles(std::move(handles)); 34 } 35 TakeHandles()36 ScopedPlatformHandleVectorPtr TakeHandles() { 37 return channel_message_->TakeHandles(); 38 } 39 TakeChannelMessage()40 Channel::MessagePtr TakeChannelMessage() { 41 return std::move(channel_message_); 42 } 43 set_source_node(const ports::NodeName & name)44 void set_source_node(const ports::NodeName& name) { source_node_ = name; } source_node()45 const ports::NodeName& source_node() const { return source_node_; } 46 47 private: 48 friend class NodeController; 49 50 // Construct a new user PortsMessage backed by a new Channel::Message. 51 PortsMessage(size_t num_payload_bytes, size_t num_ports, size_t num_handles); 52 53 // Construct a new PortsMessage backed by a Channel::Message. If 54 // |channel_message| is null, a new one is allocated internally. 55 PortsMessage(size_t num_header_bytes, 56 size_t num_payload_bytes, 57 size_t num_ports_bytes, 58 Channel::MessagePtr channel_message); 59 60 Channel::MessagePtr channel_message_; 61 62 // The node name from which this message was received, if known. 63 ports::NodeName source_node_ = ports::kInvalidNodeName; 64 }; 65 66 } // namespace edk 67 } // namespace mojo 68 69 #endif // MOJO_EDK_SYSTEM_PORTS_MESSAGE_H__ 70