First checkin of the Python XPCOM bindings.
git-svn-id: svn://10.0.0.236/trunk@87331 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
391
mozilla/extensions/python/xpcom/src/PyIInterfaceInfo.cpp
Normal file
391
mozilla/extensions/python/xpcom/src/PyIInterfaceInfo.cpp
Normal file
@@ -0,0 +1,391 @@
|
||||
/* Copyright (c) 2000-2001 ActiveState Tool Corporation.
|
||||
See the file LICENSE.txt for licensing information. */
|
||||
|
||||
//
|
||||
// This code is part of the XPCOM extensions for Python.
|
||||
//
|
||||
// Written May 2000 by Mark Hammond.
|
||||
//
|
||||
// Based heavily on the Python COM support, which is
|
||||
// (c) Mark Hammond and Greg Stein.
|
||||
//
|
||||
// (c) 2000, ActiveState corp.
|
||||
|
||||
#include "PyXPCOM_std.h"
|
||||
|
||||
|
||||
static nsIInterfaceInfo *GetI(PyObject *self) {
|
||||
nsIID iid = NS_GET_IID(nsIInterfaceInfo);
|
||||
|
||||
if (!Py_nsISupports::Check(self, iid)) {
|
||||
PyErr_SetString(PyExc_TypeError, "This object is not the correct interface");
|
||||
return NULL;
|
||||
}
|
||||
return (nsIInterfaceInfo *)Py_nsISupports::GetI(self);
|
||||
}
|
||||
|
||||
static PyObject *PyGetName(PyObject *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ":GetName"))
|
||||
return NULL;
|
||||
|
||||
nsIInterfaceInfo *pI = GetI(self);
|
||||
if (pI==NULL)
|
||||
return NULL;
|
||||
|
||||
char *name;
|
||||
nsresult r;
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
r = pI->GetName(&name);
|
||||
Py_END_ALLOW_THREADS;
|
||||
if ( NS_FAILED(r) )
|
||||
return PyXPCOM_BuildPyException(r);
|
||||
PyObject *ret = PyString_FromString(name);
|
||||
nsAllocator::Free(name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PyObject *PyGetIID(PyObject *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ":GetIID"))
|
||||
return NULL;
|
||||
|
||||
nsIInterfaceInfo *pI = GetI(self);
|
||||
if (pI==NULL)
|
||||
return NULL;
|
||||
|
||||
nsIID *iid_ret;
|
||||
nsresult r;
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
r = pI->GetIID(&iid_ret);
|
||||
Py_END_ALLOW_THREADS;
|
||||
if ( NS_FAILED(r) )
|
||||
return PyXPCOM_BuildPyException(r);
|
||||
PyObject *ret = Py_nsIID::PyObjectFromIID(*iid_ret);
|
||||
nsAllocator::Free(iid_ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PyObject *PyIsScriptable(PyObject *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ":IsScriptable"))
|
||||
return NULL;
|
||||
|
||||
nsIInterfaceInfo *pI = GetI(self);
|
||||
if (pI==NULL)
|
||||
return NULL;
|
||||
|
||||
PRBool b_ret;
|
||||
nsresult r;
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
r = pI->IsScriptable(&b_ret);
|
||||
Py_END_ALLOW_THREADS;
|
||||
if ( NS_FAILED(r) )
|
||||
return PyXPCOM_BuildPyException(r);
|
||||
return PyInt_FromLong(b_ret);
|
||||
}
|
||||
|
||||
static PyObject *PyGetParent(PyObject *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ":GetParent"))
|
||||
return NULL;
|
||||
|
||||
nsIInterfaceInfo *pI = GetI(self);
|
||||
if (pI==NULL)
|
||||
return NULL;
|
||||
|
||||
nsIInterfaceInfo *pRet;
|
||||
nsresult r;
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
r = pI->GetParent(&pRet);
|
||||
Py_END_ALLOW_THREADS;
|
||||
if ( NS_FAILED(r) )
|
||||
return PyXPCOM_BuildPyException(r);
|
||||
return Py_nsISupports::PyObjectFromInterface(pRet, NS_GET_IID(nsIInterfaceInfo), PR_FALSE);
|
||||
}
|
||||
|
||||
static PyObject *PyGetMethodCount(PyObject *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ":GetMethodCount"))
|
||||
return NULL;
|
||||
|
||||
nsIInterfaceInfo *pI = GetI(self);
|
||||
if (pI==NULL)
|
||||
return NULL;
|
||||
|
||||
PRUint16 ret;
|
||||
nsresult r;
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
r = pI->GetMethodCount(&ret);
|
||||
Py_END_ALLOW_THREADS;
|
||||
if ( NS_FAILED(r) )
|
||||
return PyXPCOM_BuildPyException(r);
|
||||
return PyInt_FromLong(ret);
|
||||
}
|
||||
|
||||
|
||||
static PyObject *PyGetConstantCount(PyObject *self, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ":GetConstantCount"))
|
||||
return NULL;
|
||||
|
||||
nsIInterfaceInfo *pI = GetI(self);
|
||||
if (pI==NULL)
|
||||
return NULL;
|
||||
|
||||
PRUint16 ret;
|
||||
nsresult r;
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
r = pI->GetConstantCount(&ret);
|
||||
Py_END_ALLOW_THREADS;
|
||||
if ( NS_FAILED(r) )
|
||||
return PyXPCOM_BuildPyException(r);
|
||||
return PyInt_FromLong(ret);
|
||||
}
|
||||
|
||||
static PyObject *PyGetMethodInfo(PyObject *self, PyObject *args)
|
||||
{
|
||||
PRUint16 index;
|
||||
if (!PyArg_ParseTuple(args, "h:GetMethodInfo", &index))
|
||||
return NULL;
|
||||
|
||||
nsIInterfaceInfo *pI = GetI(self);
|
||||
if (pI==NULL)
|
||||
return NULL;
|
||||
|
||||
PRUint16 nmethods;
|
||||
pI->GetMethodCount(&nmethods);
|
||||
if (index>=nmethods) {
|
||||
PyErr_SetString(PyExc_ValueError, "The method index is out of range");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const nsXPTMethodInfo *pRet;
|
||||
nsresult r;
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
r = pI->GetMethodInfo(index, &pRet);
|
||||
Py_END_ALLOW_THREADS;
|
||||
if ( NS_FAILED(r) )
|
||||
return PyXPCOM_BuildPyException(r);
|
||||
return PyObject_FromXPTMethodDescriptor(pRet);
|
||||
}
|
||||
|
||||
static PyObject *PyGetMethodInfoForName(PyObject *self, PyObject *args)
|
||||
{
|
||||
char *name;
|
||||
if (!PyArg_ParseTuple(args, "s:GetMethodInfoForName", &name))
|
||||
return NULL;
|
||||
|
||||
nsIInterfaceInfo *pI = GetI(self);
|
||||
if (pI==NULL)
|
||||
return NULL;
|
||||
|
||||
const nsXPTMethodInfo *pRet;
|
||||
PRUint16 index;
|
||||
nsresult r;
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
r = pI->GetMethodInfoForName(name, &index, &pRet);
|
||||
Py_END_ALLOW_THREADS;
|
||||
if ( NS_FAILED(r) )
|
||||
return PyXPCOM_BuildPyException(r);
|
||||
PyObject *ret_i = PyObject_FromXPTMethodDescriptor(pRet);
|
||||
if (ret_i==NULL)
|
||||
return NULL;
|
||||
PyObject *real_ret = Py_BuildValue("iO", (int)index, ret_i);
|
||||
Py_DECREF(ret_i);
|
||||
return real_ret;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *PyGetConstant(PyObject *self, PyObject *args)
|
||||
{
|
||||
PRUint16 index;
|
||||
if (!PyArg_ParseTuple(args, "h:GetConstant", &index))
|
||||
return NULL;
|
||||
|
||||
nsIInterfaceInfo *pI = GetI(self);
|
||||
if (pI==NULL)
|
||||
return NULL;
|
||||
|
||||
const nsXPTConstant *pRet;
|
||||
nsresult r;
|
||||
Py_BEGIN_ALLOW_THREADS;
|
||||
r = pI->GetConstant(index, &pRet);
|
||||
Py_END_ALLOW_THREADS;
|
||||
if ( NS_FAILED(r) )
|
||||
return PyXPCOM_BuildPyException(r);
|
||||
return PyObject_FromXPTConstant(pRet);
|
||||
}
|
||||
|
||||
static PRBool __GetMethodInfoHelper(nsIInterfaceInfo *pii, int mi, int pi, const nsXPTMethodInfo **ppmi)
|
||||
{
|
||||
PRUint16 nmethods=0;
|
||||
pii->GetMethodCount(&nmethods);
|
||||
if (mi<0 || mi>=nmethods) {
|
||||
PyErr_SetString(PyExc_ValueError, "The method index is out of range");
|
||||
return PR_FALSE;
|
||||
}
|
||||
const nsXPTMethodInfo *pmi;
|
||||
nsresult r = pii->GetMethodInfo(mi, &pmi);
|
||||
if ( NS_FAILED(r) ) {
|
||||
PyXPCOM_BuildPyException(r);
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
int nparams=0;
|
||||
nparams = pmi->GetParamCount();
|
||||
if (pi<0 || pi>=nparams) {
|
||||
PyErr_SetString(PyExc_ValueError, "The param index is out of range");
|
||||
return PR_FALSE;
|
||||
}
|
||||
*ppmi = pmi;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
static PyObject *PyGetInfoForParam(PyObject *self, PyObject *args)
|
||||
{
|
||||
nsIInterfaceInfo *pii = GetI(self);
|
||||
if (pii==NULL)
|
||||
return NULL;
|
||||
PRUint16 mi, pi;
|
||||
if (!PyArg_ParseTuple(args, "hh:GetInfoForParam", &mi, &pi))
|
||||
return NULL;
|
||||
const nsXPTMethodInfo *pmi;
|
||||
if (!__GetMethodInfoHelper(pii, mi, pi, &pmi))
|
||||
return NULL;
|
||||
const nsXPTParamInfo& param_info = pmi->GetParam((PRUint8)pi);
|
||||
nsIInterfaceInfo *pnewii = nsnull;
|
||||
nsresult n = pii->GetInfoForParam(mi, ¶m_info, &pnewii);
|
||||
if (NS_FAILED(n))
|
||||
return PyXPCOM_BuildPyException(n);
|
||||
return Py_nsISupports::PyObjectFromInterface(pnewii, NS_GET_IID(nsIInterfaceInfo), PR_FALSE);
|
||||
}
|
||||
|
||||
static PyObject *PyGetIIDForParam(PyObject *self, PyObject *args)
|
||||
{
|
||||
nsIInterfaceInfo *pii = GetI(self);
|
||||
if (pii==NULL)
|
||||
return NULL;
|
||||
PRUint16 mi, pi;
|
||||
if (!PyArg_ParseTuple(args, "hh:GetIIDForParam", &mi, &pi))
|
||||
return NULL;
|
||||
const nsXPTMethodInfo *pmi;
|
||||
if (!__GetMethodInfoHelper(pii, mi, pi, &pmi))
|
||||
return NULL;
|
||||
const nsXPTParamInfo& param_info = pmi->GetParam((PRUint8)pi);
|
||||
nsIID *piid;
|
||||
nsresult n = pii->GetIIDForParam(mi, ¶m_info, &piid);
|
||||
if (NS_FAILED(n) || piid==nsnull)
|
||||
return PyXPCOM_BuildPyException(n);
|
||||
return Py_nsIID::PyObjectFromIID(*piid);
|
||||
}
|
||||
|
||||
static PyObject *PyGetTypeForParam(PyObject *self, PyObject *args)
|
||||
{
|
||||
nsIInterfaceInfo *pii = GetI(self);
|
||||
if (pii==NULL)
|
||||
return NULL;
|
||||
PRUint16 mi, pi, dim;
|
||||
if (!PyArg_ParseTuple(args, "hhh:GetTypeForParam", &mi, &pi, &dim))
|
||||
return NULL;
|
||||
const nsXPTMethodInfo *pmi;
|
||||
if (!__GetMethodInfoHelper(pii, mi, pi, &pmi))
|
||||
return NULL;
|
||||
nsXPTType datumType;
|
||||
const nsXPTParamInfo& param_info = pmi->GetParam((PRUint8)pi);
|
||||
nsresult n = pii->GetTypeForParam(mi, ¶m_info, dim, &datumType);
|
||||
if (NS_FAILED(n))
|
||||
return PyXPCOM_BuildPyException(n);
|
||||
return PyObject_FromXPTTypeDescriptor((const XPTTypeDescriptor *)&datumType);
|
||||
}
|
||||
|
||||
static PyObject *PyGetSizeIsArgNumberForParam(PyObject *self, PyObject *args)
|
||||
{
|
||||
nsIInterfaceInfo *pii = GetI(self);
|
||||
if (pii==NULL)
|
||||
return NULL;
|
||||
PRUint16 mi, pi, dim;
|
||||
if (!PyArg_ParseTuple(args, "hhh:GetSizeIsArgNumberForParam", &mi, &pi, &dim))
|
||||
return NULL;
|
||||
const nsXPTMethodInfo *pmi;
|
||||
if (!__GetMethodInfoHelper(pii, mi, pi, &pmi))
|
||||
return NULL;
|
||||
PRUint8 ret;
|
||||
const nsXPTParamInfo& param_info = pmi->GetParam((PRUint8)pi);
|
||||
nsresult n = pii->GetSizeIsArgNumberForParam(mi, ¶m_info, dim, &ret);
|
||||
if (NS_FAILED(n))
|
||||
return PyXPCOM_BuildPyException(n);
|
||||
return PyInt_FromLong(ret);
|
||||
}
|
||||
|
||||
static PyObject *PyGetLengthIsArgNumberForParam(PyObject *self, PyObject *args)
|
||||
{
|
||||
nsIInterfaceInfo *pii = GetI(self);
|
||||
if (pii==NULL)
|
||||
return NULL;
|
||||
PRUint16 mi, pi, dim;
|
||||
if (!PyArg_ParseTuple(args, "hhh:GetLengthIsArgNumberForParam", &mi, &pi, &dim))
|
||||
return NULL;
|
||||
const nsXPTMethodInfo *pmi;
|
||||
if (!__GetMethodInfoHelper(pii, mi, pi, &pmi))
|
||||
return NULL;
|
||||
PRUint8 ret;
|
||||
const nsXPTParamInfo& param_info = pmi->GetParam((PRUint8)pi);
|
||||
nsresult n = pii->GetLengthIsArgNumberForParam(mi, ¶m_info, dim, &ret);
|
||||
if (NS_FAILED(n))
|
||||
return PyXPCOM_BuildPyException(n);
|
||||
return PyInt_FromLong(ret);
|
||||
}
|
||||
|
||||
static PyObject *PyGetInterfaceIsArgNumberForParam(PyObject *self, PyObject *args)
|
||||
{
|
||||
nsIInterfaceInfo *pii = GetI(self);
|
||||
if (pii==NULL)
|
||||
return NULL;
|
||||
PRUint16 mi, pi;
|
||||
if (!PyArg_ParseTuple(args, "hhh:GetInterfaceIsArgNumberForParam", &mi, &pi))
|
||||
return NULL;
|
||||
const nsXPTMethodInfo *pmi;
|
||||
if (!__GetMethodInfoHelper(pii, mi, pi, &pmi))
|
||||
return NULL;
|
||||
PRUint8 ret;
|
||||
const nsXPTParamInfo& param_info = pmi->GetParam((PRUint8)pi);
|
||||
nsresult n = pii->GetInterfaceIsArgNumberForParam(mi, ¶m_info, &ret);
|
||||
if (NS_FAILED(n))
|
||||
return PyXPCOM_BuildPyException(n);
|
||||
return PyInt_FromLong(ret);
|
||||
}
|
||||
|
||||
struct PyMethodDef
|
||||
PyMethods_IInterfaceInfo[] =
|
||||
{
|
||||
{ "GetName", PyGetName, 1},
|
||||
{ "GetIID", PyGetIID, 1},
|
||||
{ "IsScriptable", PyIsScriptable, 1},
|
||||
{ "GetParent", PyGetParent, 1},
|
||||
{ "GetMethodCount", PyGetMethodCount, 1},
|
||||
{ "GetConstantCount", PyGetConstantCount, 1},
|
||||
{ "GetMethodInfo", PyGetMethodInfo, 1},
|
||||
{ "GetMethodInfoForName", PyGetMethodInfoForName, 1},
|
||||
{ "GetConstant", PyGetConstant, 1},
|
||||
{ "GetInfoForParam", PyGetInfoForParam, 1},
|
||||
{ "GetIIDForParam", PyGetIIDForParam, 1},
|
||||
{ "GetTypeForParam", PyGetTypeForParam, 1},
|
||||
{ "GetSizeIsArgNumberForParam", PyGetSizeIsArgNumberForParam, 1},
|
||||
{ "GetLengthIsArgNumberForParam", PyGetLengthIsArgNumberForParam, 1},
|
||||
{ "GetInterfaceIsArgNumberForParam", PyGetInterfaceIsArgNumberForParam, 1},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
/*
|
||||
NS_IMETHOD GetMethodInfo(PRUint16 index, const nsXPTMethodInfo * *info) = 0;
|
||||
NS_IMETHOD GetMethodInfoForName(const char *methodName, PRUint16 *index, const nsXPTMethodInfo * *info) = 0;
|
||||
NS_IMETHOD GetConstant(PRUint16 index, const nsXPTConstant * *constant) = 0;
|
||||
NS_IMETHOD GetInfoForParam(PRUint16 methodIndex, const nsXPTParamInfo * param, nsIInterfaceInfo **_retval) = 0;
|
||||
NS_IMETHOD GetIIDForParam(PRUint16 methodIndex, const nsXPTParamInfo * param, nsIID * *_retval) = 0;
|
||||
NS_IMETHOD GetTypeForParam(PRUint16 methodIndex, const nsXPTParamInfo * param, PRUint16 dimension, nsXPTType *_retval) = 0;
|
||||
NS_IMETHOD GetSizeIsArgNumberForParam(PRUint16 methodIndex, const nsXPTParamInfo * param, PRUint16 dimension, PRUint8 *_retval) = 0;
|
||||
NS_IMETHOD GetLengthIsArgNumberForParam(PRUint16 methodIndex, const nsXPTParamInfo * param, PRUint16 dimension, PRUint8 *_retval) = 0;
|
||||
NS_IMETHOD GetInterfaceIsArgNumberForParam(PRUint16 methodIndex, const nsXPTParamInfo * param, PRUint8 *_retval) = 0;
|
||||
|
||||
*/
|
||||
Reference in New Issue
Block a user