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

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: 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
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 const void* main_buffer() const {
yzshen1 2014/02/19 23:15:59 Please consider adding a comment about what is a m
viettrungluu 2014/02/19 23:23:36 Done.
57 return static_cast<const void*>(this);
58 }
59
60 size_t main_buffer_size() const {
61 return RoundUpMessageAlignment(sizeof(*this) + header()->data_size);
62 }
63
54 // Gets the size of the data (in number of bytes). This is the full size of 64 // 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 65 // the data that follows the header, and may include data other than the
56 // message data. (See also |num_bytes()|.) 66 // message data. (See also |num_bytes()|.)
57 uint32_t data_size() const { 67 uint32_t data_size() const {
58 return header()->data_size; 68 return header()->data_size;
59 } 69 }
60 70
61 // Gets the data (of size |data_size()| bytes). 71 // Gets the data (of size |data_size()| bytes).
62 const void* data() const { 72 const void* data() const {
63 return reinterpret_cast<const char*>(this) + sizeof(*this); 73 return reinterpret_cast<const char*>(this) + sizeof(*this);
64 } 74 }
65 75
66 // Gets the size of the message data. 76 // Gets the size of the message data.
67 uint32_t num_bytes() const { 77 uint32_t num_bytes() const {
68 return header()->num_bytes; 78 return header()->num_bytes;
69 } 79 }
70 80
71 // Gets the message data (of size |num_bytes()| bytes). 81 // Gets the message data (of size |num_bytes()| bytes).
72 const void* bytes() const { 82 const void* bytes() const {
73 return reinterpret_cast<const char*>(this) + sizeof(*this); 83 return reinterpret_cast<const char*>(this) + sizeof(*this);
74 } 84 }
75 85
76 uint32_t num_handles() const { 86 uint32_t num_handles() const {
77 return header()->num_handles; 87 return header()->num_handles;
78 } 88 }
79 89
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; } 90 Type type() const { return header()->type; }
85 Subtype subtype() const { return header()->subtype; } 91 Subtype subtype() const { return header()->subtype; }
86 EndpointId source_id() const { return header()->source_id; } 92 EndpointId source_id() const { return header()->source_id; }
87 EndpointId destination_id() const { return header()->destination_id; } 93 EndpointId destination_id() const { return header()->destination_id; }
88 94
89 void set_source_id(EndpointId source_id) { header()->source_id = source_id; } 95 void set_source_id(EndpointId source_id) { header()->source_id = source_id; }
90 void set_destination_id(EndpointId destination_id) { 96 void set_destination_id(EndpointId destination_id) {
91 header()->destination_id = destination_id; 97 header()->destination_id = destination_id;
92 } 98 }
93 99
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 150
145 // The size of |MessageInTransit| must be appropriate to maintain alignment of 151 // The size of |MessageInTransit| must be appropriate to maintain alignment of
146 // the following data. 152 // the following data.
147 COMPILE_ASSERT(sizeof(MessageInTransit) % MessageInTransit::kMessageAlignment == 153 COMPILE_ASSERT(sizeof(MessageInTransit) % MessageInTransit::kMessageAlignment ==
148 0, MessageInTransit_has_wrong_size); 154 0, MessageInTransit_has_wrong_size);
149 155
150 } // namespace system 156 } // namespace system
151 } // namespace mojo 157 } // namespace mojo
152 158
153 #endif // MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ 159 #endif // MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698