OLD | NEW |
---|---|
(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 // This file contains structs used for constructing type descriptors for | |
6 // generated mojom types. A type descriptor for a mojom struct is a table | |
7 // describing the byte-offsets of all the pointers and handles in the struct, | |
8 // and has references to the type descriptorss that further describe the | |
9 // pointers. The table is used for doing all computations for the struct -- | |
10 // determining serialized size, encoding and decoding recursively, etc. A type | |
11 // descriptor is generated for each struct, union, array and map. Note that | |
12 // mojom maps are just mojom structs with two mojom arrays, so there is no | |
13 // separate descriptor for it. | |
14 // | |
15 // The user is not expected to construct type descriptors -- a bindings | |
16 // generator will do this when it generates bindings for a mojom file. | |
17 // | |
18 // A type descriptor for a mojom struct is a |MojomTypeDescriptorStruct| | |
19 // containing an array of entries of types of |MojomTypeDescriptorStructEntry|. | |
20 // Similarly, unions are described with |MojomTypeDescriptorUnion| with entries | |
21 // of |MojomTypeDescriptorUnionEntry|. Arrays are described with | |
22 // |MojomTypeDescriptorArray|. | |
23 | |
24 #ifndef MOJO_PUBLIC_C_BINDINGS_LIB_TYPE_DESCRIPTOR_H_ | |
25 #define MOJO_PUBLIC_C_BINDINGS_LIB_TYPE_DESCRIPTOR_H_ | |
26 | |
27 #include <stdbool.h> | |
28 #include <stdint.h> | |
29 | |
30 #include "mojo/public/c/system/macros.h" | |
31 | |
32 MOJO_BEGIN_EXTERN_C | |
33 | |
34 // This enum is used in a type descriptor entry for the |elem_type| field, and | |
35 // indicates which type the accompanying |elem_table| is describing (if it is | |
36 // describing a reference type), or to indicate that it's a handle type. | |
37 // Values that correspond to an |elem_table|'s pointer type: | |
38 // - If MOJOM_TYPE_DESCRIPTOR_TYPE_STRUCT, then |elem_table| points to a | |
39 // |MojomTypeDescriptorStruct|. | |
40 // - If MOJOM_TYPE_DESCRIPTOR_TYPE_UNION, then |elem_table| points to a | |
41 // |MojomTypeDescriptorUnion|. | |
42 // - If MOJOM_TYPE_DESCRIPTOR_TYPE_ARRAY, then |elem_table| points to a | |
43 // |MojomTypeDescriptorArray|. | |
44 // - For any other value, |elem_table| is NULL. | |
45 enum MojomTypeDescriptorType { | |
46 // Note: A map is a mojom struct with 2 mojom arrays, so we don't have a | |
47 // separate descriptor type for it. | |
48 MOJOM_TYPE_DESCRIPTOR_TYPE_STRUCT = 0, | |
49 MOJOM_TYPE_DESCRIPTOR_TYPE_ARRAY = 1, | |
50 MOJOM_TYPE_DESCRIPTOR_TYPE_UNION = 2, | |
51 MOJOM_TYPE_DESCRIPTOR_TYPE_HANDLE = 3, | |
52 MOJOM_TYPE_DESCRIPTOR_TYPE_INTERFACE = 4, | |
53 // This is only used in an array descriptor, and serves as a way to terminate | |
54 // a chain of array descriptors; the last entry in the chain always contains a | |
55 // plain-old-data type. | |
56 MOJOM_TYPE_DESCRIPTOR_TYPE_POD = 5, | |
57 }; | |
58 | |
59 // Mojom structs are described using this struct. | |
60 struct MojomTypeDescriptorStruct { | |
61 size_t num_entries; | |
62 // |entries| is an array of |num_entries|, each describing a field of | |
63 // reference or handle type. | |
64 const struct MojomTypeDescriptorStructEntry* entries; | |
65 }; | |
66 | |
67 // This struct is used to describe each entry in a mojom struct. Each entry | |
68 // indicates whether it is describing a reference type, or a handle type through | |
69 // the field |elem_type|. |elem_table| points to the type descriptor describing | |
70 // the field, if the type has one (handles don't have type descriptors). | |
71 // |offset| indicates the starting byte offset of the element within the struct. | |
72 struct MojomTypeDescriptorStructEntry { | |
73 // See comments for |MojomTypeDescriptorType| on possible values and | |
74 // corresponding behaviour with |elem_table|. | |
75 enum MojomTypeDescriptorType elem_type; | |
76 // Use |elem_type| to decide which type |elem_table| should be casted to. | |
77 const void* elem_table; | |
viettrungluu
2016/06/22 15:33:02
Probably you should call it elem_descriptor instea
vardhan
2016/06/22 15:44:27
Done.
| |
78 // |offset| does not account for the struct header. Offset 0 always refers to | |
79 // the first element. | |
80 uint32_t offset; | |
81 // Corresponds to the '[MinVersion]' attribute in mojom IDL. This determines | |
82 // if this field should be ignored if its min_version < version of the struct | |
83 // we are dealing with. | |
84 uint32_t min_version; | |
85 // Is this field nullable? | |
86 bool nullable; | |
87 }; | |
88 | |
89 // Mojom unions are described using this struct. | |
90 struct MojomTypeDescriptorUnion { | |
91 size_t num_entries; | |
92 const struct MojomTypeDescriptorUnionEntry* entries; | |
93 }; | |
94 | |
95 // Like |MojomTypeDescriptorStructEntry|, this variant is used to construct a | |
96 // type descriptor for a union. Instead of an offset, it describes a union field | |
97 // by its |tag|. | |
98 struct MojomTypeDescriptorUnionEntry { | |
99 // See comments for |MojomTypeDescriptorType| on possible values and | |
100 // corresponding behaviour with |elem_table|. | |
101 enum MojomTypeDescriptorType elem_type; | |
102 const void* elem_table; | |
viettrungluu
2016/06/22 15:33:02
"
vardhan
2016/06/22 15:44:27
Done.
| |
103 // The tag of the union field. | |
104 uint32_t tag; | |
105 bool nullable; | |
106 }; | |
107 | |
108 // Describes a mojom array. To describe an array, we don't need a table of | |
109 // entries, since arrays can only describe 1 type. However, that one type can | |
110 // recursively be an array (e.g, array<array<int>>), in which case a chain of | |
111 // array entries are constructed. | |
112 struct MojomTypeDescriptorArray { | |
113 enum MojomTypeDescriptorType elem_type; | |
114 const void* elem_table; | |
viettrungluu
2016/06/22 15:33:02
"
vardhan
2016/06/22 15:44:27
Done.
| |
115 // How many elements is this array expected to hold? | |
116 // 0 means unspecified. | |
117 uint32_t num_elements; | |
118 bool nullable; | |
119 }; | |
120 | |
121 // This describes a mojom string. | |
122 // A mojom string is a mojom array of chars without a fixed-sized. | |
123 extern const struct MojomTypeDescriptorArray g_mojom_string_type_description; | |
124 | |
125 MOJO_END_EXTERN_C | |
126 | |
127 #endif // MOJO_PUBLIC_C_BINDINGS_LIB_TYPE_DESCRIPTOR_H_ | |
OLD | NEW |