| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_PUBLIC_CPP_BINDINGS_MESSAGE_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_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 void Initialize(size_t capacity, bool zero_initialized); | 37 void Initialize(size_t capacity, bool zero_initialized); |
| 38 | 38 |
| 39 // Initializes a Message from an existing Mojo MessageHandle. | 39 // Initializes a Message from an existing Mojo MessageHandle. |
| 40 void InitializeFromMojoMessage(ScopedMessageHandle message, | 40 void InitializeFromMojoMessage(ScopedMessageHandle message, |
| 41 uint32_t num_bytes, | 41 uint32_t num_bytes, |
| 42 std::vector<Handle>* handles); | 42 std::vector<Handle>* handles); |
| 43 | 43 |
| 44 // Transfers data and handles to |destination|. | 44 // Transfers data and handles to |destination|. |
| 45 void MoveTo(Message* destination); | 45 void MoveTo(Message* destination); |
| 46 | 46 |
| 47 uint32_t data_num_bytes() const { return buffer_->data_num_bytes(); } | 47 uint32_t data_num_bytes() const { |
| 48 return static_cast<uint32_t>(buffer_->size()); |
| 49 } |
| 48 | 50 |
| 49 // Access the raw bytes of the message. | 51 // Access the raw bytes of the message. |
| 50 const uint8_t* data() const { | 52 const uint8_t* data() const { |
| 51 return static_cast<const uint8_t*>(buffer_->data()); | 53 return static_cast<const uint8_t*>(buffer_->data()); |
| 52 } | 54 } |
| 53 | 55 |
| 54 uint8_t* mutable_data() { return static_cast<uint8_t*>(buffer_->data()); } | 56 uint8_t* mutable_data() { return static_cast<uint8_t*>(buffer_->data()); } |
| 55 | 57 |
| 56 // Access the header. | 58 // Access the header. |
| 57 const internal::MessageHeader* header() const { | 59 const internal::MessageHeader* header() const { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 79 void set_request_id(uint64_t request_id) { | 81 void set_request_id(uint64_t request_id) { |
| 80 DCHECK(has_request_id()); | 82 DCHECK(has_request_id()); |
| 81 static_cast<internal::MessageHeaderWithRequestID*>(header()) | 83 static_cast<internal::MessageHeaderWithRequestID*>(header()) |
| 82 ->request_id = request_id; | 84 ->request_id = request_id; |
| 83 } | 85 } |
| 84 | 86 |
| 85 // Access the payload. | 87 // Access the payload. |
| 86 const uint8_t* payload() const { return data() + header()->num_bytes; } | 88 const uint8_t* payload() const { return data() + header()->num_bytes; } |
| 87 uint8_t* mutable_payload() { return const_cast<uint8_t*>(payload()); } | 89 uint8_t* mutable_payload() { return const_cast<uint8_t*>(payload()); } |
| 88 uint32_t payload_num_bytes() const { | 90 uint32_t payload_num_bytes() const { |
| 89 DCHECK(buffer_->data_num_bytes() >= header()->num_bytes); | 91 DCHECK(data_num_bytes() >= header()->num_bytes); |
| 90 size_t num_bytes = buffer_->data_num_bytes() - header()->num_bytes; | 92 size_t num_bytes = data_num_bytes() - header()->num_bytes; |
| 91 DCHECK(num_bytes <= std::numeric_limits<uint32_t>::max()); | 93 DCHECK(num_bytes <= std::numeric_limits<uint32_t>::max()); |
| 92 return static_cast<uint32_t>(num_bytes); | 94 return static_cast<uint32_t>(num_bytes); |
| 93 } | 95 } |
| 94 | 96 |
| 95 // Access the handles. | 97 // Access the handles. |
| 96 const std::vector<Handle>* handles() const { return &handles_; } | 98 const std::vector<Handle>* handles() const { return &handles_; } |
| 97 std::vector<Handle>* mutable_handles() { return &handles_; } | 99 std::vector<Handle>* mutable_handles() { return &handles_; } |
| 98 | 100 |
| 99 // Access the underlying Buffer interface. | 101 // Access the underlying Buffer interface. |
| 100 internal::Buffer* buffer() { return buffer_.get(); } | 102 internal::Buffer* buffer() { return buffer_.get(); } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // the caller should wait on the handle to become readable. Returns | 193 // the caller should wait on the handle to become readable. Returns |
| 192 // MOJO_RESULT_OK if the message was read successfully and should be | 194 // MOJO_RESULT_OK if the message was read successfully and should be |
| 193 // dispatched, otherwise returns an error code if something went wrong. | 195 // dispatched, otherwise returns an error code if something went wrong. |
| 194 // | 196 // |
| 195 // NOTE: The message hasn't been validated and may be malformed! | 197 // NOTE: The message hasn't been validated and may be malformed! |
| 196 MojoResult ReadMessage(MessagePipeHandle handle, Message* message); | 198 MojoResult ReadMessage(MessagePipeHandle handle, Message* message); |
| 197 | 199 |
| 198 } // namespace mojo | 200 } // namespace mojo |
| 199 | 201 |
| 200 #endif // MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_ | 202 #endif // MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_H_ |
| OLD | NEW |