Import 1.9b4 extra tag from cvs
[mozilla-extra.git] / extensions / mono / src / wrapped-clr.cpp
blob5a806dc5e0d067b9f4ac4ddafc4df9c7a5f0191c
1 #include <nsIInterfaceInfoManager.h>
2 #include <xptcall.h>
3 #include <xpt_xdr.h>
4 #include <nsCRT.h>
6 #include <stdio.h>
8 class WrappedCLR : public nsXPTCStubBase
10 public:
11 typedef int (*MethodInvoker)(int, nsXPTCMiniVariant *);
13 NS_DECL_ISUPPORTS
14 NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo **aInfo);
15 NS_IMETHOD CallMethod(PRUint16 methodIndex,
16 const nsXPTMethodInfo *info,
17 nsXPTCMiniVariant *params);
18 WrappedCLR(MethodInvoker del, const nsIID &id) :
19 mIID(id), mDelegate(del) { }
20 virtual ~WrappedCLR() { }
21 private:
22 nsIID mIID;
23 MethodInvoker mDelegate;
26 NS_IMPL_ISUPPORTS1(WrappedCLR, nsISupports);
28 NS_IMETHODIMP
29 WrappedCLR::GetInterfaceInfo(nsIInterfaceInfo **info)
31 extern nsIInterfaceInfoManager *infomgr;
32 return infomgr->GetInfoForIID(&mIID, info);
35 NS_IMETHODIMP
36 WrappedCLR::CallMethod(PRUint16 methodIndex,
37 const nsXPTMethodInfo *info,
38 nsXPTCMiniVariant *params)
40 fprintf(stderr, "Calling %s via %p\n", info->GetName(), mDelegate);
41 return mDelegate(methodIndex, params);
44 extern "C" WrappedCLR *
45 WrapCLRObject(WrappedCLR::MethodInvoker del, const nsIID &id)
47 char *idstr = id.ToString();
48 fprintf(stderr, "Wrapping %p as %s\n", del, idstr);
49 nsCRT::free(idstr);
50 return new WrappedCLR(del, id);