Back to index

lightning-sunbird  0.9+nobinonly
XPCDispParams.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  * ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the IDispatch implementation for XPConnect.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * David Bradley.
00019  * Portions created by the Initial Developer are Copyright (C) 2002
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00043 #include "xpcprivate.h"
00044 
00045 XPCDispParams::XPCDispParams(PRUint32 args) : 
00046     mRefBuffer(mStackRefBuffer + sizeof(VARIANT)),
00047     mDispParamsAllocated(nsnull),
00048     mRefBufferAllocated(nsnull),
00049     mPropID(DISPID_PROPERTYPUT)
00050 #ifdef DEBUG
00051     ,mInserted(PR_FALSE)
00052 #endif
00053 {
00054     if(args >= DEFAULT_ARG_ARRAY_SIZE)
00055     {
00056         mRefBufferAllocated = new char[RefBufferSize(args)];
00057         mRefBuffer = mRefBufferAllocated + sizeof(VARIANT);
00058     }
00059     // Initialize the full buffer that was allocated
00060     memset(mRefBuffer - sizeof(VARIANT), 0, RefBufferSize(args));
00061     // Initialize the IDispatch parameters
00062     mDispParams.cArgs = args;
00063     if(args == 0)
00064         mDispParams.rgvarg = nsnull;
00065     else if (args <= DEFAULT_ARG_ARRAY_SIZE)
00066         mDispParams.rgvarg = mStackArgs + 1;
00067     else
00068     {
00069         mDispParamsAllocated = new VARIANT[args + 1];
00070         mDispParams.rgvarg =  mDispParamsAllocated + 1;
00071     }
00072     mDispParams.rgdispidNamedArgs = nsnull;
00073     mDispParams.cNamedArgs = 0;
00074 }
00075 
00076 
00077 XPCDispParams::~XPCDispParams()
00078 {
00079     // Cleanup the variants
00080     for(PRUint32 index = 0; index < mDispParams.cArgs; ++index)
00081         VariantClear(mDispParams.rgvarg + index);
00082     // Cleanup if we allocated the variant array. Remember that
00083     // our buffer may point one element into the allocate buffer
00084     delete [] mRefBufferAllocated;
00085     delete [] mDispParamsAllocated;
00086 }
00087 
00088 void XPCDispParams::InsertParam(_variant_t & var)
00089 {
00090 #ifdef DEBUG
00091     NS_ASSERTION(!mInserted, 
00092                  "XPCDispParams::InsertParam cannot be called more than once");
00093     mInserted = PR_TRUE;
00094 #endif
00095     // Bump the pointer back and increment the arg count
00096     --mDispParams.rgvarg;
00097     mRefBuffer -= sizeof(VARIANT);
00098     ++mDispParams.cArgs;
00099     // Assign the value
00100     mDispParams.rgvarg[0] = var.Detach();
00101     // initialize the ref buffer
00102     memset(mRefBuffer, 0, sizeof(VARIANT));
00103 }