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 #include "mojo/edk/system/ports_message.h" |
| 6 |
| 7 #include "mojo/edk/system/node_channel.h" |
| 8 |
| 9 namespace mojo { |
| 10 namespace edk { |
| 11 |
| 12 // static |
| 13 scoped_ptr<PortsMessage> PortsMessage::NewUserMessage(size_t num_payload_bytes, |
| 14 size_t num_ports, |
| 15 size_t num_handles) { |
| 16 return make_scoped_ptr( |
| 17 new PortsMessage(num_payload_bytes, num_ports, num_handles)); |
| 18 } |
| 19 |
| 20 PortsMessage::~PortsMessage() {} |
| 21 |
| 22 PortsMessage::PortsMessage(size_t num_payload_bytes, |
| 23 size_t num_ports, |
| 24 size_t num_handles) |
| 25 : ports::Message(num_payload_bytes, num_ports) { |
| 26 size_t size = num_header_bytes_ + num_ports_bytes_ + num_payload_bytes; |
| 27 void* ptr; |
| 28 channel_message_ = NodeChannel::CreatePortsMessage(size, &ptr, num_handles); |
| 29 InitializeUserMessageHeader(ptr); |
| 30 } |
| 31 |
| 32 PortsMessage::PortsMessage(size_t num_header_bytes, |
| 33 size_t num_payload_bytes, |
| 34 size_t num_ports_bytes, |
| 35 Channel::MessagePtr channel_message) |
| 36 : ports::Message(num_header_bytes, |
| 37 num_payload_bytes, |
| 38 num_ports_bytes) { |
| 39 if (channel_message) { |
| 40 channel_message_ = std::move(channel_message); |
| 41 void* data; |
| 42 size_t num_data_bytes; |
| 43 NodeChannel::GetPortsMessageData(channel_message_.get(), &data, |
| 44 &num_data_bytes); |
| 45 start_ = static_cast<char*>(data); |
| 46 } else { |
| 47 // TODO: Clean this up. In practice this branch of the constructor should |
| 48 // only be reached from Node-internal calls to AllocMessage, which never |
| 49 // carry ports or non-header bytes. |
| 50 CHECK_EQ(num_payload_bytes, 0u); |
| 51 CHECK_EQ(num_ports_bytes, 0u); |
| 52 void* ptr; |
| 53 channel_message_ = |
| 54 NodeChannel::CreatePortsMessage(num_header_bytes, &ptr, 0); |
| 55 start_ = static_cast<char*>(ptr); |
| 56 } |
| 57 } |
| 58 |
| 59 } // namespace edk |
| 60 } // namespace mojo |
OLD | NEW |