OLD | NEW |
---|---|
1 /* Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2011 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 PPAPI_C_PP_VAR_H_ | 5 #ifndef PPAPI_C_PP_VAR_H_ |
6 #define PPAPI_C_PP_VAR_H_ | 6 #define PPAPI_C_PP_VAR_H_ |
7 | 7 |
8 #include "ppapi/c/pp_bool.h" | 8 #include "ppapi/c/pp_bool.h" |
9 #include "ppapi/c/pp_macros.h" | 9 #include "ppapi/c/pp_macros.h" |
10 #include "ppapi/c/pp_stdint.h" | 10 #include "ppapi/c/pp_stdint.h" |
11 | 11 |
12 /** | 12 /** |
13 * @file | 13 * @file |
14 * This file defines the API for handling the passing of data types between | 14 * This file defines the API for handling the passing of data types between |
15 * your module and the page. | 15 * your module and the page. |
16 */ | 16 */ |
17 | 17 |
18 /** | 18 /** |
19 * | 19 * |
20 * @addtogroup Enums | 20 * @addtogroup Enums |
21 * @{ | 21 * @{ |
22 */ | 22 */ |
23 | 23 |
24 /** | 24 /** |
25 * PP_VarType is an enumeration of the different types that can be contained | 25 * The <code>PP_VarType</code> is an enumeration of the different types that |
26 * within a PP_VAR structure. | 26 * can be contained within a <code>PP_VAR</code> structure. |
27 */ | 27 */ |
28 typedef enum { | 28 typedef enum { |
29 /** | 29 /** |
30 * An undefined value. | 30 * An undefined value. |
31 */ | 31 */ |
32 PP_VARTYPE_UNDEFINED, | 32 PP_VARTYPE_UNDEFINED, |
33 | 33 |
34 /** | 34 /** |
35 * A NULL value. This is similar to undefined, but JavaScript differentiates | 35 * A NULL value. This is similar to undefined, but JavaScript differentiates |
36 * the two so we expose it here as well. | 36 * the two so it is exposed here as well. |
37 */ | 37 */ |
38 PP_VARTYPE_NULL, | 38 PP_VARTYPE_NULL, |
39 | 39 |
40 /** | 40 /** |
41 * A boolean value, use the as_bool member of the var. | 41 * A boolean value, use the <code>as_bool</code> member of the var. |
42 */ | 42 */ |
43 PP_VARTYPE_BOOL, | 43 PP_VARTYPE_BOOL, |
44 | 44 |
45 /** | 45 /** |
46 * A 32-bit integer value. Use the as_int member of the var. | 46 * A 32-bit integer value. Use the <code>as_int</code> member of the var. |
47 */ | 47 */ |
48 PP_VARTYPE_INT32, | 48 PP_VARTYPE_INT32, |
49 | 49 |
50 /** | 50 /** |
51 * A double-precision floating point value. Use the as_double member of the | 51 * A double-precision floating point value. Use the <code>as_double</code> |
52 * var. | 52 * member of the var. |
53 */ | 53 */ |
54 PP_VARTYPE_DOUBLE, | 54 PP_VARTYPE_DOUBLE, |
55 | 55 |
56 /** | 56 /** |
57 * The Var represents a string. The as_id field is used to identify the | 57 * The Var represents a string. The <code>as_id</code> field is used to |
58 * string, which may be created and retrieved from the PPB_Var interface. | 58 * identify the string, which may be created and retrieved from the |
59 * <code>PPB_Var</code> interface. | |
59 */ | 60 */ |
60 PP_VARTYPE_STRING, | 61 PP_VARTYPE_STRING, |
61 | 62 |
62 /** | 63 /** |
63 * Represents a JavaScript object. This vartype is not currently usable | 64 * Represents a JavaScript object. This vartype is not currently usable |
64 * from plugins, although it is used internally for some tasks. | 65 * from modules, although it is used internally for some tasks. |
dmichael (off chromium)
2011/06/27 15:45:41
I think this is one place where we could legitimat
| |
65 */ | 66 */ |
66 PP_VARTYPE_OBJECT, | 67 PP_VARTYPE_OBJECT, |
67 | 68 |
68 /** | 69 /** |
69 * Arrays and dictionaries are not currently supported but will be added | 70 * Arrays and dictionaries are not currently supported but will be added |
70 * in future revisions. These objects are reference counted so be sure | 71 * in future revisions. These objects are reference counted so be sure |
71 * to properly AddRef/Release them as you would with strings to ensure your | 72 * to properly AddRef/Release them as you would with strings to ensure your |
72 * plugin will continue to work with future versions of the API. | 73 * module will continue to work with future versions of the API. |
73 */ | 74 */ |
74 PP_VARTYPE_ARRAY, | 75 PP_VARTYPE_ARRAY, |
75 PP_VARTYPE_DICTIONARY | 76 PP_VARTYPE_DICTIONARY |
76 } PP_VarType; | 77 } PP_VarType; |
77 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VarType, 4); | 78 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VarType, 4); |
78 /** | 79 /** |
79 * @} | 80 * @} |
80 */ | 81 */ |
81 | 82 |
82 /** | 83 /** |
83 * @addtogroup Structs | 84 * @addtogroup Structs |
84 * @{ | 85 * @{ |
85 */ | 86 */ |
86 | 87 |
87 /** | 88 /** |
88 * The PP_VAR struct is a variant data type and can contain any | 89 * The <code>PP_VAR</code> struct is a variant data type and can contain any |
89 * value of one of the types named in the PP_VarType enum. This structure is | 90 * value of one of the types named in the <code>PP_VarType</code> enum. This |
90 * for passing data between native code which can be strongly typed and the | 91 * structure is for passing data between native code which can be strongly |
91 * browser (JavaScript) which isn't strongly typed. | 92 * typed and the browser (JavaScript) which isn't strongly typed. |
92 * | 93 * |
93 * JavaScript has a "number" type for holding a number, and does not | 94 * JavaScript has a "number" type for holding a number, and does not |
94 * differentiate between floating point and integer numbers. The | 95 * differentiate between floating point and integer numbers. The |
95 * JavaScript operations will try to optimize operations by using | 96 * JavaScript operations will try to optimize operations by using |
96 * integers when possible, but could end up with doubles. Therefore, | 97 * integers when possible, but could end up with doubles. Therefore, |
97 * you can't assume a numeric PP_Var will be the type you expect. | 98 * you can't assume a numeric <code>PP_Var</code> will be the type you expect. |
98 * Your code should be capable of handling either int32_t or double for numeric | 99 * Your code should be capable of handling either int32_t or double for numeric |
99 * PP_Vars sent from JavaScript. | 100 * PP_Vars sent from JavaScript. |
100 */ | 101 */ |
101 struct PP_Var { | 102 struct PP_Var { |
102 PP_VarType type; | 103 PP_VarType type; |
103 | 104 |
104 /** Ensures @a value is aligned on an 8-byte boundary relative to the | 105 /** |
105 * start of the struct. Some compilers align doubles on 8-byte boundaries | 106 * This value ensures <code>value</code> is aligned on an 8-byte boundary |
dmichael (off chromium)
2011/06/27 15:45:41
I think this says 'value' one too many times. May
jond
2011/06/29 21:14:38
Had to put "The <code>padding</code>" because padd
| |
106 * for 32-bit x86, and some align on 4-byte boundaries. | 107 * relative to the start of the struct. Some compilers align doubles on |
108 * 8-byte boundaries for 32-bit x86, and some align on 4-byte boundaries. | |
107 */ | 109 */ |
108 int32_t padding; | 110 int32_t padding; |
109 | 111 |
112 /** | |
113 * This value represents how you want to treat this PP_Var: as a bool, int, | |
114 * double, or id. | |
dmichael (off chromium)
2011/06/27 15:45:41
This comment is not accurate. |value| really does
jond
2011/06/29 21:14:38
Done.
jond
2011/06/29 21:14:38
Done.
| |
115 */ | |
110 union { | 116 union { |
117 /** | |
118 * This value indiciates that this <code>PP_Var</code> will be treatd as a | |
119 * bool. | |
120 */ | |
dmichael (off chromium)
2011/06/27 15:45:41
Something like:
'If <code>type</code> is PP_VARTYP
jond
2011/06/29 21:14:38
Can you double-check the as_id description now...
| |
111 PP_Bool as_bool; | 121 PP_Bool as_bool; |
122 | |
123 /** | |
124 * This value indiciates that this <code>PP_Var</code> will be treatd as an | |
125 * int. | |
126 */ | |
112 int32_t as_int; | 127 int32_t as_int; |
128 | |
129 /** | |
130 * This value indiciates that this <code>PP_Var</code> will be treatd as a | |
131 * double. | |
132 */ | |
113 double as_double; | 133 double as_double; |
114 | 134 |
115 /** | 135 /** |
116 * Internal ID for strings objects, arrays, and dictionaries. The | 136 * Internal ID for strings objects, arrays, and dictionaries. The |
dmichael (off chromium)
2011/06/27 15:45:41
please add a comma after strings since you're in t
jond
2011/06/29 21:14:38
Done.
| |
117 * identifier is an opaque handle assigned by the browser to the plugin. It | 137 * identifier is an opaque handle assigned by the browser to the module. It |
dmichael (off chromium)
2011/06/27 15:45:41
I think we should just take out 'to the module'; I
jond
2011/06/29 21:14:38
Done.
jond
2011/06/29 21:14:38
Done.
| |
118 * is guaranteed never to be 0, so a plugin can initialize this ID to 0 to | 138 * is guaranteed never to be 0, so a module can initialize this ID to 0 to |
119 * indicate a "NULL handle." | 139 * indicate a "NULL handle." |
120 */ | 140 */ |
121 int64_t as_id; | 141 int64_t as_id; |
122 } value; | 142 } value; |
123 }; | 143 }; |
124 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_Var, 16); | 144 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_Var, 16); |
125 /** | 145 /** |
126 * @} | 146 * @} |
127 */ | 147 */ |
128 | 148 |
129 /** | 149 /** |
130 * @addtogroup Functions | 150 * @addtogroup Functions |
131 * @{ | 151 * @{ |
132 */ | 152 */ |
133 | 153 |
134 /** | 154 /** |
135 * PP_MakeUndefined() is a utility function used to wrap an undefined value | 155 * This function is used to wrap an undefined value into a <code>PP_VAR</code> |
136 * into a PP_VAR struct for passing to the browser. | 156 * struct for passing to the browser. |
137 * @return A PP_Var structure | 157 * @return A <code>PP_Var</code> structure |
138 */ | 158 */ |
139 PP_INLINE struct PP_Var PP_MakeUndefined() { | 159 PP_INLINE struct PP_Var PP_MakeUndefined() { |
140 struct PP_Var result = { PP_VARTYPE_UNDEFINED, 0, {PP_FALSE} }; | 160 struct PP_Var result = { PP_VARTYPE_UNDEFINED, 0, {PP_FALSE} }; |
141 return result; | 161 return result; |
142 } | 162 } |
143 | 163 |
144 /** | 164 /** |
145 * PP_MakeNull() is a utility function used to wrap a null value into a | 165 * This function function is used to wrap a null value into a |
dmichael (off chromium)
2011/06/27 15:45:41
If you stick with this wording, remove the extra '
jond
2011/06/29 21:14:38
Done.
| |
146 * PP_VAR struct for passing to the browser. | 166 * <code>PP_VAR</code> struct for passing to the browser. |
147 * @return A PP_Var structure | 167 * @return A <code>PP_Var</code> structure |
148 */ | 168 */ |
149 PP_INLINE struct PP_Var PP_MakeNull() { | 169 PP_INLINE struct PP_Var PP_MakeNull() { |
150 struct PP_Var result = { PP_VARTYPE_NULL, 0, {PP_FALSE} }; | 170 struct PP_Var result = { PP_VARTYPE_NULL, 0, {PP_FALSE} }; |
151 return result; | 171 return result; |
152 } | 172 } |
153 | 173 |
154 /** | 174 /** |
155 * PP_MakeBool() is a utility function used to wrap a boolean value into a | 175 * This function isused to wrap a boolean value into a |
dmichael (off chromium)
2011/06/27 15:45:41
isused->is used
jond
2011/06/29 21:14:38
Done.
| |
156 * PP_VAR struct for passing to the browser. | 176 * <code>PP_VAR</code> struct for passing to the browser. |
157 * @param[in] value A PP_Bool enumeration | 177 * @param[in] value A <code>PP_Bool</code> enumeration |
158 * @return A PP_Var structure | 178 * @return A <code>PP_Var</code> structure |
159 */ | 179 */ |
160 PP_INLINE struct PP_Var PP_MakeBool(PP_Bool value) { | 180 PP_INLINE struct PP_Var PP_MakeBool(PP_Bool value) { |
161 struct PP_Var result = { PP_VARTYPE_BOOL, 0, {PP_FALSE} }; | 181 struct PP_Var result = { PP_VARTYPE_BOOL, 0, {PP_FALSE} }; |
162 result.value.as_bool = value; | 182 result.value.as_bool = value; |
163 return result; | 183 return result; |
164 } | 184 } |
165 | 185 |
166 /** | 186 /** |
167 * PP_MakeInt32() is a utility function used to wrap a 32 bit integer value | 187 * This function is used to wrap a 32 bit integer value |
168 * into a PP_VAR struct for passing to the browser. | 188 * into a <code>PP_VAR</code> struct for passing to the browser. |
169 * @param[in] value An int32 | 189 * @param[in] value An int32 |
170 * @return A PP_Var structure | 190 * @return A <code>PP_Var</code> structure |
171 */ | 191 */ |
172 PP_INLINE struct PP_Var PP_MakeInt32(int32_t value) { | 192 PP_INLINE struct PP_Var PP_MakeInt32(int32_t value) { |
173 struct PP_Var result = { PP_VARTYPE_INT32, 0, {PP_FALSE} }; | 193 struct PP_Var result = { PP_VARTYPE_INT32, 0, {PP_FALSE} }; |
174 result.value.as_int = value; | 194 result.value.as_int = value; |
175 return result; | 195 return result; |
176 } | 196 } |
177 | 197 |
178 /** | 198 /** |
179 * PP_MakeDouble() is a utility function used to wrap a double value into a | 199 * This function is used to wrap a double value into a |
180 * PP_VAR struct for passing to the browser. | 200 * <code>PP_VAR</code> struct for passing to the browser. |
181 * @param[in] value A double | 201 * @param[in] value A double |
182 * @return A PP_Var structure | 202 * @return A <code>PP_Var</code> structure |
183 */ | 203 */ |
184 PP_INLINE struct PP_Var PP_MakeDouble(double value) { | 204 PP_INLINE struct PP_Var PP_MakeDouble(double value) { |
185 struct PP_Var result = { PP_VARTYPE_DOUBLE, 0, {PP_FALSE} }; | 205 struct PP_Var result = { PP_VARTYPE_DOUBLE, 0, {PP_FALSE} }; |
186 result.value.as_double = value; | 206 result.value.as_double = value; |
187 return result; | 207 return result; |
188 } | 208 } |
189 /** | 209 /** |
190 * @} | 210 * @} |
191 */ | 211 */ |
192 | 212 |
193 #endif /* PPAPI_C_PP_VAR_H_ */ | 213 #endif /* PPAPI_C_PP_VAR_H_ */ |
194 | 214 |
OLD | NEW |