blob: 15a8df69653eda3d6f776306be39bc6aebc50d15 [file] [log] [blame]
[email protected]256513872012-01-05 15:41:521/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]6ea69542010-12-20 18:15:592 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
[email protected]9b37f4802011-07-19 00:09:285
[email protected]56d75f22014-04-10 23:58:416/* From pp_var.idl modified Thu Apr 10 14:52:30 2014. */
[email protected]9b37f4802011-07-19 00:09:287
[email protected]1758e882010-11-01 16:16:508#ifndef PPAPI_C_PP_VAR_H_
9#define PPAPI_C_PP_VAR_H_
10
[email protected]f98c6a12011-01-28 22:28:4311#include "ppapi/c/pp_bool.h"
12#include "ppapi/c/pp_macros.h"
13#include "ppapi/c/pp_stdint.h"
14
[email protected]1758e882010-11-01 16:16:5015/**
16 * @file
[email protected]6b91c40a2011-02-03 17:52:3917 * This file defines the API for handling the passing of data types between
18 * your module and the page.
[email protected]1758e882010-11-01 16:16:5019 */
20
[email protected]9b37f4802011-07-19 00:09:2821
[email protected]040d5e82011-01-28 15:38:3822/**
[email protected]040d5e82011-01-28 15:38:3823 * @addtogroup Enums
24 * @{
25 */
[email protected]6b91c40a2011-02-03 17:52:3926/**
[email protected]c5495952011-06-30 22:57:1727 * The <code>PP_VarType</code> is an enumeration of the different types that
28 * can be contained within a <code>PP_Var</code> structure.
[email protected]6b91c40a2011-02-03 17:52:3929 */
[email protected]1758e882010-11-01 16:16:5030typedef enum {
[email protected]9b6db26f2011-04-11 04:27:4731 /**
32 * An undefined value.
33 */
[email protected]03f54582011-11-13 02:43:3334 PP_VARTYPE_UNDEFINED = 0,
[email protected]9b6db26f2011-04-11 04:27:4735 /**
36 * A NULL value. This is similar to undefined, but JavaScript differentiates
[email protected]c5495952011-06-30 22:57:1737 * the two so it is exposed here as well.
[email protected]9b6db26f2011-04-11 04:27:4738 */
[email protected]03f54582011-11-13 02:43:3339 PP_VARTYPE_NULL = 1,
[email protected]9b6db26f2011-04-11 04:27:4740 /**
[email protected]c5495952011-06-30 22:57:1741 * A boolean value, use the <code>as_bool</code> member of the var.
[email protected]9b6db26f2011-04-11 04:27:4742 */
[email protected]03f54582011-11-13 02:43:3343 PP_VARTYPE_BOOL = 2,
[email protected]9b6db26f2011-04-11 04:27:4744 /**
[email protected]c5495952011-06-30 22:57:1745 * A 32-bit integer value. Use the <code>as_int</code> member of the var.
[email protected]9b6db26f2011-04-11 04:27:4746 */
[email protected]03f54582011-11-13 02:43:3347 PP_VARTYPE_INT32 = 3,
[email protected]9b6db26f2011-04-11 04:27:4748 /**
[email protected]c5495952011-06-30 22:57:1749 * A double-precision floating point value. Use the <code>as_double</code>
50 * member of the var.
[email protected]9b6db26f2011-04-11 04:27:4751 */
[email protected]03f54582011-11-13 02:43:3352 PP_VARTYPE_DOUBLE = 4,
[email protected]9b6db26f2011-04-11 04:27:4753 /**
[email protected]c5495952011-06-30 22:57:1754 * The Var represents a string. The <code>as_id</code> field is used to
55 * identify the string, which may be created and retrieved from the
[email protected]35ac9412013-09-06 08:57:1956 * <code>PPB_Var</code> interface. These objects are reference counted, so
[email protected]56d75f22014-04-10 23:58:4157 * AddRef() and Release() must be used properly to avoid memory leaks.
[email protected]9b6db26f2011-04-11 04:27:4758 */
[email protected]03f54582011-11-13 02:43:3359 PP_VARTYPE_STRING = 5,
[email protected]9b6db26f2011-04-11 04:27:4760 /**
61 * Represents a JavaScript object. This vartype is not currently usable
[email protected]35ac9412013-09-06 08:57:1962 * from modules, although it is used internally for some tasks. These objects
[email protected]56d75f22014-04-10 23:58:4163 * are reference counted, so AddRef() and Release() must be used properly to
64 * avoid memory leaks.
[email protected]9b6db26f2011-04-11 04:27:4765 */
[email protected]03f54582011-11-13 02:43:3366 PP_VARTYPE_OBJECT = 6,
[email protected]9b6db26f2011-04-11 04:27:4767 /**
[email protected]35ac9412013-09-06 08:57:1968 * Represents an array of Vars. The <code>as_id</code> field is used to
69 * identify the array, which may be created and manipulated from the
70 * <code>PPB_VarArray</code> interface. These objects are reference counted,
[email protected]56d75f22014-04-10 23:58:4171 * so AddRef() and Release() must be used properly to avoid memory leaks.
[email protected]9b6db26f2011-04-11 04:27:4772 */
[email protected]03f54582011-11-13 02:43:3373 PP_VARTYPE_ARRAY = 7,
[email protected]35ac9412013-09-06 08:57:1974 /**
75 * Represents a mapping from strings to Vars. The <code>as_id</code> field is
76 * used to identify the dictionary, which may be created and manipulated from
77 * the <code>PPB_VarDictionary</code> interface. These objects are reference
[email protected]56d75f22014-04-10 23:58:4178 * counted, so AddRef() and Release() must be used properly to avoid memory
79 * leaks.
[email protected]35ac9412013-09-06 08:57:1980 */
[email protected]ddd61db2011-12-07 06:49:0081 PP_VARTYPE_DICTIONARY = 8,
82 /**
83 * ArrayBuffer represents a JavaScript ArrayBuffer. This is the type which
84 * represents Typed Arrays in JavaScript. Unlike JavaScript 'Array', it is
85 * only meant to contain basic numeric types, and is always stored
86 * contiguously. See PPB_VarArrayBuffer_Dev for functions special to
[email protected]56d75f22014-04-10 23:58:4187 * ArrayBuffer vars. These objects are reference counted, so AddRef() and
88 * Release() must be used properly to avoid memory leaks.
[email protected]ddd61db2011-12-07 06:49:0089 */
[email protected]424bf6b2013-09-12 11:11:2090 PP_VARTYPE_ARRAY_BUFFER = 9,
91 /**
[email protected]56d75f22014-04-10 23:58:4192 * This type allows the <code>PP_Var</code> to wrap a <code>PP_Resource
93 * </code>. This can be useful for sending or receiving some types of
94 * <code>PP_Resource</code> using <code>PPB_Messaging</code> or
95 * <code>PPP_Messaging</code>.
96 *
97 * These objects are reference counted, so AddRef() and Release() must be used
98 * properly to avoid memory leaks. Under normal circumstances, the
99 * <code>PP_Var</code> will implicitly hold a reference count on the
100 * <code>PP_Resource</code> on your behalf. For example, if you call
101 * VarFromResource(), it implicitly calls PPB_Core::AddRefResource() on the
102 * <code>PP_Resource</code>. Likewise, PPB_Var::Release() on a Resource
103 * <code>PP_Var</code> will invoke PPB_Core::ReleaseResource() when the Var
104 * reference count goes to zero.
[email protected]424bf6b2013-09-12 11:11:20105 */
106 PP_VARTYPE_RESOURCE = 10
[email protected]1758e882010-11-01 16:16:50107} PP_VarType;
[email protected]7631cf82010-11-10 21:36:06108PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VarType, 4);
[email protected]040d5e82011-01-28 15:38:38109/**
110 * @}
111 */
112
[email protected]b2b420d72011-07-12 00:59:31113/**
114 * @addtogroup Structs
115 * @{
116 */
[email protected]b2b420d72011-07-12 00:59:31117/**
118 * The PP_VarValue union stores the data for any one of the types listed
119 * in the PP_VarType enum.
120 */
121union PP_VarValue {
122 /**
123 * If <code>type</code> is <code>PP_VARTYPE_BOOL</code>,
124 * <code>as_bool</code> represents the value of this <code>PP_Var</code> as
125 * <code>PP_Bool</code>.
126 */
127 PP_Bool as_bool;
[email protected]b2b420d72011-07-12 00:59:31128 /**
129 * If <code>type</code> is <code>PP_VARTYPE_INT32</code>,
130 * <code>as_int</code> represents the value of this <code>PP_Var</code> as
131 * <code>int32_t</code>.
132 */
133 int32_t as_int;
[email protected]b2b420d72011-07-12 00:59:31134 /**
135 * If <code>type</code> is <code>PP_VARTYPE_DOUBLE</code>,
136 * <code>as_double</code> represents the value of this <code>PP_Var</code>
137 * as <code>double</code>.
138 */
139 double as_double;
[email protected]b2b420d72011-07-12 00:59:31140 /**
141 * If <code>type</code> is <code>PP_VARTYPE_STRING</code>,
[email protected]424bf6b2013-09-12 11:11:20142 * <code>PP_VARTYPE_OBJECT</code>, <code>PP_VARTYPE_ARRAY</code>,
143 * <code>PP_VARTYPE_DICTIONARY</code>, <code>PP_VARTYPE_ARRAY_BUFFER</code>,
144 * or <code>PP_VARTYPE_RESOURCE</code>, <code>as_id</code> represents the
145 * value of this <code>PP_Var</code> as an opaque handle assigned by the
146 * browser. This handle is guaranteed never to be 0, so a module can
147 * initialize this ID to 0 to indicate a "NULL handle."
[email protected]b2b420d72011-07-12 00:59:31148 */
149 int64_t as_id;
150};
[email protected]7631cf82010-11-10 21:36:06151
[email protected]1758e882010-11-01 16:16:50152/**
[email protected]c5495952011-06-30 22:57:17153 * The <code>PP_VAR</code> struct is a variant data type and can contain any
154 * value of one of the types named in the <code>PP_VarType</code> enum. This
155 * structure is for passing data between native code which can be strongly
156 * typed and the browser (JavaScript) which isn't strongly typed.
[email protected]1758e882010-11-01 16:16:50157 *
[email protected]6b91c40a2011-02-03 17:52:39158 * JavaScript has a "number" type for holding a number, and does not
159 * differentiate between floating point and integer numbers. The
160 * JavaScript operations will try to optimize operations by using
161 * integers when possible, but could end up with doubles. Therefore,
[email protected]c5495952011-06-30 22:57:17162 * you can't assume a numeric <code>PP_Var</code> will be the type you expect.
[email protected]6b91c40a2011-02-03 17:52:39163 * Your code should be capable of handling either int32_t or double for numeric
164 * PP_Vars sent from JavaScript.
[email protected]1758e882010-11-01 16:16:50165 */
166struct PP_Var {
167 PP_VarType type;
[email protected]c5495952011-06-30 22:57:17168 /**
169 * The <code>padding</code> ensures <code>value</code> is aligned on an
170 * 8-byte boundary relative to the start of the struct. Some compilers
171 * align doubles on 8-byte boundaries for 32-bit x86, and some align on
172 * 4-byte boundaries.
[email protected]1ad2a1db2010-12-13 20:04:31173 */
174 int32_t padding;
[email protected]c5495952011-06-30 22:57:17175 /**
176 * This <code>value</code> represents the contents of the PP_Var. Only one of
177 * the fields of <code>value</code> is valid at a time based upon
178 * <code>type</code>.
179 */
[email protected]b2b420d72011-07-12 00:59:31180 union PP_VarValue value;
[email protected]1758e882010-11-01 16:16:50181};
[email protected]1ad2a1db2010-12-13 20:04:31182PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_Var, 16);
[email protected]040d5e82011-01-28 15:38:38183/**
184 * @}
185 */
[email protected]1758e882010-11-01 16:16:50186
[email protected]040d5e82011-01-28 15:38:38187/**
188 * @addtogroup Functions
189 * @{
190 */
[email protected]6b91c40a2011-02-03 17:52:39191
192/**
[email protected]c5495952011-06-30 22:57:17193 * PP_MakeUndefined() is used to wrap an undefined value into a
194 * <code>PP_Var</code> struct for passing to the browser.
195 *
196 * @return A <code>PP_Var</code> structure.
[email protected]6b91c40a2011-02-03 17:52:39197 */
[email protected]e4a47422013-02-15 11:46:35198PP_INLINE struct PP_Var PP_MakeUndefined(void) {
[email protected]1ad2a1db2010-12-13 20:04:31199 struct PP_Var result = { PP_VARTYPE_UNDEFINED, 0, {PP_FALSE} };
[email protected]1758e882010-11-01 16:16:50200 return result;
201}
202
[email protected]6b91c40a2011-02-03 17:52:39203/**
[email protected]c5495952011-06-30 22:57:17204 * PP_MakeNull() is used to wrap a null value into a
205 * <code>PP_Var</code> struct for passing to the browser.
206 *
207 * @return A <code>PP_Var</code> structure,
[email protected]6b91c40a2011-02-03 17:52:39208 */
[email protected]e4a47422013-02-15 11:46:35209PP_INLINE struct PP_Var PP_MakeNull(void) {
[email protected]1ad2a1db2010-12-13 20:04:31210 struct PP_Var result = { PP_VARTYPE_NULL, 0, {PP_FALSE} };
[email protected]1758e882010-11-01 16:16:50211 return result;
212}
213
[email protected]6b91c40a2011-02-03 17:52:39214/**
[email protected]c5495952011-06-30 22:57:17215 * PP_MakeBool() is used to wrap a boolean value into a
216 * <code>PP_Var</code> struct for passing to the browser.
217 *
218 * @param[in] value A <code>PP_Bool</code> enumeration to
219 * wrap.
220 *
221 * @return A <code>PP_Var</code> structure.
[email protected]6b91c40a2011-02-03 17:52:39222 */
[email protected]6f2e3912010-11-05 14:45:44223PP_INLINE struct PP_Var PP_MakeBool(PP_Bool value) {
[email protected]1ad2a1db2010-12-13 20:04:31224 struct PP_Var result = { PP_VARTYPE_BOOL, 0, {PP_FALSE} };
[email protected]1758e882010-11-01 16:16:50225 result.value.as_bool = value;
226 return result;
227}
228
[email protected]6b91c40a2011-02-03 17:52:39229/**
[email protected]c5495952011-06-30 22:57:17230 * PP_MakeInt32() is used to wrap a 32 bit integer value
231 * into a <code>PP_Var</code> struct for passing to the browser.
232 *
233 * @param[in] value An int32 to wrap.
234 *
235 * @return A <code>PP_Var</code> structure.
[email protected]6b91c40a2011-02-03 17:52:39236 */
[email protected]6f2e3912010-11-05 14:45:44237PP_INLINE struct PP_Var PP_MakeInt32(int32_t value) {
[email protected]1ad2a1db2010-12-13 20:04:31238 struct PP_Var result = { PP_VARTYPE_INT32, 0, {PP_FALSE} };
[email protected]1758e882010-11-01 16:16:50239 result.value.as_int = value;
240 return result;
241}
242
[email protected]6b91c40a2011-02-03 17:52:39243/**
[email protected]c5495952011-06-30 22:57:17244 * PP_MakeDouble() is used to wrap a double value into a
245 * <code>PP_Var</code> struct for passing to the browser.
246 *
247 * @param[in] value A double to wrap.
248 *
249 * @return A <code>PP_Var</code> structure.
[email protected]6b91c40a2011-02-03 17:52:39250 */
[email protected]6f2e3912010-11-05 14:45:44251PP_INLINE struct PP_Var PP_MakeDouble(double value) {
[email protected]1ad2a1db2010-12-13 20:04:31252 struct PP_Var result = { PP_VARTYPE_DOUBLE, 0, {PP_FALSE} };
[email protected]1758e882010-11-01 16:16:50253 result.value.as_double = value;
254 return result;
255}
[email protected]1758e882010-11-01 16:16:50256/**
257 * @}
[email protected]1758e882010-11-01 16:16:50258 */
[email protected]040d5e82011-01-28 15:38:38259
[email protected]6ea69542010-12-20 18:15:59260#endif /* PPAPI_C_PP_VAR_H_ */
261