Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(669)

Side by Side Diff: mojo/public/c/bindings/message.h

Issue 2232833003: Change the canonical way to include the C bindings headers to <mojo/bindings/*.h>. (Closed) Base URL: https://github.com/domokit/mojo.git@work791_mojo_tests
Patch Set: rebased Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/c/bindings/map.h ('k') | mojo/public/c/bindings/string.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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_C_BINDINGS_MESSAGE_H_
6 #define MOJO_PUBLIC_C_BINDINGS_MESSAGE_H_
7
8 #include <mojo/macros.h>
9 #include <stdint.h>
10
11 #include "mojo/public/c/bindings/struct.h"
12 #include "mojo/public/c/bindings/validation.h"
13
14 MOJO_BEGIN_EXTERN_C
15
16 #define MOJOM_MESSAGE_FLAGS_EXPECTS_RESPONSE ((uint32_t)(1 << 0u))
17 #define MOJOM_MESSAGE_FLAGS_IS_RESPONSE ((uint32_t)(1 << 1u))
18
19 // All mojom messages (over a message pipe) are framed with a MojomMessage as
20 // its header.
21 // MojomMessage is actually a mojom struct -- we define it here since it's
22 // easier to read, and the validation has more to it than simple mojom struct
23 // validation.
24 struct MojomMessage {
25 // header.version = 0 (version 1 has a request_id)
26 struct MojomStructHeader header;
27 // The ordinal number associated with this message. This is specified
28 // (implicitly, if not explicitly) in the mojom IDL for an interface message
29 // and is used to identify it.
30 uint32_t ordinal;
31 // Described by the MOJOM_MESSAGE_* flags defined above.
32 uint32_t flags;
33 };
34 MOJO_STATIC_ASSERT(sizeof(struct MojomMessage) == 16,
35 "struct MojomMessage must be 16 bytes");
36
37 // Using |MojomMessage| as a member of this struct could work, but usability
38 // would suffer a little while accessing the |header|. MojomMessageWithRequestId
39 // is a "newer" version than MojomMessage.
40 struct MojomMessageWithRequestId {
41 // header.version = 1
42 struct MojomStructHeader header;
43 // Which message is it?
44 uint32_t ordinal;
45 // Described by the MOJOM_MESSAGE_* flags defined above.
46 uint32_t flags;
47 uint64_t request_id;
48 };
49 MOJO_STATIC_ASSERT(sizeof(struct MojomMessageWithRequestId) == 24,
50 "MojomMessageWithRequestId must be 24 bytes");
51
52 // Validates that |in_buf| is a valid mojom message. This does not validate the
53 // contents of the message's body, only the message header. This function does
54 // not validate whether a message should be a kind of request.
55 // |in_buf|: can be a MojomMessage or a MojomMessageWithRequestId.
56 // |in_buf_size|: number of bytes in |in_buf|.
57 MojomValidationResult MojomMessage_ValidateHeader(const void* in_buf,
58 uint32_t in_buf_size);
59
60 // Validates that the given message is a request expecting a response. Assumes
61 // that the message is already validated by MojomMessage_ValidateHeader().
62 MojomValidationResult MojomMessage_ValidateRequestExpectingResponse(
63 const void* in_buf);
64
65 // Validates that the given message is a request which isn't expecting a
66 // response. Assumes that the message is already validated by
67 // MojomMessage_ValidateHeader().
68 MojomValidationResult MojomMessage_ValidateRequestWithoutResponse(
69 const void* in_buf);
70
71 // Validates that the given message is a response. Assumes taht the message is
72 // already validated by MojomMessage_ValidateHeader().
73 MojomValidationResult MojomMessage_ValidateResponse(const void* in_buf);
74
75 MOJO_END_EXTERN_C
76
77 #endif // MOJO_PUBLIC_C_BINDINGS_MESSAGE_H_
OLDNEW
« no previous file with comments | « mojo/public/c/bindings/map.h ('k') | mojo/public/c/bindings/string.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698