sbClassInfoUtils.h
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25  */
26 
27 
28 #ifndef __SB_CLASSINFO_UTILS_H__
29 #define __SB_CLASSINFO_UTILS_H__
30 
31 #include <nsComponentManagerUtils.h>
32 #include <nsIClassInfoImpl.h>
33 #include <nsIProgrammingLanguage.h>
34 #include <nsMemory.h>
35 #include <nsStringGlue.h>
36 
37 
38 #define SB_IMPL_CLASSINFO( _class, \
39  _contractID, \
40  _description, \
41  _language, \
42  _flags, \
43  _classID ) \
44  \
45 NS_IMETHODIMP \
46 _class::GetInterfaces( PRUint32 *aCount, nsIID ***aArray ) \
47 { \
48  NS_ENSURE_ARG_POINTER(aCount); \
49  NS_ENSURE_ARG_POINTER(aArray); \
50  return NS_CI_INTERFACE_GETTER_NAME(_class)( aCount, aArray ); \
51 } \
52 NS_IMETHODIMP \
53 _class::GetHelperForLanguage( PRUint32 language, nsISupports **_retval ) \
54 { \
55  *_retval = nsnull; \
56  return NS_OK; \
57 } \
58 NS_IMETHODIMP \
59 _class::GetContractID( char **aContractID ) \
60 { \
61  if ( _contractID ) { \
62  *aContractID = ToNewCString( NS_LITERAL_CSTRING(_contractID) ); \
63  return *aContractID ? NS_OK : NS_ERROR_OUT_OF_MEMORY; \
64  } \
65  return NS_OK; \
66 } \
67 NS_IMETHODIMP \
68 _class::GetClassDescription( char **aClassDescription ) \
69 { \
70  *aClassDescription = ToNewCString( NS_LITERAL_CSTRING(_description) ); \
71  return *aClassDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY; \
72 } \
73 NS_IMETHODIMP \
74 _class::GetClassID( nsCID **aClassID ) \
75 { \
76  *aClassID = (nsCID*) nsMemory::Alloc( sizeof(nsCID) ); \
77  return *aClassID ? GetClassIDNoAlloc(*aClassID) : NS_ERROR_OUT_OF_MEMORY; \
78 } \
79 NS_IMETHODIMP \
80 _class::GetImplementationLanguage( PRUint32 *aImplementationLanguage ) \
81 { \
82  *aImplementationLanguage = _language; \
83  return NS_OK; \
84 } \
85 NS_IMETHODIMP \
86 _class::GetFlags( PRUint32 *aFlags ) \
87 { \
88  *aFlags = _flags; \
89  return NS_OK; \
90 } \
91 NS_IMETHODIMP \
92 _class::GetClassIDNoAlloc( nsCID *aClassIDNoAlloc ) \
93 { \
94  *aClassIDNoAlloc = _classID; \
95  return NS_OK; \
96 }
97 
98 
99 #define SB_IMPL_CLASSINFO_INTERFACES_ONLY(_class) \
100 NS_IMETHODIMP \
101 _class::GetInterfaces(PRUint32 *aCount, nsIID ***aArray) \
102 { \
103  NS_ENSURE_ARG_POINTER(aCount); \
104  NS_ENSURE_ARG_POINTER(aArray); \
105  return NS_CI_INTERFACE_GETTER_NAME(_class)(aCount, aArray); \
106 } \
107 NS_IMETHODIMP \
108 _class::GetHelperForLanguage(PRUint32 language, nsISupports **_retval) \
109 { \
110  *_retval = nsnull; \
111  return NS_OK; \
112 } \
113 NS_IMETHODIMP \
114 _class::GetContractID(char **aContractID) \
115 { \
116  *aContractID = nsnull; \
117  return NS_OK; \
118 } \
119 NS_IMETHODIMP \
120 _class::GetClassDescription(char **aClassDescription) \
121 { \
122  *aClassDescription = nsnull; \
123  return NS_OK; \
124 } \
125 NS_IMETHODIMP \
126 _class::GetClassID(nsCID **aClassID) \
127 { \
128  *aClassID = nsnull; \
129  return NS_OK; \
130 } \
131 NS_IMETHODIMP \
132 _class::GetImplementationLanguage(PRUint32 *aImplementationLanguage) \
133 { \
134  *aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS; \
135  return NS_OK; \
136 } \
137 NS_IMETHODIMP \
138 _class::GetFlags(PRUint32 *aFlags) \
139 { \
140  *aFlags = 0; \
141  return NS_OK; \
142 } \
143 NS_IMETHODIMP \
144 _class::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) \
145 { \
146  return NS_ERROR_NOT_AVAILABLE; \
147 }
148 
149 #endif // __SB_CLASSINFO_UTILS_H__