OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 5 #ifndef MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ |
6 #define MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 6 #define MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 Subtype subtype, | 46 Subtype subtype, |
47 const void* bytes, | 47 const void* bytes, |
48 uint32_t num_bytes, | 48 uint32_t num_bytes, |
49 uint32_t num_handles); | 49 uint32_t num_handles); |
50 | 50 |
51 MessageInTransit* Clone() const; | 51 MessageInTransit* Clone() const; |
52 | 52 |
53 // Destroys a |MessageInTransit| created using |Create()| or |Clone()|. | 53 // Destroys a |MessageInTransit| created using |Create()| or |Clone()|. |
54 void Destroy(); | 54 void Destroy(); |
55 | 55 |
| 56 // Gets the size of the next message from |buffer|, which has |buffer_size| |
| 57 // bytes currently available, returning true and setting |*next_message_size| |
| 58 // on success. |buffer| should be aligned on a |kMessageAlignment| boundary |
| 59 // (and on success, |*next_message_size| will be a multiple of |
| 60 // |kMessageAlignment|). |
| 61 // TODO(vtl): In |RawChannelPosix|, the alignment requirements are currently |
| 62 // satisified on a faith-based basis. |
| 63 static bool GetNextMessageSize(const void* buffer, |
| 64 size_t buffer_size, |
| 65 size_t* next_message_size); |
| 66 |
| 67 // Creates a read-only |MessageInTransit| from |buffer|, which must have |
| 68 // enough data (as indicated by |GetNextMessageSize()|). |buffer| has the same |
| 69 // alignment requirements as in |GetNextMessageSize()|. |
| 70 // |
| 71 // The returned message should not be destroyed using |Destroy()|, and the |
| 72 // underlying buffer must remain alive and unmodified as long as the returned |
| 73 // message is in use. |
| 74 // TODO(vtl): Change these odd semantics (once I make |MessageInTransit|s have |
| 75 // pointers to the buffers, instead of being POD). |
| 76 static const MessageInTransit* CreateReadOnlyFromBuffer(const void* buffer); |
| 77 |
56 // Gets the "main" buffer for a |MessageInTransit|. A |MessageInTransit| can | 78 // Gets the "main" buffer for a |MessageInTransit|. A |MessageInTransit| can |
57 // be serialized by writing the main buffer. The returned pointer will be | 79 // be serialized by writing the main buffer. The returned pointer will be |
58 // aligned to a multiple of |kMessageAlignment| bytes, and the size of the | 80 // aligned to a multiple of |kMessageAlignment| bytes, and the size of the |
59 // buffer (see below) will also be a multiple of |kMessageAlignment|. | 81 // buffer (see below) will also be a multiple of |kMessageAlignment|. |
60 // TODO(vtl): Add a "secondary" buffer, so that this makes more sense. | 82 // TODO(vtl): Add a "secondary" buffer, so that this makes more sense. |
61 const void* main_buffer() const { | 83 const void* main_buffer() const { |
62 return static_cast<const void*>(this); | 84 return static_cast<const void*>(this); |
63 } | 85 } |
64 | 86 |
65 // Gets the size of the main buffer (in number of bytes). | 87 // Gets the size of the main buffer (in number of bytes). |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 178 |
157 // The size of |MessageInTransit| must be appropriate to maintain alignment of | 179 // The size of |MessageInTransit| must be appropriate to maintain alignment of |
158 // the following data. | 180 // the following data. |
159 COMPILE_ASSERT(sizeof(MessageInTransit) % MessageInTransit::kMessageAlignment == | 181 COMPILE_ASSERT(sizeof(MessageInTransit) % MessageInTransit::kMessageAlignment == |
160 0, MessageInTransit_has_wrong_size); | 182 0, MessageInTransit_has_wrong_size); |
161 | 183 |
162 } // namespace system | 184 } // namespace system |
163 } // namespace mojo | 185 } // namespace mojo |
164 | 186 |
165 #endif // MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ | 187 #endif // MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ |
OLD | NEW |