Chromium Code Reviews| Index: mojo/system/message_in_transit.h |
| diff --git a/mojo/system/message_in_transit.h b/mojo/system/message_in_transit.h |
| index 77b658fa4f5cccf8722798cdeeab29de06289f6f..1a14b08955b4a4a23a68e227239187819f4a43aa 100644 |
| --- a/mojo/system/message_in_transit.h |
| +++ b/mojo/system/message_in_transit.h |
| @@ -18,8 +18,32 @@ namespace system { |
| // Note: This class is POD. |
| class MOJO_SYSTEM_EXPORT MessageInTransit { |
| public: |
| - // Creates a |MessageInTransit| with the data given by |bytes|/|num_bytes|. |
| - static MessageInTransit* Create(const void* bytes, uint32_t num_bytes); |
| + typedef uint16_t Type; |
| + // Messages that are forwarded to |MessagePipeEndpoint|s. |
| + static const Type TYPE_MESSAGE_PIPE_ENDPOINT = 0; |
|
darin (slow to review)
2013/11/06 18:26:00
nit: shouldn't these be formatted using kFooBar st
viettrungluu
2013/11/06 21:13:39
Fixed. (They were enum values before, until I deci
|
| + // Messages that are forwarded to |MessagePipe|s. |
| + static const Type TYPE_MESSAGE_PIPE = 1; |
| + // Messages that are consumed by the channel. |
| + static const Type TYPE_CHANNEL = 2; |
| + |
| + typedef uint16_t Subtype; |
| + // Subtypes for type |TYPE_MESSAGE_PIPE_ENDPOINT|: |
| + static const Subtype SUBTYPE_MESSAGE_PIPE_ENDPOINT_DATA = 0; |
| + // Subtypes for type |TYPE_MESSAGE_PIPE|: |
| + static const Subtype SUBTYPE_MESSAGE_PIPE_PEER_CLOSED = 0; |
| + |
| + typedef uint32_t EndpointId; |
| + // Never a valid endpoint ID. |
| + static const EndpointId kInvalidEndpointId = 0; |
| + |
| + // Messages (the header and data) must always be aligned to a multiple of this |
| + // quantity (which must be a power of 2). |
| + static const size_t kMessageAlignment = 8; |
| + |
| + // Creates a |MessageInTransit| of the given |type| and |subtype|, with the |
| + // data given by |bytes|/|num_bytes|. |
| + static MessageInTransit* Create(Type type, Subtype subtype, |
| + const void* bytes, uint32_t num_bytes); |
| // Destroys a |MessageInTransit| created using |Create()|. |
| inline void Destroy() { |
| @@ -41,11 +65,19 @@ class MOJO_SYSTEM_EXPORT MessageInTransit { |
| return RoundUpMessageAlignment(sizeof(*this) + size_); |
| } |
| - // TODO(vtl): Add whatever's necessary to transport handles. |
| + Type type() const { return type_; } |
| + Subtype subtype() const { return subtype_; } |
| + EndpointId source_id() const { return source_id_; } |
| + EndpointId destination_id() const { return destination_id_; } |
| - // Messages (the header and data) must always be aligned to a multiple of this |
| - // quantity (which must be a power of 2). |
| - static const size_t kMessageAlignment = 8; |
| + void set_type(Type type) { type_ = type; } |
|
darin (slow to review)
2013/11/06 18:26:00
note: set_type and set_subtype do not appear to be
viettrungluu
2013/11/06 21:13:39
Thanks, I deleted them (they were left over from w
|
| + void set_subtype(Subtype subtype) { subtype_ = subtype; } |
| + void set_source_id(EndpointId source_id) { source_id_ = source_id; } |
| + void set_destination_id(EndpointId destination_id) { |
| + destination_id_ = destination_id; |
| + } |
| + |
| + // TODO(vtl): Add whatever's necessary to transport handles. |
| // Rounds |n| up to a multiple of |kMessageAlignment|. |
| static inline size_t RoundUpMessageAlignment(size_t n) { |
| @@ -53,14 +85,19 @@ class MOJO_SYSTEM_EXPORT MessageInTransit { |
| } |
| private: |
| - explicit MessageInTransit(uint32_t size) |
| - : size_(size), reserved_(0), user_1_(0), user_2_(0) {} |
| + explicit MessageInTransit(uint32_t size, Type type, Subtype subtype) |
| + : size_(size), |
| + type_(type), |
| + subtype_(subtype), |
| + source_id_(kInvalidEndpointId), |
| + destination_id_(kInvalidEndpointId) {} |
| // "Header" for the data. |
| uint32_t size_; |
| - uint32_t reserved_; |
| - uint32_t user_1_; |
| - uint32_t user_2_; |
| + Type type_; |
| + Subtype subtype_; |
| + EndpointId source_id_; |
| + EndpointId destination_id_; |
| // Intentionally unimplemented (and private): Use |Destroy()| instead (which |
| // simply frees the memory). |