Back to index

lightning-sunbird  0.9+nobinonly
xpctest_attributes.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla Communicator client code, released
00017  * March 31, 1998.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 1998
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *   John Bandhauer <jband@netscape.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #include "xpctest_attributes.h"
00042 #include "nsISupports.h"
00043 #include "xpctest_private.h"
00044 
00045 #define NS_IXPCTESTOBJECTREADONLY_IID \
00046   {0x1364941e, 0x4462, 0x11d3, \
00047     { 0x82, 0xee, 0x00, 0x60, 0xb0, 0xeb, 0x59, 0x6f }}
00048 
00049 class xpcTestObjectReadOnly : public nsIXPCTestObjectReadOnly {
00050  public: 
00051   NS_DECL_ISUPPORTS
00052   NS_DECL_NSIXPCTESTOBJECTREADONLY
00053   xpcTestObjectReadOnly();
00054    
00055  private:
00056     PRBool  boolProperty;
00057     PRInt16 shortProperty;
00058     PRInt32 longProperty;
00059     float   floatProperty;
00060     char    charProperty;
00061     char    *stringID;
00062 };
00063 
00064 NS_IMPL_ISUPPORTS1(xpcTestObjectReadOnly, nsIXPCTestObjectReadOnly)
00065 
00066 xpcTestObjectReadOnly :: xpcTestObjectReadOnly() {
00067     NS_ADDREF_THIS();
00068 
00069     boolProperty = PR_TRUE;
00070     shortProperty = 32767;
00071     longProperty =  2147483647;
00072     charProperty = 'X';
00073 
00074     const char _id[] = "a68cc6a6-6552-11d3-82ef-0060b0eb596f";
00075     stringID = (char*) nsMemory::Clone(_id, sizeof(char)*(strlen(_id)+1));
00076 }
00077 
00078 NS_IMETHODIMP xpcTestObjectReadOnly :: GetID(char **_retval) {
00079     *_retval= (char*) nsMemory::Clone(stringID, 
00080                                          sizeof(char)*(strlen(stringID)+1));
00081     return *_retval? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00082 }
00083 
00084 NS_IMETHODIMP xpcTestObjectReadOnly :: GetStrReadOnly(char * *aStrReadOnly){
00085     char aString[] = "XPConnect Read-Only String";
00086 
00087     if(!aStrReadOnly)
00088         return NS_ERROR_NULL_POINTER;
00089     *aStrReadOnly = (char*) nsMemory::Clone(aStrReadOnly, 
00090                                                sizeof(char)*(strlen(aString)+1));
00091     return *aStrReadOnly ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00092 }
00093 
00094 NS_IMETHODIMP xpcTestObjectReadOnly :: GetBoolReadOnly(PRBool *aBoolReadOnly) {
00095     *aBoolReadOnly = boolProperty;
00096     return NS_OK;
00097 }
00098 NS_IMETHODIMP xpcTestObjectReadOnly :: GetShortReadOnly(PRInt16 *aShortReadOnly){
00099     *aShortReadOnly = shortProperty;
00100     return NS_OK;
00101 }
00102 NS_IMETHODIMP xpcTestObjectReadOnly :: GetLongReadOnly(PRInt32 *aLongReadOnly){
00103     *aLongReadOnly = longProperty;
00104     return NS_OK;
00105 }
00106 NS_IMETHODIMP xpcTestObjectReadOnly :: GetFloatReadOnly(float *aFloatReadOnly){
00107     *aFloatReadOnly = floatProperty;
00108     return NS_OK;
00109 }
00110 NS_IMETHODIMP xpcTestObjectReadOnly :: GetCharReadOnly(char *aCharReadOnly){
00111     *aCharReadOnly = charProperty;
00112     return NS_OK;
00113 }
00114 NS_IMETHODIMP
00115 xpctest::ConstructXPCTestObjectReadOnly(nsISupports *aOuter, REFNSIID aIID, void **aResult)
00116 {
00117     nsresult rv;
00118     NS_ASSERTION(aOuter == nsnull, "no aggregation");
00119     xpcTestObjectReadOnly *obj = new xpcTestObjectReadOnly();
00120 
00121     if(obj)
00122     {
00123         rv = obj->QueryInterface(aIID, aResult);
00124         NS_ASSERTION(NS_SUCCEEDED(rv), "unable to find correct interface");
00125         NS_RELEASE(obj);
00126     }
00127     else
00128     {
00129         *aResult = nsnull;
00130         rv = NS_ERROR_OUT_OF_MEMORY;
00131     }
00132 
00133     return rv;
00134 }
00135 /****************************************************************************/
00136 /* starting interface:    nsIXPCTestObjectReadWrite */
00137 /* {3b9b1d38-491a-11d3-82ef-0060b0eb596f} */
00138 /*
00139 
00140 #define NS_IXPCTESTOBJECTREADWRITE_IID_STR "3b9b1d38-491a-11d3-82ef-0060b0eb596f"
00141 */
00142 #define NS_IXPCTESTOBJECTREADWRITE_IID \
00143   {0x3b9b1d38, 0x491a, 0x11d3, \
00144     { 0x82, 0xef, 0x00, 0x60, 0xb0, 0xeb, 0x59, 0x6f }}
00145 
00146 class xpcTestObjectReadWrite : public nsIXPCTestObjectReadWrite {
00147   public: 
00148   NS_DECL_ISUPPORTS
00149   NS_DECL_NSIXPCTESTOBJECTREADWRITE
00150   
00151   xpcTestObjectReadWrite();
00152 
00153  private:
00154      PRBool boolProperty;
00155      PRInt16 shortProperty;
00156      PRInt32 longProperty;
00157      float floatProperty;
00158      char charProperty;
00159      const char *stringProperty;
00160 };
00161 
00162 NS_IMPL_ISUPPORTS1(xpcTestObjectReadWrite, nsIXPCTestObjectReadWrite)
00163 
00164 xpcTestObjectReadWrite :: xpcTestObjectReadWrite() {
00165     NS_ADDREF_THIS();
00166 
00167 
00168     boolProperty = PR_TRUE;
00169     shortProperty = 32767;
00170     longProperty =  2147483647;
00171     charProperty = 'X';
00172 
00173     const char s[] = "XPConnect Read-Writable String";
00174     stringProperty = (char*) nsMemory::Clone(s, 
00175                                                 sizeof(char)*(strlen(s)+1));
00176 }
00177 
00178 NS_IMETHODIMP xpcTestObjectReadWrite :: GetStringProperty(char * *aStringProperty) {
00179     if(!aStringProperty)
00180         return NS_ERROR_NULL_POINTER;
00181     *aStringProperty = (char*) nsMemory::Clone(stringProperty, 
00182                                                sizeof(char)*(strlen(stringProperty)+1));
00183     return *aStringProperty ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00184 
00185 }
00186 NS_IMETHODIMP xpcTestObjectReadWrite :: SetStringProperty(const char * aStringProperty) {
00187     stringProperty = aStringProperty;
00188     return NS_OK;
00189 }
00190 
00191 NS_IMETHODIMP xpcTestObjectReadWrite :: GetBooleanProperty(PRBool *aBooleanProperty) {
00192     *aBooleanProperty = boolProperty;
00193     return NS_OK;
00194 }
00195 NS_IMETHODIMP xpcTestObjectReadWrite :: SetBooleanProperty(PRBool aBooleanProperty) {
00196     boolProperty = aBooleanProperty;
00197     return NS_OK;
00198 }
00199 NS_IMETHODIMP xpcTestObjectReadWrite :: GetShortProperty(PRInt16 *aShortProperty) {
00200     *aShortProperty = shortProperty;
00201     return NS_OK;
00202 }
00203 NS_IMETHODIMP xpcTestObjectReadWrite :: SetShortProperty(PRInt16 aShortProperty) {
00204     shortProperty = aShortProperty;
00205     return NS_OK;
00206 }
00207 NS_IMETHODIMP xpcTestObjectReadWrite :: GetLongProperty(PRInt32 *aLongProperty) {
00208     *aLongProperty = longProperty;
00209     return NS_OK;
00210 }
00211 NS_IMETHODIMP xpcTestObjectReadWrite :: SetLongProperty(PRInt32 aLongProperty) {
00212     longProperty = aLongProperty;
00213     return NS_OK;
00214 }
00215 NS_IMETHODIMP xpcTestObjectReadWrite :: GetFloatProperty(float *aFloatProperty) {
00216     *aFloatProperty = floatProperty;
00217     return NS_OK;
00218 }
00219 NS_IMETHODIMP xpcTestObjectReadWrite :: SetFloatProperty(float aFloatProperty) {
00220     floatProperty = aFloatProperty;
00221     return NS_OK;
00222 }
00223 NS_IMETHODIMP xpcTestObjectReadWrite :: GetCharProperty(char *aCharProperty) {
00224     *aCharProperty = charProperty;
00225     return NS_OK;
00226 }
00227 NS_IMETHODIMP xpcTestObjectReadWrite :: SetCharProperty(char aCharProperty) {
00228     charProperty = aCharProperty;
00229     return NS_OK;
00230 }
00231 NS_IMETHODIMP
00232 xpctest::ConstructXPCTestObjectReadWrite(nsISupports *aOuter, REFNSIID aIID, void **aResult)
00233 {
00234     nsresult rv;
00235     NS_ASSERTION(aOuter == nsnull, "no aggregation");
00236     xpcTestObjectReadWrite *obj = new xpcTestObjectReadWrite();
00237 
00238     if(obj)
00239     {
00240         rv = obj->QueryInterface(aIID, aResult);
00241         NS_ASSERTION(NS_SUCCEEDED(rv), "unable to find correct interface");
00242         NS_RELEASE(obj);
00243     }
00244     else
00245     {
00246         *aResult = nsnull;
00247         rv = NS_ERROR_OUT_OF_MEMORY;
00248     }
00249     return rv;
00250 }
00251 
00252 
00253 /****************************************************************************/
00254 /*
00255 class xpcTestAttributes : public nsIXPCTestObjectReadWrite, 
00256     public nsIXPCTestObjectReadOnly
00257 {
00258 public: 
00259   NS_DECL_ISUPPORTS
00260   NS_DECL_NSIXPCTESTOBJECTREADONLY
00261   NS_DECL_NSIXPCTESTOBJECTREADWRITE
00262 
00263   NS_IMETHOD GetName(char * *aString);
00264   NS_IMETHOD SetName(char * aString );
00265 
00266 private:
00267     char *name;
00268 };
00269   
00270 NS_IMPL_ISUPPORTS2(xpcTestAttributes, nsIXPCTestObjectReadWrite, nsIXPCTestObjectReadOnly)
00271 
00272 NS_IMETHODIMP xpcTestAttributes ::GetName(char * *aString) {
00273     if(!aString)
00274         return NS_ERROR_NULL_POINTER;
00275     *aString = (char*) nsMemory::Clone(name, 
00276                 sizeof(char)*(strlen(name)+1));
00277     return *aString ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
00278 
00279 }
00280 NS_IMETHODIMP xpcTestAttributes ::SetName(char * aString) {
00281     name = aString;
00282     return NS_OK;
00283 }
00284 
00285 NS_IMETHODIMP
00286 xpctest::ConstructXPCTestAttributes(nsISupports *aOuter, REFNSIID aIID, void **aResult)
00287 {
00288     nsresult rv;
00289     NS_ASSERTION(aOuter == nsnull, "no aggregation");
00290     xpcTestAttributes *obj = new xpcTestAttributes();
00291 
00292     if(obj)
00293     {
00294         rv = obj->QueryInterface(aIID, aResult);
00295         NS_ASSERTION(NS_SUCCEEDED(rv), "unable to find correct interface");
00296         NS_RELEASE(obj);
00297     }
00298     else
00299     {
00300         *aResult = nsnull;
00301         rv = NS_ERROR_OUT_OF_MEMORY;
00302     }
00303     return rv;
00304 }
00305 */