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

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

Issue 163023004: Mojo: Move the header bits of MessageInTransit into a separate struct. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new version 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 | « no previous file | 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Destroys a |MessageInTransit| created using |Create()|.
52 void Destroy(); 52 void Destroy();
53 53
54 // Gets the size of the data (in number of bytes). This is the full size of 54 // 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 55 // the data that follows the header, and may include data other than the
56 // message data. (See also |num_bytes()|.) 56 // message data. (See also |num_bytes()|.)
57 uint32_t data_size() const { 57 uint32_t data_size() const {
58 return data_size_; 58 return header()->data_size;
59 } 59 }
60 60
61 // Gets the data (of size |data_size()| bytes). 61 // Gets the data (of size |data_size()| bytes).
62 const void* data() const { 62 const void* data() const {
63 return reinterpret_cast<const char*>(this) + sizeof(*this); 63 return reinterpret_cast<const char*>(this) + sizeof(*this);
64 } 64 }
65 65
66 // Gets the size of the message data. 66 // Gets the size of the message data.
67 uint32_t num_bytes() const { 67 uint32_t num_bytes() const {
68 return num_bytes_; 68 return header()->num_bytes;
69 } 69 }
70 70
71 // Gets the message data (of size |num_bytes()| bytes). 71 // Gets the message data (of size |num_bytes()| bytes).
72 const void* bytes() const { 72 const void* bytes() const {
73 return reinterpret_cast<const char*>(this) + sizeof(*this); 73 return reinterpret_cast<const char*>(this) + sizeof(*this);
74 } 74 }
75 75
76 uint32_t num_handles() const { 76 uint32_t num_handles() const {
77 return num_handles_; 77 return header()->num_handles;
78 } 78 }
79 79
80 size_t size_with_header_and_padding() const { 80 size_t size_with_header_and_padding() const {
81 return RoundUpMessageAlignment(sizeof(*this) + data_size_); 81 return RoundUpMessageAlignment(sizeof(*this) + header()->data_size);
82 } 82 }
83 83
84 Type type() const { return type_; } 84 Type type() const { return header()->type; }
85 Subtype subtype() const { return subtype_; } 85 Subtype subtype() const { return header()->subtype; }
86 EndpointId source_id() const { return source_id_; } 86 EndpointId source_id() const { return header()->source_id; }
87 EndpointId destination_id() const { return destination_id_; } 87 EndpointId destination_id() const { return header()->destination_id; }
88 88
89 void set_source_id(EndpointId source_id) { source_id_ = source_id; } 89 void set_source_id(EndpointId source_id) { header()->source_id = source_id; }
90 void set_destination_id(EndpointId destination_id) { 90 void set_destination_id(EndpointId destination_id) {
91 destination_id_ = destination_id; 91 header()->destination_id = destination_id;
92 } 92 }
93 93
94 // TODO(vtl): Add whatever's necessary to transport handles. 94 // TODO(vtl): Add whatever's necessary to transport handles.
95 95
96 // Rounds |n| up to a multiple of |kMessageAlignment|. 96 // Rounds |n| up to a multiple of |kMessageAlignment|.
97 static inline size_t RoundUpMessageAlignment(size_t n) { 97 static inline size_t RoundUpMessageAlignment(size_t n) {
98 return (n + kMessageAlignment - 1) & ~(kMessageAlignment - 1); 98 return (n + kMessageAlignment - 1) & ~(kMessageAlignment - 1);
99 } 99 }
100 100
101 private: 101 private:
102 // "Header" for the data. Must be a multiple of |kMessageAlignment| bytes in
103 // size.
104 struct Header {
105 Header(uint32_t data_size, Type type, Subtype subtype, EndpointId source_id,
yzshen1 2014/02/19 18:35:06 I think we need to do each parameter on a separate
106 EndpointId destination_id, uint32_t num_bytes, uint32_t num_handles)
107 : data_size(data_size), type(type), subtype(subtype),
108 source_id(source_id), destination_id(destination_id),
109 num_bytes(num_bytes), num_handles(num_handles), reserved0(0),
110 reserved1(0) {}
111
112 // Total size of data following the "header".
113 uint32_t data_size;
114 Type type;
115 Subtype subtype;
116 EndpointId source_id;
117 EndpointId destination_id;
118 // Size of actual message data.
119 uint32_t num_bytes;
120 // Number of handles "attached".
121 uint32_t num_handles;
122 // To be used soon.
123 uint32_t reserved0;
124 uint32_t reserved1;
125 };
126
102 MessageInTransit(uint32_t data_size, 127 MessageInTransit(uint32_t data_size,
103 Type type, 128 Type type,
104 Subtype subtype, 129 Subtype subtype,
105 uint32_t num_bytes, 130 uint32_t num_bytes,
106 uint32_t num_handles); 131 uint32_t num_handles);
107 132
108 // "Header" for the data. Must be a multiple of |kMessageAlignment| bytes in 133 const Header* header() const { return &header_; }
109 // size. 134 Header* header() { return &header_; }
110 // Total size of data following the "header". 135
111 uint32_t data_size_; 136 Header header_;
112 Type type_;
113 Subtype subtype_;
114 EndpointId source_id_;
115 EndpointId destination_id_;
116 // Size of actual message data.
117 uint32_t num_bytes_;
118 // Number of handles "attached".
119 uint32_t num_handles_;
120 // To be used soon.
121 uint32_t reserved0_;
122 uint32_t reserved1_;
123 137
124 // Intentionally unimplemented (and private): Use |Destroy()| instead (which 138 // Intentionally unimplemented (and private): Use |Destroy()| instead (which
125 // simply frees the memory). 139 // simply frees the memory).
126 ~MessageInTransit(); 140 ~MessageInTransit();
127 141
128 DISALLOW_COPY_AND_ASSIGN(MessageInTransit); 142 DISALLOW_COPY_AND_ASSIGN(MessageInTransit);
129 }; 143 };
130 144
131 // The size of |MessageInTransit| must be appropriate to maintain alignment of 145 // The size of |MessageInTransit| must be appropriate to maintain alignment of
132 // the following data. 146 // the following data.
133 COMPILE_ASSERT(sizeof(MessageInTransit) % MessageInTransit::kMessageAlignment == 147 COMPILE_ASSERT(sizeof(MessageInTransit) % MessageInTransit::kMessageAlignment ==
134 0, MessageInTransit_has_wrong_size); 148 0, MessageInTransit_has_wrong_size);
135 149
136 } // namespace system 150 } // namespace system
137 } // namespace mojo 151 } // namespace mojo
138 152
139 #endif // MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_ 153 #endif // MOJO_SYSTEM_MESSAGE_IN_TRANSIT_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/system/message_in_transit.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698