michael@0: /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "xpctest_private.h" michael@0: michael@0: NS_IMPL_ISUPPORTS(xpcTestObjectReadOnly, nsIXPCTestObjectReadOnly) michael@0: michael@0: xpcTestObjectReadOnly :: xpcTestObjectReadOnly() { michael@0: boolProperty = true; michael@0: shortProperty = 32767; michael@0: longProperty = 2147483647; michael@0: floatProperty = 5.5f; michael@0: charProperty = 'X'; michael@0: // timeProperty is PRTime and signed type. michael@0: // So it has to allow negative value. michael@0: timeProperty = -1; michael@0: } michael@0: michael@0: NS_IMETHODIMP xpcTestObjectReadOnly :: GetStrReadOnly(char * *aStrReadOnly){ michael@0: char aString[] = "XPConnect Read-Only String"; michael@0: michael@0: if (!aStrReadOnly) michael@0: return NS_ERROR_NULL_POINTER; michael@0: *aStrReadOnly = (char*) nsMemory::Clone(aString, michael@0: sizeof(char)*(strlen(aString)+1)); michael@0: return *aStrReadOnly ? NS_OK : NS_ERROR_OUT_OF_MEMORY; michael@0: } michael@0: michael@0: NS_IMETHODIMP xpcTestObjectReadOnly :: GetBoolReadOnly(bool *aBoolReadOnly) { michael@0: *aBoolReadOnly = boolProperty; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadOnly :: GetShortReadOnly(int16_t *aShortReadOnly){ michael@0: *aShortReadOnly = shortProperty; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadOnly :: GetLongReadOnly(int32_t *aLongReadOnly){ michael@0: *aLongReadOnly = longProperty; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadOnly :: GetFloatReadOnly(float *aFloatReadOnly){ michael@0: *aFloatReadOnly = floatProperty; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadOnly :: GetCharReadOnly(char *aCharReadOnly){ michael@0: *aCharReadOnly = charProperty; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadOnly :: GetTimeReadOnly(PRTime *aTimeReadOnly){ michael@0: *aTimeReadOnly = timeProperty; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMPL_ISUPPORTS(xpcTestObjectReadWrite, nsIXPCTestObjectReadWrite) michael@0: michael@0: xpcTestObjectReadWrite :: xpcTestObjectReadWrite() { michael@0: const char s[] = "XPConnect Read-Writable String"; michael@0: stringProperty = (char*) nsMemory::Clone(s, sizeof(char)*(strlen(s)+1)); michael@0: boolProperty = true; michael@0: shortProperty = 32767; michael@0: longProperty = 2147483647; michael@0: floatProperty = 5.5f; michael@0: charProperty = 'X'; michael@0: // timeProperty is PRTime and signed type. michael@0: // So it has to allow negative value. michael@0: timeProperty = -1; michael@0: } michael@0: michael@0: xpcTestObjectReadWrite :: ~xpcTestObjectReadWrite() michael@0: { michael@0: nsMemory::Free(stringProperty); michael@0: } michael@0: michael@0: NS_IMETHODIMP xpcTestObjectReadWrite :: GetStringProperty(char * *aStringProperty) { michael@0: if (!aStringProperty) michael@0: return NS_ERROR_NULL_POINTER; michael@0: *aStringProperty = (char*) nsMemory::Clone(stringProperty, michael@0: sizeof(char)*(strlen(stringProperty)+1)); michael@0: return *aStringProperty ? NS_OK : NS_ERROR_OUT_OF_MEMORY; michael@0: michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadWrite :: SetStringProperty(const char * aStringProperty) { michael@0: nsMemory::Free(stringProperty); michael@0: stringProperty = (char*) nsMemory::Clone(aStringProperty, michael@0: sizeof(char)*(strlen(aStringProperty)+1)); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP xpcTestObjectReadWrite :: GetBooleanProperty(bool *aBooleanProperty) { michael@0: *aBooleanProperty = boolProperty; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadWrite :: SetBooleanProperty(bool aBooleanProperty) { michael@0: boolProperty = aBooleanProperty; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadWrite :: GetShortProperty(int16_t *aShortProperty) { michael@0: *aShortProperty = shortProperty; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadWrite :: SetShortProperty(int16_t aShortProperty) { michael@0: shortProperty = aShortProperty; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadWrite :: GetLongProperty(int32_t *aLongProperty) { michael@0: *aLongProperty = longProperty; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadWrite :: SetLongProperty(int32_t aLongProperty) { michael@0: longProperty = aLongProperty; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadWrite :: GetFloatProperty(float *aFloatProperty) { michael@0: *aFloatProperty = floatProperty; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadWrite :: SetFloatProperty(float aFloatProperty) { michael@0: floatProperty = aFloatProperty; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadWrite :: GetCharProperty(char *aCharProperty) { michael@0: *aCharProperty = charProperty; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadWrite :: SetCharProperty(char aCharProperty) { michael@0: charProperty = aCharProperty; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadWrite :: GetTimeProperty(PRTime *aTimeProperty) { michael@0: *aTimeProperty = timeProperty; michael@0: return NS_OK; michael@0: } michael@0: NS_IMETHODIMP xpcTestObjectReadWrite :: SetTimeProperty(PRTime aTimeProperty) { michael@0: timeProperty = aTimeProperty; michael@0: return NS_OK; michael@0: }