1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
---|
2 | /* ***** BEGIN LICENSE BLOCK ***** |
---|
3 | * Version: NPL 1.1/GPL 2.0/LGPL 2.1 |
---|
4 | * |
---|
5 | * The contents of this file are subject to the Netscape Public License |
---|
6 | * Version 1.1 (the "License"); you may not use this file except in |
---|
7 | * compliance with the License. You may obtain a copy of the License at |
---|
8 | * http://www.mozilla.org/NPL/ |
---|
9 | * |
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis, |
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
---|
12 | * for the specific language governing rights and limitations under the |
---|
13 | * License. |
---|
14 | * |
---|
15 | * The Original Code is mozilla.org code. |
---|
16 | * |
---|
17 | * The Initial Developer of the Original Code is |
---|
18 | * Netscape Communications Corporation. |
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998 |
---|
20 | * the Initial Developer. All Rights Reserved. |
---|
21 | * |
---|
22 | * Contributor(s): |
---|
23 | * |
---|
24 | * Alternatively, the contents of this file may be used under the terms of |
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead |
---|
28 | * of those above. If you wish to allow use of your version of this file only |
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to |
---|
30 | * use your version of this file under the terms of the NPL, indicate your |
---|
31 | * decision by deleting the provisions above and replace them with the notice |
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete |
---|
33 | * the provisions above, a recipient may use your version of this file under |
---|
34 | * the terms of any one of the NPL, the GPL or the LGPL. |
---|
35 | * |
---|
36 | * ***** END LICENSE BLOCK ***** */ |
---|
37 | |
---|
38 | /** |
---|
39 | * A sample of XPConnect. This file is the header of an implementation |
---|
40 | * nsSample of the nsISample interface. |
---|
41 | * |
---|
42 | */ |
---|
43 | |
---|
44 | #include "nsISample.h" |
---|
45 | |
---|
46 | /** |
---|
47 | * SampleImpl is an implementation of the nsISample interface. In XPCOM, |
---|
48 | * there can be more than one implementation of an given interface. Class |
---|
49 | * IDs (CIDs) uniquely identify a particular implementation of an interface. |
---|
50 | * Interface IDs (IIDs) uniquely identify an interface. |
---|
51 | * |
---|
52 | * The CID is also a unique number that looks just like an IID |
---|
53 | * and uniquely identifies an implementation |
---|
54 | * {7CB5B7A0-07D7-11d3-BDE2-000064657374} |
---|
55 | */ |
---|
56 | |
---|
57 | #define NS_SAMPLE_CID \ |
---|
58 | { 0x7cb5b7a0, 0x7d7, 0x11d3, { 0xbd, 0xe2, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } } |
---|
59 | |
---|
60 | #define NS_SAMPLE_CONTRACTID "@mozilla.org/sample;1" |
---|
61 | |
---|
62 | |
---|
63 | class nsSampleImpl : public nsISample |
---|
64 | { |
---|
65 | public: |
---|
66 | nsSampleImpl(); |
---|
67 | |
---|
68 | /** |
---|
69 | * This macro expands into a declaration of the nsISupports interface. |
---|
70 | * Every XPCOM component needs to implement nsISupports, as it acts |
---|
71 | * as the gateway to other interfaces this component implements. You |
---|
72 | * could manually declare QueryInterface, AddRef, and Release instead |
---|
73 | * of using this macro, but why? |
---|
74 | */ |
---|
75 | // nsISupports interface |
---|
76 | NS_DECL_ISUPPORTS |
---|
77 | |
---|
78 | /** |
---|
79 | * This macro is defined in the nsISample.h file, and is generated |
---|
80 | * automatically by the xpidl compiler. It expands to |
---|
81 | * declarations of all of the methods required to implement the |
---|
82 | * interface. xpidl will generate a NS_DECL_[INTERFACENAME] macro |
---|
83 | * for each interface that it processes. |
---|
84 | * |
---|
85 | * The methods of nsISample are discussed individually below, but |
---|
86 | * commented out (because this macro already defines them.) |
---|
87 | */ |
---|
88 | NS_DECL_NSISAMPLE |
---|
89 | |
---|
90 | /** |
---|
91 | * The following is an explanation of how the interface header |
---|
92 | * file expands to for a c++ implementation. NS_DELC_NSISAMPLE |
---|
93 | * takes care of defining the right c++ implementation. |
---|
94 | * |
---|
95 | * The following if provided for more understanding. |
---|
96 | * |
---|
97 | * NS_IMETHOD expands to the standard XPCOM return type. XPCOM methods |
---|
98 | * should never return any other type. The return value is used |
---|
99 | * behind the scenes by the XPConnect runtime to figure out if the call |
---|
100 | * failed in any way. |
---|
101 | * These methods were generated by "attribute string Value" in |
---|
102 | * nsISample.idl. When reflected into JavaScript, XPCOM will use these |
---|
103 | * calls as Getter/Setter ops, so that they can be called transparently |
---|
104 | * as "sample.Value='foo';" and "var val = sample.Value" |
---|
105 | */ |
---|
106 | /* NS_IMETHOD GetValue(char * *aValue); */ |
---|
107 | /* NS_IMETHOD SetValue(char * aValue); */ |
---|
108 | |
---|
109 | /** |
---|
110 | * The const came from the "in" specifier in nsISample.idl. "in" |
---|
111 | * specifies that the value of this parameter is used only for input, |
---|
112 | * this method is not allowed to modify the contents of the buffer. |
---|
113 | */ |
---|
114 | /* NS_IMETHOD WriteValue(const char *aPrefix); */ |
---|
115 | |
---|
116 | /** |
---|
117 | * nsISample.idl specifies all of it's string types as string, instead |
---|
118 | * of wstring (wide string), the Unicode type. If the world were a |
---|
119 | * perfect place, all normal strings in XPCOM interfaces would be unicode. |
---|
120 | * If this type had been specified as wstring, it would appear as |
---|
121 | * PRUnichar * in C++, which is the NSPR type for unicode characters. |
---|
122 | */ |
---|
123 | /* NS_IMETHOD Poke(const char* aValue); */ |
---|
124 | |
---|
125 | private: |
---|
126 | ~nsSampleImpl(); |
---|
127 | |
---|
128 | char* mValue; |
---|
129 | }; |
---|