Back to index

lightning-sunbird  0.9+nobinonly
nsProxyEventPrivate.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; 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 mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Pierre Phaneuf <pp@ludusdesign.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef __nsProxyEventPrivate_h_
00040 #define __nsProxyEventPrivate_h_
00041 
00042 #include "nscore.h"
00043 #include "nsISupports.h"
00044 #include "nsIFactory.h"
00045 #include "nsHashtable.h"
00046 
00047 #include "plevent.h"
00048 #include "xptcall.h"    // defines nsXPTCVariant
00049 #include "nsIEventQueue.h"
00050 
00051 #include "nsProxyEvent.h"
00052 #include "nsIProxyObjectManager.h"
00053 
00054 class nsProxyEventObject;
00055 class nsProxyEventClass;
00056 
00057 #define NS_PROXYEVENT_CLASS_IID                  \
00058 { 0xeea90d42,                                    \
00059   0xb059,                                        \
00060   0x11d2,                                        \
00061  {0x91, 0x5e, 0xc1, 0x2b, 0x69, 0x6c, 0x93, 0x33}\
00062 } 
00063 
00064 #define NS_PROXYEVENT_IDENTITY_CLASS_IID \
00065 { 0xeea90d45, 0xb059, 0x11d2,                       \
00066   { 0x91, 0x5e, 0xc1, 0x2b, 0x69, 0x6c, 0x93, 0x33 } }
00067 
00068 
00069 #define NS_PROXYEVENT_OBJECT_IID \
00070 { 0xec373590, 0x9164, 0x11d3,    \
00071 {0x8c, 0x73, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74} }
00072 
00073 
00074 class nsProxyEventClass : public nsISupports
00075 {
00076 public:
00077     NS_DECL_ISUPPORTS
00078     
00079     NS_DEFINE_STATIC_IID_ACCESSOR(NS_PROXYEVENT_CLASS_IID)
00080     static nsProxyEventClass* GetNewOrUsedClass(REFNSIID aIID);
00081     
00082     NS_IMETHOD DelegatedQueryInterface( nsProxyEventObject* self, 
00083                                         REFNSIID aIID, 
00084                                         void** aInstancePtr);
00085 
00086 
00087     nsIInterfaceInfo*        GetInterfaceInfo() const {return mInfo;}
00088     const nsIID&             GetProxiedIID()    const {return mIID; }
00089 protected:
00090     nsProxyEventClass();
00091     nsProxyEventClass(REFNSIID aIID, nsIInterfaceInfo* aInfo);
00092     
00093 private:
00094     ~nsProxyEventClass();
00095 
00096     nsIID                      mIID;
00097     nsCOMPtr<nsIInterfaceInfo> mInfo;
00098     uint32*                    mDescriptors;
00099 
00100     nsresult          CallQueryInterfaceOnProxy(nsProxyEventObject* self, 
00101                                                 REFNSIID aIID, 
00102                                                 nsProxyEventObject** aInstancePtr);
00103 };
00104 
00105 
00106 
00107 class nsProxyEventObject : public nsXPTCStubBase
00108 {
00109 public:
00110 
00111     NS_DECL_ISUPPORTS
00112 
00113     NS_DEFINE_STATIC_IID_ACCESSOR(NS_PROXYEVENT_OBJECT_IID)
00114     
00115     static nsProxyEventObject* GetNewOrUsedProxy(nsIEventQueue *destQueue,
00116                                                  PRInt32 proxyType,
00117                                                  nsISupports *aObj,
00118                                                  REFNSIID aIID);
00119     
00120     
00121     NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info);
00122 
00123     // call this method and return result
00124     NS_IMETHOD CallMethod(PRUint16 methodIndex, const nsXPTMethodInfo* info, nsXPTCMiniVariant* params);
00125 
00126 
00127     nsProxyEventClass*    GetClass()           const { return mClass; }
00128     nsIEventQueue*        GetQueue()           const { return (mProxyObject ? mProxyObject->GetQueue()     : nsnull);}
00129     nsISupports*          GetRealObject()      const { return (mProxyObject ? mProxyObject->GetRealObject(): nsnull);}
00130     PRInt32               GetProxyType()       const { return (mProxyObject ? mProxyObject->GetProxyType() : nsnull);} 
00131 
00132     nsProxyEventObject();
00133     nsProxyEventObject(nsIEventQueue *destQueue,
00134                        PRInt32 proxyType,
00135                        nsISupports* aObj,
00136                        nsProxyEventClass* aClass,
00137                        nsProxyEventObject* root,
00138                        nsIEventQueueService* eventQService);
00139     
00140     nsProxyEventObject*   LockedFind(REFNSIID aIID);
00141 
00142 #ifdef DEBUG_xpcom_proxy
00143     void DebugDump(const char * message, PRUint32 hashKey);
00144 #endif
00145 
00146 private:
00147     ~nsProxyEventObject();
00148 
00149 protected:
00150     void LockedRemoveProxy();
00151 
00152 protected:
00153     nsCOMPtr<nsProxyEventClass> mClass;
00154     nsRefPtr<nsProxyObject>     mProxyObject;
00155 
00156     // Owning reference...
00157     nsProxyEventObject *mRoot;
00158 
00159     // Weak reference...
00160     nsProxyEventObject *mNext;
00161 };
00162 
00163 
00164 
00165 
00167 // nsProxyObjectManager
00169 
00170 class nsProxyObjectManager: public nsIProxyObjectManager
00171 {
00172 public:
00173 
00174     NS_DECL_ISUPPORTS
00175     NS_DECL_NSIPROXYOBJECTMANAGER
00176         
00177     
00178     static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
00179     
00180     nsProxyObjectManager();
00181     
00182     static nsProxyObjectManager *GetInstance();
00183     static PRBool IsManagerShutdown();
00184 
00185     static void Shutdown();
00186     
00187     nsHashtable* GetRealObjectToProxyObjectMap() { return &mProxyObjectMap;}   
00188     nsHashtable* GetIIDToProxyClassMap() { return &mProxyClassMap; }   
00189 
00190     PRMonitor*   GetMonitor() const { return mProxyCreationMonitor; }
00191     
00192 private:
00193     ~nsProxyObjectManager();
00194 
00195     static nsProxyObjectManager* mInstance;
00196     nsHashtable  mProxyObjectMap;
00197     nsHashtable  mProxyClassMap;
00198     PRMonitor   *mProxyCreationMonitor;
00199 };
00200 
00201 
00202 #endif