| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 // Message is a holder for the data and handles to be sent over a MessagePipe. | 30 // Message is a holder for the data and handles to be sent over a MessagePipe. |
| 31 // Message owns its data, but a consumer of Message is free to manipulate the | 31 // Message owns its data and handles, but a consumer of Message is free to |
| 32 // data member or replace it. If replacing, then be sure to use |malloc| to | 32 // manipulate the data and handles members. |
| 33 // allocate the memory. | |
| 34 class Message { | 33 class Message { |
| 35 public: | 34 public: |
| 36 Message(); | 35 Message(); |
| 37 ~Message(); | 36 ~Message(); |
| 38 | 37 |
| 39 void Swap(Message* other); | 38 void Swap(Message* other); |
| 40 | 39 |
| 41 MessageData* data; // Heap-allocated. | 40 MessageData* data; // Heap-allocated using malloc. |
| 42 std::vector<Handle> handles; | 41 std::vector<Handle> handles; |
| 43 | 42 |
| 44 private: | 43 private: |
| 45 MOJO_DISALLOW_COPY_AND_ASSIGN(Message); | 44 MOJO_DISALLOW_COPY_AND_ASSIGN(Message); |
| 46 }; | 45 }; |
| 47 | 46 |
| 48 class MessageReceiver { | 47 class MessageReceiver { |
| 49 public: | 48 public: |
| 50 // The receiver may mutate the given message or take ownership of its | 49 // The receiver may mutate the given message or take ownership of its |
| 51 // |message->data| member by setting it to NULL. Returns true if the message | 50 // |message->data| member by setting it to NULL. Returns true if the message |
| 52 // was accepted and false otherwise, indicating that the message was invalid | 51 // was accepted and false otherwise, indicating that the message was invalid |
| 53 // or malformed. | 52 // or malformed. |
| 54 virtual bool Accept(Message* message) = 0; | 53 virtual bool Accept(Message* message) = 0; |
| 55 }; | 54 }; |
| 56 | 55 |
| 57 } // namespace mojo | 56 } // namespace mojo |
| 58 | 57 |
| 59 #endif // MOJO_PUBLIC_BINDINGS_LIB_MESSAGE_H_ | 58 #endif // MOJO_PUBLIC_BINDINGS_LIB_MESSAGE_H_ |
| OLD | NEW |