1/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7/* The long avoided variant support for xpcom. */
8
9#include "nsISupports.idl"
10
11%{C++
12#include "xptinfo.h"
13
14// This enum class used to be a const-only XPIDL interface, containing literal
15// integer descriptions of the different fields. Instead, it now directly
16// references the nsXPTTypeTag variants VTYPE_ are intended to match.
17struct nsIDataType
18{
19    enum {
20        // These MUST match the declarations in xptinfo.h.
21        // Otherwise the world is likely to explode.
22        VTYPE_INT8              = TD_INT8             ,
23        VTYPE_INT16             = TD_INT16            ,
24        VTYPE_INT32             = TD_INT32            ,
25        VTYPE_INT64             = TD_INT64            ,
26        VTYPE_UINT8             = TD_UINT8            ,
27        VTYPE_UINT16            = TD_UINT16           ,
28        VTYPE_UINT32            = TD_UINT32           ,
29        VTYPE_UINT64            = TD_UINT64           ,
30        VTYPE_FLOAT             = TD_FLOAT            ,
31        VTYPE_DOUBLE            = TD_DOUBLE           ,
32        VTYPE_BOOL              = TD_BOOL             ,
33        VTYPE_CHAR              = TD_CHAR             ,
34        VTYPE_WCHAR             = TD_WCHAR            ,
35        VTYPE_VOID              = TD_VOID             ,
36        VTYPE_ID                = TD_NSIDPTR          ,
37        VTYPE_CHAR_STR          = TD_PSTRING          ,
38        VTYPE_WCHAR_STR         = TD_PWSTRING         ,
39        VTYPE_INTERFACE         = TD_INTERFACE_TYPE   ,
40        VTYPE_INTERFACE_IS      = TD_INTERFACE_IS_TYPE,
41        VTYPE_ARRAY             = TD_LEGACY_ARRAY     ,
42        VTYPE_STRING_SIZE_IS    = TD_PSTRING_SIZE_IS  ,
43        VTYPE_WSTRING_SIZE_IS   = TD_PWSTRING_SIZE_IS ,
44        VTYPE_UTF8STRING        = TD_UTF8STRING       ,
45        VTYPE_CSTRING           = TD_CSTRING          ,
46        VTYPE_ASTRING           = TD_ASTRING          ,
47
48        // Non-xpt variant types
49        VTYPE_EMPTY_ARRAY       = 254                 ,
50        VTYPE_EMPTY             = 255
51    };
52};
53%}
54
55
56/**
57 * XPConnect has magic to transparently convert between nsIVariant and JS types.
58 * We mark the interface [scriptable] so that JS can use methods
59 * that refer to this interface. But we mark all the methods and attributes
60 * [noscript] since any nsIVariant object will be automatically converted to a
61 * JS type anyway.
62 */
63
64[scriptable, builtinclass, uuid(81e4c2de-acac-4ad6-901a-b5fb1b851a0d)]
65interface nsIVariant : nsISupports
66{
67    [notxpcom,nostdcall] readonly attribute uint16_t     dataType;
68
69    [noscript] uint8_t      getAsInt8();
70    [noscript] int16_t      getAsInt16();
71    [noscript] int32_t      getAsInt32();
72    [noscript] int64_t      getAsInt64();
73    [noscript] uint8_t      getAsUint8();
74    [noscript] uint16_t     getAsUint16();
75    [noscript] uint32_t     getAsUint32();
76    [noscript] uint64_t     getAsUint64();
77    [noscript] float        getAsFloat();
78    [noscript] double       getAsDouble();
79    [noscript] boolean      getAsBool();
80    [noscript] char         getAsChar();
81    [noscript] wchar        getAsWChar();
82    [notxpcom] nsresult     getAsID(out nsID retval);
83    [noscript] AString      getAsAString();
84    [noscript] ACString     getAsACString();
85    [noscript] AUTF8String  getAsAUTF8String();
86    [noscript] string       getAsString();
87    [noscript] wstring      getAsWString();
88    [noscript] nsISupports  getAsISupports();
89    [noscript] jsval        getAsJSVal();
90
91    [noscript] void getAsInterface(out nsIIDPtr iid,
92                                   [iid_is(iid), retval] out nsQIResult iface);
93
94    [notxpcom] nsresult getAsArray(out uint16_t type, out nsIID iid,
95                                   out uint32_t count, out voidPtr ptr);
96
97    [noscript] void getAsStringWithSize(out uint32_t size,
98                                        [size_is(size), retval] out string str);
99
100    [noscript] void getAsWStringWithSize(out uint32_t size,
101                                         [size_is(size), retval] out wstring str);
102};
103
104/**
105 * An object that implements nsIVariant may or may NOT also implement this
106 * nsIWritableVariant.
107 *
108 * If the 'writable' attribute is false then attempts to call any of the 'set'
109 * methods can be expected to fail. Setting the 'writable' attribute may or
110 * may not succeed.
111 *
112 */
113
114[scriptable, builtinclass, uuid(5586a590-8c82-11d5-90f3-0010a4e73d9a)]
115interface nsIWritableVariant : nsIVariant
116{
117    attribute boolean writable;
118
119    void setAsInt8(in uint8_t aValue);
120    void setAsInt16(in int16_t aValue);
121    void setAsInt32(in int32_t aValue);
122    void setAsInt64(in int64_t aValue);
123    void setAsUint8(in uint8_t aValue);
124    void setAsUint16(in uint16_t aValue);
125    void setAsUint32(in uint32_t aValue);
126    void setAsUint64(in uint64_t aValue);
127    void setAsFloat(in float aValue);
128    void setAsDouble(in double aValue);
129    void setAsBool(in boolean aValue);
130    void setAsChar(in char aValue);
131    void setAsWChar(in wchar aValue);
132    void setAsID(in nsIDRef aValue);
133    void setAsAString(in AString aValue);
134    void setAsACString(in ACString aValue);
135    void setAsAUTF8String(in AUTF8String aValue);
136    void setAsString(in string aValue);
137    void setAsWString(in wstring aValue);
138    void setAsISupports(in nsISupports aValue);
139
140    void setAsInterface(in nsIIDRef iid,
141                        [iid_is(iid)] in nsQIResult iface);
142
143    [noscript] void setAsArray(in uint16_t type, in nsIIDPtr iid,
144                               in uint32_t count, in voidPtr ptr);
145
146    void setAsStringWithSize(in uint32_t size,
147                             [size_is(size)] in string str);
148
149    void setAsWStringWithSize(in uint32_t size,
150                              [size_is(size)] in wstring str);
151
152    void setAsVoid();
153    void setAsEmpty();
154    void setAsEmptyArray();
155
156    void setFromVariant(in nsIVariant aValue);
157};
158
159%{C++
160// The contractID for the generic implementation built in to xpcom.
161#define NS_VARIANT_CONTRACTID "@mozilla.org/variant;1"
162%}
163