Mozilla/mozilla/extensions/mono/src/wrapped-clr.cpp
shaver%mozilla.org c367c99af4 initial import of monoconnect^Wxpcom-dotnet^Wextensions/mono code -- not working, not done, not useful to you, not part of the build
git-svn-id: svn://10.0.0.236/trunk@168679 18797224-902f-48f8-a5cc-f745e15eee43
2005-02-01 23:58:57 +00:00

52 lines
1.3 KiB
C++

#include <nsIInterfaceInfoManager.h>
#include <xptcall.h>
#include <xpt_xdr.h>
#include <nsCRT.h>
#include <stdio.h>
class WrappedCLR : public nsXPTCStubBase
{
public:
typedef int (*MethodInvoker)(int, nsXPTCMiniVariant *);
NS_DECL_ISUPPORTS
NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo **aInfo);
NS_IMETHOD CallMethod(PRUint16 methodIndex,
const nsXPTMethodInfo *info,
nsXPTCMiniVariant *params);
WrappedCLR(MethodInvoker del, const nsIID &id) :
mIID(id), mDelegate(del) { }
virtual ~WrappedCLR() { }
private:
nsIID mIID;
MethodInvoker mDelegate;
};
NS_IMPL_ISUPPORTS1(WrappedCLR, nsISupports);
NS_IMETHODIMP
WrappedCLR::GetInterfaceInfo(nsIInterfaceInfo **info)
{
extern nsIInterfaceInfoManager *infomgr;
return infomgr->GetInfoForIID(&mIID, info);
}
NS_IMETHODIMP
WrappedCLR::CallMethod(PRUint16 methodIndex,
const nsXPTMethodInfo *info,
nsXPTCMiniVariant *params)
{
fprintf(stderr, "Calling %s via %p\n", info->GetName(), mDelegate);
return mDelegate(methodIndex, params);
}
extern "C" WrappedCLR *
WrapCLRObject(WrappedCLR::MethodInvoker del, const nsIID &id)
{
char *idstr = id.ToString();
fprintf(stderr, "Wrapping %p as %s\n", del, idstr);
nsCRT::free(idstr);
return new WrappedCLR(del, id);
}