- add sources.
[platform/framework/web/crosswalk.git] / src / mojo / public / bindings / lib / message.h
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
3 // found in the LICENSE file.
4
5 #ifndef MOJO_PUBLIC_BINDINGS_LIB_MESSAGE_H_
6 #define MOJO_PUBLIC_BINDINGS_LIB_MESSAGE_H_
7
8 #include <vector>
9
10 #include "mojo/public/system/core.h"
11
12 namespace mojo {
13
14 #pragma pack(push, 1)
15
16 struct MessageHeader {
17   uint32_t num_bytes;
18   uint32_t name;
19 };
20 MOJO_COMPILE_ASSERT(sizeof(MessageHeader) == 8, bad_sizeof_MessageHeader);
21
22 struct MessageData {
23   MessageHeader header;
24   uint8_t payload[1];
25 };
26 MOJO_COMPILE_ASSERT(sizeof(MessageData) == 9, bad_sizeof_MessageData);
27
28 #pragma pack(pop)
29
30 struct Message {
31   Message();
32   ~Message();
33
34   MessageData* data;  // Heap-allocated.
35   std::vector<Handle> handles;
36 };
37
38 class MessageReceiver {
39  public:
40   // The receiver may mutate the given message or take ownership of its
41   // |message->data| member by setting it to NULL.
42   virtual bool Accept(Message* message) = 0;
43 };
44
45 }  // namespace mojo
46
47 #endif  // MOJO_PUBLIC_BINDINGS_LIB_MESSAGE_H_