Hidehiko Abe | b268b43 | 2018-04-24 01:37:19 +0900 | [diff] [blame] | 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_PUBLIC_CPP_BINDINGS_MESSAGE_LIB_MESSAGE_BUFFER_H_ |
| 6 | #define MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_LIB_MESSAGE_BUFFER_H_ |
| 7 | |
| 8 | #include <stdint.h> |
| 9 | |
| 10 | #include <utility> |
| 11 | |
| 12 | #include "base/macros.h" |
| 13 | #include "mojo/public/cpp/bindings/lib/buffer.h" |
| 14 | #include "mojo/public/cpp/system/message.h" |
| 15 | |
| 16 | namespace mojo { |
| 17 | namespace internal { |
| 18 | |
| 19 | // A fixed-size Buffer using a Mojo message object for storage. |
| 20 | class MessageBuffer : public Buffer { |
| 21 | public: |
| 22 | // Initializes this buffer to carry a fixed byte capacity and no handles. |
| 23 | MessageBuffer(size_t capacity, bool zero_initialized); |
| 24 | |
| 25 | // Initializes this buffer from an existing Mojo MessageHandle. |
| 26 | MessageBuffer(ScopedMessageHandle message, uint32_t num_bytes); |
| 27 | |
| 28 | ~MessageBuffer(); |
| 29 | |
| 30 | ScopedMessageHandle TakeMessage() { return std::move(message_); } |
| 31 | |
| 32 | void NotifyBadMessage(const std::string& error); |
| 33 | |
| 34 | private: |
| 35 | ScopedMessageHandle message_; |
| 36 | |
| 37 | DISALLOW_COPY_AND_ASSIGN(MessageBuffer); |
| 38 | }; |
| 39 | |
| 40 | } // namespace internal |
| 41 | } // namespace mojo |
| 42 | |
| 43 | #endif // MOJO_PUBLIC_CPP_BINDINGS_MESSAGE_LIB_MESSAGE_BUFFER_H_ |