Back to index

lightning-sunbird  0.9+nobinonly
XPCDispPrivate.h
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 
00038 #ifndef XPCDispPrivate_h__
00039 #define XPCDispPrivate_h__
00040 
00046 #ifndef xpcprivate_h___
00047 #error "DispPrivate.h should not be included directly, please use XPCPrivate.h"
00048 #endif
00049 
00053 #include <atlbase.h>
00057 #include <comdef.h>
00061 #include "objsafe.h"
00062 
00063 // MS clutters the global namespace with so many macro names :-(
00064 // I tried to keep these includes in the CPP's but it became too
00065 // convoluted
00066 #undef GetClassInfo
00067 #undef GetClassName
00068 #undef GetMessage
00069 
00070 // We need IDispatch
00071 #include "nsIDispatchSupport.h"
00072 
00073 // The following are macro helpers pulled from XPCOM but tailored to COM
00074 #define NS_DECL_IUNKNOWN                                                      \
00075 public:                                                                       \
00076   STDMETHOD(QueryInterface)(REFIID aIID,                                      \
00077                             void** aInstancePtr);                             \
00078   STDMETHODIMP_(ULONG) AddRef(void);                                          \
00079   STDMETHODIMP_(ULONG) Release(void);                                         \
00080 protected:                                                                    \
00081   ULONG mRefCnt;                                                       
00082 
00083 #define NS_IMPL_COM_QUERY_HEAD(_class)                                        \
00084 STDMETHODIMP _class::QueryInterface(REFIID aIID, void** aInstancePtr)         \
00085 {                                                                             \
00086   NS_ASSERTION(aInstancePtr,                                                  \
00087                "QueryInterface requires a non-NULL destination!");            \
00088   if( !aInstancePtr )                                                         \
00089     return E_POINTER;                                                         \
00090   IUnknown* foundInterface;
00091 
00092 #define NS_IMPL_COM_QUERY_BODY(_interface)                                    \
00093   if(IsEqualIID(aIID, __uuidof(_interface)) )                                 \
00094     foundInterface = NS_STATIC_CAST(_interface*, this);                       \
00095   else
00096 
00097 #define NS_IMPL_COM_QUERY_TAIL_GUTS                                           \
00098     foundInterface = 0;                                                       \
00099   HRESULT status;                                                             \
00100   if( !foundInterface )                                                       \
00101     status = E_NOINTERFACE;                                                   \
00102   else                                                                        \
00103     {                                                                         \
00104       NS_ADDREF(foundInterface);                                              \
00105       status = S_OK;                                                          \
00106     }                                                                         \
00107   *aInstancePtr = foundInterface;                                             \
00108   return status;                                                              \
00109 }
00110 
00111 #define NS_COM_MAP_BEGIN(_implClass)      NS_IMPL_COM_QUERY_HEAD(_implClass)
00112 #define NS_COM_MAP_ENTRY(_interface)      NS_IMPL_COM_QUERY_BODY(_interface)
00113 #define NS_COM_MAP_END                    NS_IMPL_COM_QUERY_TAIL_GUTS
00114 
00115 #define NS_COM_IMPL_ADDREF(_class)                                            \
00116 STDMETHODIMP_(ULONG) _class::AddRef(void)                                     \
00117 {                                                                             \
00118   NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");                   \
00119   NS_ASSERT_OWNINGTHREAD(_class);                                             \
00120   ++mRefCnt;                                                                  \
00121   NS_LOG_ADDREF(this, mRefCnt, #_class, sizeof(*this));                       \
00122   return mRefCnt;                                                             \
00123 }
00124 
00125 #define NS_COM_IMPL_RELEASE(_class)                                           \
00126 STDMETHODIMP_(ULONG) _class::Release(void)                                    \
00127 {                                                                             \
00128   NS_PRECONDITION(0 != mRefCnt, "dup release");                               \
00129   NS_ASSERT_OWNINGTHREAD(_class);                                             \
00130   --mRefCnt;                                                                  \
00131   NS_LOG_RELEASE(this, mRefCnt, #_class);                                     \
00132   if(mRefCnt == 0) {                                                         \
00133     mRefCnt = 1; /* stabilize */                                              \
00134     delete this;                                                              \
00135     return 0;                                                                 \
00136   }                                                                           \
00137   return mRefCnt;                                                             \
00138 }
00139 
00140 extern const nsID NSID_IDISPATCH;
00141 
00147 class XPCDispConvert
00148 {
00149 public:
00156     static
00157     VARTYPE JSTypeToCOMType(XPCCallContext& ccx, jsval val);
00158 
00167     static
00168     JSBool JSToCOM(XPCCallContext& ccx, jsval src, VARIANT & dest, 
00169                    nsresult& err, JSBool isByRef = JS_FALSE);
00170 
00179     static
00180     JSBool COMToJS(XPCCallContext& ccx, const VARIANT & src, jsval & dest,
00181                    nsresult& err);
00182 private:
00191     static
00192     JSBool JSArrayToCOMArray(XPCCallContext& ccx, JSObject *obj, VARIANT & var,
00193                           nsresult& err);
00202     static
00203     JSBool COMArrayToJSArray(XPCCallContext& ccx, const VARIANT & src,
00204                              jsval & dest, nsresult& err);
00205 };
00206 
00216 JSBool JS_DLL_CALLBACK
00217 XPC_IDispatch_CallMethod(JSContext *cx, JSObject *obj, uintN argc,
00218                          jsval *argv, jsval *vp);
00228 JSBool JS_DLL_CALLBACK
00229 XPC_IDispatch_GetterSetter(JSContext *cx, JSObject *obj, uintN argc, 
00230                            jsval *argv, jsval *vp);
00231 
00237 class XPCDispNameArray
00238 {
00239 public:
00243     XPCDispNameArray();
00247     ~XPCDispNameArray();
00252     void SetSize(PRUint32 size);
00257     PRUint32 GetSize() const;
00264     void SetName(DISPID dispid, nsAString const & name);
00270     const nsAString&  GetName(DISPID dispid) const;
00276     DISPID Find(const nsAString &target) const;
00277 private:
00282     static const nsString sEmpty;
00283     PRUint32 mCount;
00284     nsString* mNames;
00285 };
00286 
00291 class XPCDispIDArray
00292 {
00293 public:
00299     XPCDispIDArray(XPCCallContext& ccx, JSIdArray* array);
00304     PRUint32 Length() const;
00311     jsval Item(JSContext* cx, PRUint32 index) const;
00312 
00316     void Mark();
00320     void Unmark();
00324     JSBool IsMarked() const;
00325 
00329     inline void MarkBeforeJSFinalize(JSContext*);
00330 private:
00331     JSBool mMarked;
00332     nsVoidArray mIDArray;
00333 };
00334 
00338 class XPCDispTypeInfo : public ITypeInfo
00339 {
00340     NS_DECL_IUNKNOWN
00341 public:
00345     class FuncDescArray
00346     {
00347     public:
00351         FuncDescArray(XPCCallContext& ccx, JSObject* obj, 
00352                       const XPCDispIDArray& array, XPCDispNameArray & names);
00356         ~FuncDescArray();
00362         FUNCDESC* Get(PRUint32 index);
00369         void Release(FUNCDESC *);
00374         PRUint32 Length() const;
00375     private:
00376         nsVoidArray      mArray;
00383         PRBool BuildFuncDesc(XPCCallContext& ccx, JSObject* obj,
00384                            XPCDispJSPropertyInfo & propInfo);
00385     };
00390     static
00391     XPCDispTypeInfo* New(XPCCallContext& ccx, JSObject* obj);
00392     virtual ~XPCDispTypeInfo();
00393     // ITypeInfo methods, see MSDN for detail information
00394     STDMETHOD(GetTypeAttr)( 
00395         /* [out] */ TYPEATTR __RPC_FAR *__RPC_FAR *ppTypeAttr);
00396     
00397     STDMETHOD(GetTypeComp)(
00398         /* [out] */ ITypeComp __RPC_FAR *__RPC_FAR *ppTComp);
00399     
00400     STDMETHOD(GetFuncDesc)( 
00401         /* [in] */ UINT index,
00402         /* [out] */ FUNCDESC __RPC_FAR *__RPC_FAR *ppFuncDesc);
00403     
00404     STDMETHOD(GetVarDesc)( 
00405         /* [in] */ UINT index,
00406         /* [out] */ VARDESC __RPC_FAR *__RPC_FAR *ppVarDesc);
00407     
00408     STDMETHOD(GetNames)( 
00409         /* [in] */ MEMBERID memid,
00410         /* [length_is][size_is][out] */ BSTR __RPC_FAR *rgBstrNames,
00411         /* [in] */ UINT cMaxNames,
00412         /* [out] */ UINT __RPC_FAR *pcNames);
00413     
00414     STDMETHOD(GetRefTypeOfImplType)( 
00415         /* [in] */ UINT index,
00416         /* [out] */ HREFTYPE __RPC_FAR *pRefType);
00417     
00418     STDMETHOD(GetImplTypeFlags)( 
00419         /* [in] */ UINT index,
00420         /* [out] */ INT __RPC_FAR *pImplTypeFlags);
00421     
00422     STDMETHOD(GetIDsOfNames)( 
00423         /* [size_is][in] */ LPOLESTR __RPC_FAR *rgszNames,
00424         /* [in] */ UINT cNames,
00425         /* [size_is][out] */ MEMBERID __RPC_FAR *pMemId);
00426     
00427     STDMETHOD(Invoke)( 
00428         /* [in] */ PVOID pvInstance,
00429         /* [in] */ MEMBERID memid,
00430         /* [in] */ WORD wFlags,
00431         /* [out][in] */ DISPPARAMS __RPC_FAR *pDispParams,
00432         /* [out] */ VARIANT __RPC_FAR *pVarResult,
00433         /* [out] */ EXCEPINFO __RPC_FAR *pExcepInfo,
00434         /* [out] */ UINT __RPC_FAR *puArgErr);
00435     
00436     STDMETHOD(GetDocumentation)( 
00437         /* [in] */ MEMBERID memid,
00438         /* [out] */ BSTR __RPC_FAR *pBstrName,
00439         /* [out] */ BSTR __RPC_FAR *pBstrDocString,
00440         /* [out] */ DWORD __RPC_FAR *pdwHelpContext,
00441         /* [out] */ BSTR __RPC_FAR *pBstrHelpFile);
00442     
00443     STDMETHOD(GetDllEntry)( 
00444         /* [in] */ MEMBERID memid,
00445         /* [in] */ INVOKEKIND invKind,
00446         /* [out] */ BSTR __RPC_FAR *pBstrDllName,
00447         /* [out] */ BSTR __RPC_FAR *pBstrName,
00448         /* [out] */ WORD __RPC_FAR *pwOrdinal);
00449     
00450     STDMETHOD(GetRefTypeInfo)( 
00451         /* [in] */ HREFTYPE hRefType,
00452         /* [out] */ ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo);
00453     
00454     STDMETHOD(AddressOfMember)( 
00455         /* [in] */ MEMBERID memid,
00456         /* [in] */ INVOKEKIND invKind,
00457         /* [out] */ PVOID __RPC_FAR *ppv);
00458     
00459     STDMETHOD(CreateInstance)( 
00460         /* [in] */ IUnknown __RPC_FAR *pUnkOuter,
00461         /* [in] */ REFIID riid,
00462         /* [iid_is][out] */ PVOID __RPC_FAR *ppvObj);
00463     
00464     STDMETHOD(GetMops)( 
00465         /* [in] */ MEMBERID memid,
00466         /* [out] */ BSTR __RPC_FAR *pBstrMops);
00467     
00468     STDMETHOD(GetContainingTypeLib)( 
00469         /* [out] */ ITypeLib __RPC_FAR *__RPC_FAR *ppTLib,
00470         /* [out] */ UINT __RPC_FAR *pIndex);
00471     
00472     virtual /* [local] */ void STDMETHODCALLTYPE ReleaseTypeAttr( 
00473         /* [in] */ TYPEATTR __RPC_FAR *pTypeAttr);
00474     
00475     virtual /* [local] */ void STDMETHODCALLTYPE ReleaseFuncDesc( 
00476         /* [in] */ FUNCDESC __RPC_FAR *pFuncDesc);
00477     
00478     virtual /* [local] */ void STDMETHODCALLTYPE ReleaseVarDesc( 
00479         /* [in] */ VARDESC __RPC_FAR *pVarDesc);
00485     const nsAString& GetNameForDispID(DISPID dispID);
00486 private:
00493     XPCDispTypeInfo(XPCCallContext& ccx, JSObject* obj, XPCDispIDArray* array);
00494     JSObject*               mJSObject;
00495     XPCDispIDArray*         mIDArray;
00496     XPCDispNameArray        mNameArray;
00497     // mFuncDescArray must occur after
00498     // TODO: We should probably refactor this so this isn't a requirement
00499     FuncDescArray        mFuncDescArray;
00500 };
00501 
00505 class XPCDispJSPropertyInfo
00506 {
00507 public:
00515     XPCDispJSPropertyInfo(JSContext*cx, PRUint32 memid, JSObject* obj, jsval val);
00520     PRBool Valid() const;
00526     PRUint32 GetParamCount() const;
00532     PRUint32 GetMemID() const;
00537     INVOKEKIND GetInvokeKind() const;
00543     void GetReturnType(XPCCallContext& ccx, ELEMDESC & elemDesc);
00549     ELEMDESC * GetParamInfo();
00554     PRBool IsProperty() const;
00559     PRBool IsReadOnly() const;
00564     PRBool IsSetter() const;
00568     void SetSetter();
00573     nsAString const & GetName() const;
00574 private:
00575     enum property_type
00576     {
00577         INVALID,
00578         PROPERTY,
00579         READONLY_PROPERTY,
00580         FUNCTION,
00581         SETTER_MODE = 0x20
00582     };
00583 
00584     PRUint32        mPropertyType;
00585     PRUint32        mParamCount;
00586     PRUint32        mMemID;
00587     jsval           mProperty;
00588     nsString        mName;
00589 
00594     inline
00595     property_type PropertyType() const;
00596 };
00597 
00601 class XPCDispatchTearOff : public IDispatch, public ISupportErrorInfo
00602 {
00603 public:
00607     XPCDispatchTearOff(nsIXPConnectWrappedJS * wrappedJS);
00611     virtual ~XPCDispatchTearOff();
00616     STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
00620     STDMETHODIMP_(ULONG) AddRef();
00624     STDMETHODIMP_(ULONG) Release();
00633     STDMETHOD(QueryInterface)(REFIID IID,void ** pPtr);
00640     STDMETHOD(GetTypeInfoCount)(unsigned int * pctinfo);
00646     STDMETHOD(GetTypeInfo)(unsigned int iTInfo, LCID lcid, 
00647                            ITypeInfo FAR* FAR* ppTInfo);
00653     STDMETHOD(GetIDsOfNames)(REFIID riid, OLECHAR FAR* FAR* rgszNames, 
00654                              unsigned int cNames, LCID  lcid, 
00655                              DISPID FAR* rgDispId);
00661     STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
00662                       DISPPARAMS FAR* pDispParams, VARIANT FAR* pVarResult, 
00663                       EXCEPINFO FAR* pExcepInfo, unsigned int FAR* puArgErr);
00664 
00665 private:
00666     // Pointer back to our main object
00667     nsCOMPtr<nsIXPConnectWrappedJS> mWrappedJS;
00668     // The Type information for our instance
00669     XPCDispTypeInfo *                 mCOMTypeInfo;
00670     // Reference count
00671     ULONG                             mRefCnt;
00672     // Returns the type information
00673     XPCDispTypeInfo *                 GetCOMTypeInfo();
00674     // Returns the JS Object being used to wrap
00675     inline
00676     JSObject* GetJSObject();
00677 
00678     NS_DECL_OWNINGTHREAD;
00679 };
00680 
00687 class XPCDispInterface
00688 {
00689 public:
00694     class Member
00695     {
00696     public:
00701         class ParamInfo
00702         {
00703         public:
00708             ParamInfo(const ELEMDESC * paramInfo);
00714             JSBool InitializeOutputParam(void * varBuffer, 
00715                                          VARIANT & var) const;
00721             PRBool IsFlagSet(unsigned short flag) const;
00726             PRBool IsIn() const;
00731             PRBool IsOut() const;
00736             PRBool IsOptional() const;
00741             PRBool IsRetVal() const;
00742             // TODO: Handle VT_ARRAY as well
00747             VARTYPE GetType() const;
00748         private:
00749             const ELEMDESC * mParamInfo;
00750         };
00751         Member();
00752         ~Member();
00758         void* operator new(size_t, Member* p) CPP_THROW_NEW;
00763         PRBool IsSetter() const;
00768         PRBool IsGetter() const;
00773         PRBool IsProperty() const;
00778         PRBool IsParameterizedSetter() const;
00783         PRBool IsParameterizedGetter() const;
00788         PRBool IsParameterizedProperty() const;
00793         PRBool IsFunction() const;
00798         jsval GetName() const;
00806         JSBool GetValue(XPCCallContext& ccx, XPCNativeInterface* iface, 
00807                         jsval * retval) const;
00812         PRUint32 GetDispID() const;
00818         PRUint32 GetParamCount(PRBool getter = PR_FALSE) const;
00825         ParamInfo GetParamInfo(PRUint32 index, PRBool getter = PR_FALSE) const;
00826         // === Setup functions ===
00831         void SetName(jsval name);
00836         void MakeGetter();
00840         void MakeSetter();
00845         void SetFunction();
00849         void ResetType();
00856         void SetTypeInfo(DISPID dispID, ITypeInfo* pTypeInfo,
00857                          FUNCDESC* funcdesc);
00862         void SetGetterFuncDesc(FUNCDESC* funcdesc);
00867         void SetMemID(DISPID memID);
00872         DISPID GetMemID() const;
00873 
00874     private:
00875        DISPID   mMemID;
00880         enum member_type
00881         {
00882             UNINITIALIZED = 0,
00883             SET_PROPERTY = 1,
00884             GET_PROPERTY = 2,
00885             FUNCTION = 4,
00886             RESOLVED = 8
00887         };
00888         PRUint16 mType;
00889         jsval mVal;     // Mutable
00890         jsval mName;    // Mutable
00891         CComPtr<ITypeInfo> mTypeInfo;
00892         FUNCDESC* mFuncDesc; // We own this
00893         FUNCDESC* mGetterFuncDesc; // We own this
00899         PRUint16 GetParamType(PRUint32 index) const;
00905         PRBool IsFlagSet(unsigned short flag) const;
00906     };
00912     JSObject* GetJSObject() const;
00918     void SetJSObject(JSObject* jsobj);
00924     const Member * FindMember(jsval name) const;
00932     const Member* FindMemberCI(XPCCallContext& ccx, jsval name) const;
00938     const Member & GetMember(PRUint32 index);
00943     PRUint32 GetMemberCount() const;
00950     static
00951     XPCDispInterface* NewInstance(JSContext* cx, nsISupports * pIface);
00956     void operator delete(void * p);
00960     ~XPCDispInterface();
00961 private:
00968     XPCDispInterface(JSContext* cx, 
00969                           ITypeInfo * pTypeInfo,
00970                           PRUint32 members);
00976     void * operator new (size_t, PRUint32 members) CPP_THROW_NEW;
00977 
00982     JSObject*   mJSObject;
00983     PRUint32    mMemberCount;
00984     Member      mMembers[1];
00993     PRBool InspectIDispatch(JSContext * cx, ITypeInfo * pTypeInfo, 
00994                           PRUint32 members);
00995 
01002     class Allocator
01003     {
01004     public:
01011         Allocator(JSContext * cx, ITypeInfo * pTypeInfo);
01015         inline
01016         ~Allocator();
01021         inline
01022         XPCDispInterface* Allocate();
01023     private:
01024         DISPID * mMemIDs;
01025         PRUint32 mCount;            // Total unique ID's found
01026         PRUint32 mIDispatchMembers; // Total entries reported by ITypeInfo
01027         JSContext* mCX;
01028         ITypeInfo* mTypeInfo;
01029 
01034         inline
01035         PRUint32 Count() const;
01040         void Add(DISPID memID);
01045         inline
01046         PRBool Valid() const;
01047 
01048         // No copying or assigning allowed
01049         Allocator(const Allocator&);
01050         Allocator& operator =(const Allocator&);
01051     };
01055     friend class Allocator;
01056 };
01057 
01063 class XPCDispObject
01064 {
01065 public:
01066     enum CallMode {CALL_METHOD, CALL_GETTER, CALL_SETTER};
01079     static
01080     JSBool Dispatch(XPCCallContext& ccx, IDispatch * pDisp,
01081                     DISPID dispID, CallMode mode, XPCDispParams * params,
01082                     jsval* retval, XPCDispInterface::Member* member = nsnull,
01083                     XPCJSRuntime* rt = nsnull);
01089     static
01090     JSBool Invoke(XPCCallContext & ccx, CallMode mode);
01099     static
01100     HRESULT SecurityCheck(XPCCallContext & ccx, const CLSID & aCID,
01101                           IDispatch ** createdObject = nsnull);
01112     static
01113     HRESULT COMCreateInstance(XPCCallContext & ccx, BSTR className,
01114                               PRBool enforceSecurity, IDispatch ** result);
01122     static
01123     PRBool WrapIDispatch(IDispatch *pDispatch, XPCCallContext & ccx,
01124                          JSObject *obj, jsval *rval);
01125 };
01126 
01127 class XPCIDispatchExtension
01128 {
01129 public:
01133     static void InitStatics() { mIsEnabled = PR_TRUE; }
01134 
01139     static PRBool IsEnabled() { return mIsEnabled; }
01143     static void Enable() { mIsEnabled = PR_TRUE; }
01147     static void Disable() { mIsEnabled = PR_FALSE; }
01154     static JSBool Initialize(JSContext * aJSContext,
01155                              JSObject* aGlobalJSObj);
01166     static JSBool DefineProperty(XPCCallContext & ccx, 
01167                                  JSObject *obj, jsval idval,
01168                                  XPCWrappedNative* wrapperToReflectInterfaceNames,
01169                                  uintN propFlags, JSBool* resolved);
01178     static JSBool Enumerate(XPCCallContext& ccx, JSObject* obj, 
01179                             XPCWrappedNative * wrapper);
01188     static nsresult IDispatchQIWrappedJS(nsXPCWrappedJS * self, 
01189                                          void ** aInstancePtr);
01190 
01191 private:
01192     static PRBool  mIsEnabled;
01193 };
01194 
01198 class XPCDispParams
01199 {
01200 public:
01205     XPCDispParams(PRUint32 args);
01209     ~XPCDispParams();
01214     void SetNamedPropID();
01220     VARIANT & GetParamRef(PRUint32 index);
01226     _variant_t GetParam(PRUint32 index) const;
01232     void * GetOutputBuffer(PRUint32 index);
01237     DISPPARAMS* GetDispParams() const { return &NS_CONST_CAST(XPCDispParams*,this)->mDispParams; }
01242     uintN GetParamCount() const { return mDispParams.cArgs; }
01248     void InsertParam(_variant_t & var);
01249 private:
01253     XPCDispParams(const XPCDispParams & other) {
01254         NS_ERROR("XPCDispParams can't be copied"); }
01258     XPCDispParams& operator =(const XPCDispParams&) {
01259         NS_ERROR("XPCDispParams can't be assigned"); }
01260 
01261     enum
01262     {
01263         DEFAULT_ARG_ARRAY_SIZE = 8,
01264         DEFAULT_REF_BUFFER_SIZE = 8 * sizeof(VARIANT)
01265     };
01266     static
01267     PRUint32 RefBufferSize(PRUint32 args) { return (args + 1) * sizeof(VARIANT); }
01268 
01269     DISPPARAMS  mDispParams;
01270     char*       mRefBuffer;
01271     VARIANT*    mDispParamsAllocated;
01272     char*       mRefBufferAllocated;
01276     char        mStackRefBuffer[DEFAULT_REF_BUFFER_SIZE];
01277     VARIANT     mStackArgs[DEFAULT_ARG_ARRAY_SIZE];
01278     DISPID      mPropID;
01279 #ifdef DEBUG
01280     PRBool mInserted;
01281 #endif
01282 };
01283 
01288 class XPCDispParamPropJSClass
01289 {
01290 public:
01303     static JSBool NewInstance(XPCCallContext& ccx, XPCWrappedNative* wrapper,
01304                                PRUint32 dispID,
01305                                XPCDispParams* dispParams,
01306                                jsval* paramPropObj);
01310     ~XPCDispParamPropJSClass();
01315     XPCWrappedNative*       GetWrapper() const { return mWrapper; }
01322     JSBool                  Invoke(XPCCallContext& ccx, 
01323                                    XPCDispObject::CallMode mode, 
01324                                    jsval* retval);
01329     XPCDispParams*    GetParams() const { return mDispParams; }
01330 private:
01338     XPCDispParamPropJSClass(XPCWrappedNative* wrapper, nsISupports* dispObj, 
01339                             PRUint32 dispID, XPCDispParams* dispParams);
01340 
01341     XPCWrappedNative*           mWrapper;
01342     PRUint32                    mDispID;
01343     XPCDispParams*              mDispParams;
01344     IDispatch*                  mDispObj;
01345 };
01346 
01351 class nsDispatchSupport : public nsIDispatchSupport
01352 {
01353 public:
01354     NS_DECL_ISUPPORTS
01355     NS_DECL_NSIDISPATCHSUPPORT
01359     nsDispatchSupport();
01363     virtual ~nsDispatchSupport();
01368     static nsDispatchSupport* GetSingleton();
01372     static void FreeSingleton() { NS_IF_RELEASE(mInstance); }
01373 
01374 private:
01375     static nsDispatchSupport* mInstance;
01376 };
01377 
01381 class XPCIDispatchClassInfo : public nsIClassInfo
01382 {
01383 public:
01388     static XPCIDispatchClassInfo* GetSingleton();
01392     static void FreeSingleton();
01393     NS_DECL_ISUPPORTS
01394     NS_DECL_NSICLASSINFO
01395 private:
01399     XPCIDispatchClassInfo() {}
01400     virtual ~XPCIDispatchClassInfo() {}
01401 
01402     static XPCIDispatchClassInfo*  sInstance;
01403 };
01404 
01405 #include "XPCDispInlines.h"
01406 
01407 #endif