00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef __TCLXPCOMPRIVATE_H__
00036 #define __TCLXPCOMPRIVATE_H__
00037
00038 #ifndef MOZILLA_STRICT_API
00039 #define MOZILLA_STRICT_API
00040 #endif
00041
00042
00043 #define USE_NON_CONST
00044
00045 #include "tclxpcom.h"
00046 #include "xptcall.h"
00047 #include "nsISupports.h"
00048 #include "nsISupportsUtils.h"
00049 #include "nsIClassInfo.h"
00050 #include "nsIInterfaceInfo.h"
00051 #include "nsIServiceManager.h"
00052 #include "nsIInterfaceInfoManager.h"
00053 #include "nsIComponentRegistrar.h"
00054 #include "nsIMemory.h"
00055 #include "nsWeakReference.h"
00056
00057 extern Tcl_Encoding ascii_enc;
00058
00059
00060 #ifdef TCL_WIDE_INT_TYPE
00061 # define USE_TCL_WIDEINT
00062 #endif
00063
00064
00065 #ifdef USE_TCL_WIDEINT
00066
00067 typedef Tcl_WideInt TclXPCOM_WideInt;
00068 #define TclXPCOM_NewWideIntObj Tcl_NewWideIntObj
00069 #define TclXPCOM_GetWideIntFromObj Tcl_GetWideIntFromObj
00070
00071 #else
00072
00073 typedef PRInt64 TclXPCOM_WideInt;
00074 Tcl_Obj *TclXPCOM_NewWideIntObj (TclXPCOM_WideInt wideint);
00075 int TclXPCOM_GetWideIntFromObj (Tcl_Interp *interp, Tcl_Obj *objPtr, TclXPCOM_WideInt *wideint);
00076
00077 #endif
00078
00079
00080 extern nsIServiceManager *servmanager;
00081 extern nsIInterfaceInfoManager *manager;
00082 extern nsIComponentRegistrar *registrar;
00083 extern nsIMemory *memmgr;
00084
00085 extern nsIID nsisupports_iid;
00086 extern nsIID nsiclassinfo_iid;
00087 extern nsIID nsiservicemanager_iid;
00088
00089 extern nsIInterfaceInfo *nsisupports_info;
00090 extern nsIInterfaceInfo *nsiservicemanager_info;
00091 extern nsIInterfaceInfo *nsiclassinfo_info;
00092
00093 extern Tcl_ObjType ISupportsType;
00094
00098 #define PARAM_IS_SKIPPED 0x0100
00099 #define PARAM_IS_RETVAL 0x0200
00100 #define PARAM_IS_SKIPPED_IN 0x0400
00101 #define PARAM_IS_SKIPPED_OUT 0x0800
00102 #define PARAM_IS_SHARED_IN 0x1000
00103 #define PARAM_IS_SHARED_OUT 0x2000
00104 #define PARAM_INDEX_MASK 0x00ff
00105
00106
00110 typedef struct MethodInfo
00111 {
00112 PRUint8 paramcount;
00113 PRUint8 tclparamcount;
00114 PRUint16 *tclparams;
00115 nsXPTParamInfo *paraminfos;
00116 } MethodInfo;
00117
00118
00122 typedef struct IdentifierInfo_
00123 {
00124 char *name;
00125 PRUint8 type;
00126 union
00127 {
00128 PRUint16 methodindex;
00129 struct
00130 {
00131 PRUint16 getterindex;
00132 PRUint16 setterindex;
00133 } attributeindices;
00134 } indices;
00135 } IdentifierInfo;
00136
00137
00141 typedef struct InterfaceInfo
00142 {
00143
00144 nsIInterfaceInfo *info;
00145 nsIInterfaceInfo *parentinfo;
00146
00147
00148 PRUint16 imethodcount;
00149 PRUint16 methodcount;
00150 PRUint16 attributecount;
00151 PRUint16 constantcount;
00152
00153 PRUint16 baseimethodindex;
00154 PRUint16 basemethodindex;
00155 PRUint16 baseattributeindex;
00156 PRUint16 baseconstantindex;
00157
00158 MethodInfo *imethods;
00159 IdentifierInfo *methods;
00160 IdentifierInfo *attributes;
00161 char **constantnames;
00162 Tcl_Obj **constantvalues;
00163 } InterfaceInfo;
00164
00165
00169 typedef struct ClassInfoSignature
00170 {
00171 int infocount;
00172 nsIInterfaceInfo **infolist;
00173 } ClassInfoSignature;
00174
00175
00179 typedef struct ClassIdentifierInfo
00180 {
00181 IdentifierInfo idinfo;
00182 nsIInterfaceInfo *info;
00183 PRUint8 qualified;
00184 } ClassIdentifierInfo;
00185
00186
00190 typedef struct ClassInfo_
00191 {
00192
00193 ClassInfoSignature signature;
00194 PRUint16 methodcount;
00195 PRUint16 attributecount;
00196 ClassIdentifierInfo *methods;
00197 ClassIdentifierInfo *attributes;
00198 } ClassInfo;
00199
00200
00204 typedef struct InterfaceRef
00205 {
00206 int refcount;
00207 Tcl_HashTable refhash;
00208 nsIClassInfo *cinforef;
00209 ClassInfo *cinfo;
00210 int cisupported;
00211 } InterfaceRef;
00212
00213
00217 class TclXPCOMStub : public nsXPTCStubBase,
00218 public nsSupportsWeakReference
00219 {
00220 public:
00221
00222 nsIInterfaceInfo *info;
00223 struct TclXPCOMComponent *component;
00224 Tcl_Obj **bindings;
00225
00226 TclXPCOMStub (nsIInterfaceInfo *interfaceinfo);
00227 ~TclXPCOMStub (void);
00228
00229 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
00230 NS_IMETHOD_(nsrefcnt) AddRef(void);
00231 NS_IMETHOD_(nsrefcnt) Release(void);
00232 NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info);
00233 NS_IMETHOD CallMethod(PRUint16 methodIndex, const nsXPTMethodInfo *info, nsXPTCMiniVariant *params);
00234
00235 void SetBinding (PRUint16 methodindex, Tcl_Obj *script);
00236 void UnsetBinding (PRUint16 methodindex);
00237 Tcl_Obj *GetBinding (PRUint16 methodindex);
00238 };
00239
00240
00244 typedef struct TclXPCOMComponent
00245 {
00246 nsrefcnt refcount;
00247 Tcl_Interp *interp;
00248 Tcl_ThreadId thread;
00249 ClassInfo *cinfo;
00250 TclXPCOMStub **stubs;
00251 Tcl_Obj *destructor;
00252 int nesting;
00253 int nestlevel;
00254 } TclXPCOMComponent;
00255
00256
00257 void TclXPCOM_InitInterfaceRef (void);
00258 void TclXPCOM_InitClassInfo (void);
00259 void TclXPCOM_InitInterfaceInfo (void);
00260 void TclXPCOM_RegisterObjTypes (void);
00261
00262 int AddRefInterface (nsISupports *isupports, nsIInterfaceInfo *interfaceinfo, Tcl_HashEntry **entry);
00263 int ReleaseInterface (nsISupports *isupports);
00264 int QueryInterfaceIRef (Tcl_Interp *interp, InterfaceRef *iref, nsIInterfaceInfo *queryinfo, nsISupports **result);
00265 int GetMethodFromIRef (Tcl_Interp *interp, nsISupports *isupports, nsIInterfaceInfo *info, Tcl_Obj *identifier, int type, nsIInterfaceInfo **interfaceinfo, PRUint16 *methodindex);
00266 InterfaceRef *GetInterfaceRef (nsISupports *isupports);
00267
00268 TclXPCOMComponent *NewTclXPCOMComponent (Tcl_Interp *interp, Tcl_ThreadId thread, ClassInfo *cinfo);
00269 void FreeTclXPCOMComponent (TclXPCOMComponent *component);
00270 int BindScript (Tcl_Interp *interp, TclXPCOMComponent *component, Tcl_Obj *identifier, Tcl_Obj *script, int flags);
00271
00272 InterfaceInfo *GetInterfaceInfo (nsIInterfaceInfo *interfaceinfo);
00273 MethodInfo *GetMethodInfo (nsIInterfaceInfo *interfaceinfo, PRUint16 methodindex);
00274
00275 int IsInInterface (nsIInterfaceInfo *infoa, nsIInterfaceInfo *infob);
00276 int isInInterface (nsIInterfaceInfo *interfaceinfo, nsIID *iid);
00277
00278 int Tcl2Native (Tcl_Interp *interp, Tcl_Obj *value, void **params, void *param, nsXPTType *type, int shared, nsIInterfaceInfo *interfaceinfo, PRUint16 methodindex, nsXPTParamInfo *paraminfo);
00279 nsresult Native2Tcl (void **params, void *param, nsXPTType *type, nsIInterfaceInfo *interfaceinfo, PRUint16 methodindex, nsXPTParamInfo *paraminfo, Tcl_Obj **result);
00280 void CleanupParam (void **params, void *param, nsXPTType *type, nsIInterfaceInfo *interfaceinfo, PRUint16 methodindex, nsXPTParamInfo *paraminfo);
00281
00282 nsresult TclXPCOM_CallMethod (Tcl_Interp *interp, nsXPTCMiniVariant *variants, nsISupports *isupports, nsIInterfaceInfo *interfaceinfo, PRUint16 methodindex, Tcl_Obj *script);
00283
00284 void *CloneMemory (void *ptr, size_t size);
00285
00286 #endif