| 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_PUBLIC_BINDINGS_LIB_MESSAGE_H_ | 5 #ifndef MOJO_PUBLIC_BINDINGS_LIB_MESSAGE_H_ |
| 6 #define MOJO_PUBLIC_BINDINGS_LIB_MESSAGE_H_ | 6 #define MOJO_PUBLIC_BINDINGS_LIB_MESSAGE_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "mojo/public/system/core.h" | 10 #include "mojo/public/system/core.h" |
| 11 | 11 |
| 12 namespace mojo { | 12 namespace mojo { |
| 13 | 13 |
| 14 #pragma pack(push, 1) | 14 #pragma pack(push, 1) |
| 15 | 15 |
| 16 struct MessageHeader { | 16 struct MessageHeader { |
| 17 uint32_t num_bytes; | 17 uint32_t num_bytes; |
| 18 uint32_t name; | 18 uint32_t name; |
| 19 }; | 19 }; |
| 20 MOJO_COMPILE_ASSERT(sizeof(MessageHeader) == 8, bad_sizeof_MessageHeader); | 20 MOJO_COMPILE_ASSERT(sizeof(MessageHeader) == 8, bad_sizeof_MessageHeader); |
| 21 | 21 |
| 22 struct MessageData { | 22 struct MessageData { |
| 23 MessageHeader header; | 23 MessageHeader header; |
| 24 uint8_t payload[1]; | 24 uint8_t payload[1]; |
| 25 }; | 25 }; |
| 26 MOJO_COMPILE_ASSERT(sizeof(MessageData) == 9, bad_sizeof_MessageData); | 26 MOJO_COMPILE_ASSERT(sizeof(MessageData) == 9, bad_sizeof_MessageData); |
| 27 | 27 |
| 28 #pragma pack(pop) | 28 #pragma pack(pop) |
| 29 | 29 |
| 30 struct Message { | 30 class Message { |
| 31 public: |
| 31 Message(); | 32 Message(); |
| 32 ~Message(); | 33 ~Message(); |
| 33 | 34 |
| 35 void Swap(Message* other); |
| 36 |
| 34 MessageData* data; // Heap-allocated. | 37 MessageData* data; // Heap-allocated. |
| 35 std::vector<Handle> handles; | 38 std::vector<Handle> handles; |
| 39 |
| 40 private: |
| 41 MOJO_DISALLOW_COPY_AND_ASSIGN(Message); |
| 36 }; | 42 }; |
| 37 | 43 |
| 38 class MessageReceiver { | 44 class MessageReceiver { |
| 39 public: | 45 public: |
| 40 // The receiver may mutate the given message or take ownership of its | 46 // The receiver may mutate the given message or take ownership of its |
| 41 // |message->data| member by setting it to NULL. | 47 // |message->data| member by setting it to NULL. Returns true if the message |
| 48 // was accepted and false otherwise, indicating that the message was invalid |
| 49 // or malformed. |
| 42 virtual bool Accept(Message* message) = 0; | 50 virtual bool Accept(Message* message) = 0; |
| 43 }; | 51 }; |
| 44 | 52 |
| 45 } // namespace mojo | 53 } // namespace mojo |
| 46 | 54 |
| 47 #endif // MOJO_PUBLIC_BINDINGS_LIB_MESSAGE_H_ | 55 #endif // MOJO_PUBLIC_BINDINGS_LIB_MESSAGE_H_ |
| OLD | NEW |