Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: mojo/system/message_in_transit.h

Issue 172953003: Mojo: Make MessageInTransit more opaque. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/system/channel.cc ('k') | mojo/system/message_in_transit.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 30 matching lines...) Expand all
41 41
42 // Creates a |MessageInTransit| of the given |type| and |subtype|, with 42 // Creates a |MessageInTransit| of the given |type| and |subtype|, with
43 // message data given by |bytes|/|num_bytes|. 43 // message data given by |bytes|/|num_bytes|.
44 // TODO(vtl): Add ability to tack on handle information. 44 // TODO(vtl): Add ability to tack on handle information.
45 static MessageInTransit* Create(Type type, 45 static MessageInTransit* Create(Type type,
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 // Destroys a |MessageInTransit| created using |Create()|. 51 MessageInTransit* Clone() const;
52
53 // Destroys a |MessageInTransit| created using |Create()| or |Clone()|.
52 void Destroy(); 54 void Destroy();
53 55
56 // Gets the "main" buffer for a |MessageInTransit|. A |MessageInTransit| can
57 // 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
59 // buffer (see below) will also be a multiple of |kMessageAlignment|.
60 // TODO(vtl): Add a "secondary" buffer, so that this makes more sense.
61 const void* main_buffer() const {
62 return static_cast<const void*>(this);
63 }
64
65 // Gets the size of the main buffer (in number of bytes).
66 size_t main_buffer_size() const {
67 return RoundUpMessageAlignment(sizeof(*this) + header()->data_size);
68 }
69
54 // Gets the size of the data (in number of bytes). This is the full size of 70 // Gets the size of the data (in number of bytes). This is the full size of
55 // the data that follows the header, and may include data other than the 71 // the data that follows the header, and may include data other than the
56 // message data. (See also |num_bytes()|.) 72 // message data. (See also |num_bytes()|.)
57 uint32_t data_size() const { 73 uint32_t data_size() const {
58 return header()->data_size; 74 return header()->data_size;
59 } 75 }
60 76
61 // Gets the data (of size |data_size()| bytes). 77 // Gets the data (of size |data_size()| bytes).
62 const void* data() const { 78 const void* data() const {
63 return reinterpret_cast<const char*>(this) + sizeof(*this); 79 return reinterpret_cast<const char*>(this) + sizeof(*this);
64 } 80 }
65 81
66 // Gets the size of the message data. 82 // Gets the size of the message data.
67 uint32_t num_bytes() const { 83 uint32_t num_bytes() const {
68 return header()->num_bytes; 84 return header()->num_bytes;
69 } 85 }
70 86
71 // Gets the message data (of size |num_bytes()| bytes). 87 // Gets the message data (of size |num_bytes()| bytes).
72 const void* bytes() const { 88 const void* bytes() const {
73 return reinterpret_cast<const char*>(this) + sizeof(*this); 89 return reinterpret_cast<const char*>(this) + sizeof(*this);
74 } 90 }
75 91
76 uint32_t num_handles() const { 92 uint32_t num_handles() const {
77 return header()->num_handles; 93 return header()->num_handles;
78 } 94 }
79 95
80 size_t size_with_header_and_padding() const {
81 return RoundUpMessageAlignment(sizeof(*this) + header()->data_size);
82 }
83
84 Type type() const { return header()->type; } 96 Type type() const { return header()->type; }
85 Subtype subtype() const { return header()->subtype; } 97 Subtype subtype() const { return header()->subtype; }
86 EndpointId source_id() const { return header()->source_id; } 98 EndpointId source_id() const { return header()->source_id; }
87 EndpointId destination_id() const { return header()->destination_id; } 99 EndpointId destination_id() const { return header()->destination_id; }
88 100
89 void set_source_id(EndpointId source_id) { header()->source_id = source_id; } 101 void set_source_id(EndpointId source_id) { header()->source_id = source_id; }
90 void set_destination_id(EndpointId destination_id) { 102 void set_destination_id(EndpointId destination_id) {
91 header()->destination_id = destination_id; 103 header()->destination_id = destination_id;
92 } 104 }
93 105
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 156
145 // The size of |MessageInTransit| must be appropriate to maintain alignment of 157 // The size of |MessageInTransit| must be appropriate to maintain alignment of
146 // the following data. 158 // the following data.
147 COMPILE_ASSERT(sizeof(MessageInTransit) % MessageInTransit::kMessageAlignment == 159 COMPILE_ASSERT(sizeof(MessageInTransit) % MessageInTransit::kMessageAlignment ==
148 0, MessageInTransit_has_wrong_size); 160 0, MessageInTransit_has_wrong_size);
149 161
150 } // namespace system 162 } // namespace system
151 } // namespace mojo 163 } // namespace mojo
152 164
153 #endif // MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ 165 #endif // MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_
OLDNEW
« no previous file with comments | « mojo/system/channel.cc ('k') | mojo/system/message_in_transit.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698