• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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_CPP_BINDINGS_LIB_MESSAGE_INTERNAL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_INTERNAL_H_
7 
8 #include <stdint.h>
9 
10 #include <string>
11 
12 #include "base/callback.h"
13 #include "base/component_export.h"
14 #include "base/macros.h"
15 #include "mojo/public/cpp/bindings/lib/bindings_internal.h"
16 
17 namespace mojo {
18 
19 class Message;
20 
21 namespace internal {
22 
23 template <typename T>
24 class Array_Data;
25 
26 #pragma pack(push, 1)
27 
28 struct MessageHeader : internal::StructHeader {
29   // Interface ID for identifying multiple interfaces running on the same
30   // message pipe.
31   uint32_t interface_id;
32   // Message name, which is scoped to the interface that the message belongs to.
33   uint32_t name;
34   // 0 or either of the enum values defined above.
35   uint32_t flags;
36   // Unused padding to make the struct size a multiple of 8 bytes.
37   uint32_t padding;
38 };
39 static_assert(sizeof(MessageHeader) == 24, "Bad sizeof(MessageHeader)");
40 
41 struct MessageHeaderV1 : MessageHeader {
42   // Only used if either kFlagExpectsResponse or kFlagIsResponse is set in
43   // order to match responses with corresponding requests.
44   uint64_t request_id;
45 };
46 static_assert(sizeof(MessageHeaderV1) == 32, "Bad sizeof(MessageHeaderV1)");
47 
48 struct MessageHeaderV2 : MessageHeaderV1 {
49   MessageHeaderV2();
50   GenericPointer payload;
51   Pointer<Array_Data<uint32_t>> payload_interface_ids;
52 };
53 static_assert(sizeof(MessageHeaderV2) == 48, "Bad sizeof(MessageHeaderV2)");
54 
55 #pragma pack(pop)
56 
COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE)57 class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) MessageDispatchContext {
58  public:
59   explicit MessageDispatchContext(Message* message);
60   ~MessageDispatchContext();
61 
62   static MessageDispatchContext* current();
63 
64   base::OnceCallback<void(const std::string&)> GetBadMessageCallback();
65 
66  private:
67   MessageDispatchContext* outer_context_;
68   Message* message_;
69 
70   DISALLOW_COPY_AND_ASSIGN(MessageDispatchContext);
71 };
72 
COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE)73 class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) SyncMessageResponseSetup {
74  public:
75   static void SetCurrentSyncResponseMessage(Message* message);
76 };
77 
78 COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE)
79 size_t ComputeSerializedMessageSize(uint32_t flags,
80                                     size_t payload_size,
81                                     size_t payload_interface_id_count);
82 
83 }  // namespace internal
84 }  // namespace mojo
85 
86 #endif  // MOJO_PUBLIC_CPP_BINDINGS_LIB_MESSAGE_INTERNAL_H_
87