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. |
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 * The <code>padding</code> ensures <code>value</code> is aligned on an |
106 * for 32-bit x86, and some align on 4-byte boundaries. | 107 * 8-byte boundary relative to the start of the struct. Some compilers |
108 * align doubles on 8-byte boundaries for 32-bit x86, and some align on | |
109 * 4-byte boundaries. | |
107 */ | 110 */ |
108 int32_t padding; | 111 int32_t padding; |
109 | 112 |
113 /** | |
114 * This <code>value</code> represents the contents of the PP_Var. Only one of | |
115 * the fields of <code>value</code> is valid at a time based upon | |
116 * <code>type</code>. | |
117 */ | |
110 union { | 118 union { |
119 /** | |
120 * If <code>type</code> is <code>PP_VARTYPE_BOOL</code>, | |
121 * <code>as_bool</code> represents the value of this <code>PP_VAR</code> as | |
dmichael (off chromium)
2011/06/30 10:03:48
PP_VAR->PP_Var, here and for the rest
jond
2011/06/30 16:24:16
Changed throughout document
| |
122 * <code>PP_Bool</code>. | |
123 */ | |
111 PP_Bool as_bool; | 124 PP_Bool as_bool; |
125 | |
126 /** | |
127 * If <code>type</code> is <code>PP_VARTYPE_INT32</code>, | |
128 * <code>as_int</code> represents the value of this <code>PP_VAR</code> as | |
129 * <code>int32_t</code>. | |
130 */ | |
112 int32_t as_int; | 131 int32_t as_int; |
132 | |
133 /** | |
134 * If <code>type</code> is <code>PP_VARTYPE_DOUBLE</code>, | |
135 * <code>as_double</code> represents the value of this <code>PP_VAR</code> | |
136 * as <code>double</code>. | |
137 */ | |
113 double as_double; | 138 double as_double; |
114 | 139 |
115 /** | 140 /** |
116 * Internal ID for strings objects, arrays, and dictionaries. The | 141 * If <code>type</code> is <code>PP_VARTYPE_STRING</code>, |
117 * identifier is an opaque handle assigned by the browser to the plugin. It | 142 * <code>PP_VARTYPE_OBJECT</code>, <code>PP_VARTYPE_ARRAY</code>, or |
118 * is guaranteed never to be 0, so a plugin can initialize this ID to 0 to | 143 * <code>PP_VARTYPE_DICTIONARY</code>, |
119 * indicate a "NULL handle." | 144 * <code>as_id</code> represents the value of this <code>PP_VAR</code> as |
145 * an opaque handle assigned by the browser. This handle is guaranteed | |
146 * never to be 0, so a module can initialize this ID to 0 to indicate a | |
147 * "NULL handle." | |
120 */ | 148 */ |
121 int64_t as_id; | 149 int64_t as_id; |
122 } value; | 150 } value; |
123 }; | 151 }; |
124 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_Var, 16); | 152 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_Var, 16); |
125 /** | 153 /** |
126 * @} | 154 * @} |
127 */ | 155 */ |
128 | 156 |
129 /** | 157 /** |
130 * @addtogroup Functions | 158 * @addtogroup Functions |
131 * @{ | 159 * @{ |
132 */ | 160 */ |
133 | 161 |
134 /** | 162 /** |
135 * PP_MakeUndefined() is a utility function used to wrap an undefined value | 163 * PP_MakeUndefined() is used to wrap an undefined value into a |
136 * into a PP_VAR struct for passing to the browser. | 164 * <code>PP_VAR</code> struct for passing to the browser. |
137 * @return A PP_Var structure | 165 * |
166 * @return A <code>PP_Var</code> structure. | |
138 */ | 167 */ |
139 PP_INLINE struct PP_Var PP_MakeUndefined() { | 168 PP_INLINE struct PP_Var PP_MakeUndefined() { |
140 struct PP_Var result = { PP_VARTYPE_UNDEFINED, 0, {PP_FALSE} }; | 169 struct PP_Var result = { PP_VARTYPE_UNDEFINED, 0, {PP_FALSE} }; |
141 return result; | 170 return result; |
142 } | 171 } |
143 | 172 |
144 /** | 173 /** |
145 * PP_MakeNull() is a utility function used to wrap a null value into a | 174 * PP_MakeNull() is used to wrap a null value into a |
146 * PP_VAR struct for passing to the browser. | 175 * <code>PP_VAR</code> struct for passing to the browser. |
147 * @return A PP_Var structure | 176 * |
177 * @return A <code>PP_Var</code> structure, | |
148 */ | 178 */ |
149 PP_INLINE struct PP_Var PP_MakeNull() { | 179 PP_INLINE struct PP_Var PP_MakeNull() { |
150 struct PP_Var result = { PP_VARTYPE_NULL, 0, {PP_FALSE} }; | 180 struct PP_Var result = { PP_VARTYPE_NULL, 0, {PP_FALSE} }; |
151 return result; | 181 return result; |
152 } | 182 } |
153 | 183 |
154 /** | 184 /** |
155 * PP_MakeBool() is a utility function used to wrap a boolean value into a | 185 * PP_MakeBool() is used to wrap a boolean value into a |
156 * PP_VAR struct for passing to the browser. | 186 * <code>PP_VAR</code> struct for passing to the browser. |
157 * @param[in] value A PP_Bool enumeration | 187 * |
158 * @return A PP_Var structure | 188 * @param[in] value A <code>PP_Bool</code> enumeration to |
189 * wrap. | |
190 * | |
191 * @return A <code>PP_Var</code> structure. | |
159 */ | 192 */ |
160 PP_INLINE struct PP_Var PP_MakeBool(PP_Bool value) { | 193 PP_INLINE struct PP_Var PP_MakeBool(PP_Bool value) { |
161 struct PP_Var result = { PP_VARTYPE_BOOL, 0, {PP_FALSE} }; | 194 struct PP_Var result = { PP_VARTYPE_BOOL, 0, {PP_FALSE} }; |
162 result.value.as_bool = value; | 195 result.value.as_bool = value; |
163 return result; | 196 return result; |
164 } | 197 } |
165 | 198 |
166 /** | 199 /** |
167 * PP_MakeInt32() is a utility function used to wrap a 32 bit integer value | 200 * PP_MakeInt32() is used to wrap a 32 bit integer value |
168 * into a PP_VAR struct for passing to the browser. | 201 * into a <code>PP_VAR</code> struct for passing to the browser. |
169 * @param[in] value An int32 | 202 * |
170 * @return A PP_Var structure | 203 * @param[in] value An int32 to wrap. |
204 * | |
205 * @return A <code>PP_Var</code> structure. | |
171 */ | 206 */ |
172 PP_INLINE struct PP_Var PP_MakeInt32(int32_t value) { | 207 PP_INLINE struct PP_Var PP_MakeInt32(int32_t value) { |
173 struct PP_Var result = { PP_VARTYPE_INT32, 0, {PP_FALSE} }; | 208 struct PP_Var result = { PP_VARTYPE_INT32, 0, {PP_FALSE} }; |
174 result.value.as_int = value; | 209 result.value.as_int = value; |
175 return result; | 210 return result; |
176 } | 211 } |
177 | 212 |
178 /** | 213 /** |
179 * PP_MakeDouble() is a utility function used to wrap a double value into a | 214 * PP_MakeDouble() is used to wrap a double value into a |
180 * PP_VAR struct for passing to the browser. | 215 * <code>PP_VAR</code> struct for passing to the browser. |
181 * @param[in] value A double | 216 * |
182 * @return A PP_Var structure | 217 * @param[in] value A double to wrap. |
218 * | |
219 * @return A <code>PP_Var</code> structure. | |
183 */ | 220 */ |
184 PP_INLINE struct PP_Var PP_MakeDouble(double value) { | 221 PP_INLINE struct PP_Var PP_MakeDouble(double value) { |
185 struct PP_Var result = { PP_VARTYPE_DOUBLE, 0, {PP_FALSE} }; | 222 struct PP_Var result = { PP_VARTYPE_DOUBLE, 0, {PP_FALSE} }; |
186 result.value.as_double = value; | 223 result.value.as_double = value; |
187 return result; | 224 return result; |
188 } | 225 } |
189 /** | 226 /** |
190 * @} | 227 * @} |
191 */ | 228 */ |
192 | 229 |
193 #endif /* PPAPI_C_PP_VAR_H_ */ | 230 #endif /* PPAPI_C_PP_VAR_H_ */ |
194 | 231 |
OLD | NEW |