Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
xpcom.cpp File Reference
#include "PyXPCOM_std.h"
#include "nsIThread.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "nsIModule.h"
#include "nsIFile.h"
#include "nsILocalFile.h"
#include "nsIComponentRegistrar.h"
#include "nsIComponentManagerObsolete.h"
#include "nsIEventQueue.h"
#include "nsIProxyObjectManager.h"

Go to the source code of this file.

Defines

#define LOADER_LINKS_WITH_PYTHON
#define REGISTER_IID(t)
#define REGISTER_INT(val)

Functions

PRInt32 _PyXPCOM_GetGatewayCount (void)
PRInt32 _PyXPCOM_GetInterfaceCount (void)
void AddDefaultGateway (PyObject *instance, nsISupports *gateway)
void PyXPCOM_InterpreterState_Ensure ()
 PyXPCOM_INTERFACE_DEFINE (Py_nsIComponentManager, nsIComponentManager, PyMethods_IComponentManager) PyXPCOM_INTERFACE_DEFINE(Py_nsIInterfaceInfoManager
PyMethods_IInterfaceInfoManager PyXPCOM_INTERFACE_DEFINE (Py_nsIEnumerator, nsIEnumerator, PyMethods_IEnumerator) PyXPCOM_INTERFACE_DEFINE(Py_nsISimpleEnumerator
PyMethods_IInterfaceInfoManager
PyMethods_ISimpleEnumerator 
PyXPCOM_INTERFACE_DEFINE (Py_nsIInterfaceInfo, nsIInterfaceInfo, PyMethods_IInterfaceInfo) PyXPCOM_INTERFACE_DEFINE(Py_nsIInputStream
PyMethods_IInterfaceInfoManager
PyMethods_ISimpleEnumerator
PyMethods_IInputStream 
PyXPCOM_INTERFACE_DEFINE (Py_nsIClassInfo, nsIClassInfo, PyMethods_IClassInfo) PyXPCOM_INTERFACE_DEFINE(Py_nsIVariant
PyMethods_IInterfaceInfoManager
PyMethods_ISimpleEnumerator
PyMethods_IInputStream
PyMethods_IVariant 
PyXPCOM_INTERFACE_DEFINE (Py_nsIComponentManagerObsolete, nsIComponentManagerObsolete, PyMethods_IComponentManagerObsolete) extern"C"NS_EXPORT nsresult PyXPCOM_NSGetModule(nsIComponentManager *servMgr
static PyObject * PyXPCOMMethod_GetProxyForObject (PyObject *self, PyObject *args)
PyObject * PyGetSpecialDirectory (PyObject *self, PyObject *args)
PyObject * AllocateBuffer (PyObject *self, PyObject *args)
PyObject * LogWarning (PyObject *self, PyObject *args)
PyObject * LogError (PyObject *self, PyObject *args)
PyObject * PyXPCOMMethod_IID (PyObject *self, PyObject *args)
PRBool PyXPCOM_Globals_Ensure ()
NS_EXPORT void init_xpcom ()

Variables

PYXPCOM_EXPORT PyObject * PyXPCOM_Error = NULL
 nsIInterfaceInfoManager
PyMethods_IInterfaceInfoManager nsISimpleEnumerator
PyMethods_IInterfaceInfoManager
PyMethods_ISimpleEnumerator 
nsIInputStream
PyMethods_IInterfaceInfoManager
PyMethods_ISimpleEnumerator
PyMethods_IInputStream 
nsIVariant
PyMethods_IInterfaceInfoManager
PyMethods_ISimpleEnumerator
PyMethods_IInputStream
PyMethods_IVariant nsIFile
location
static struct PyMethodDef []

Define Documentation

Definition at line 74 of file xpcom.cpp.

Value:
{ \
       PyObject *iid_ob = Py_nsIID::PyObjectFromIID(NS_GET_IID(t)); \
       PyDict_SetItemString(dict, "IID_"#t, iid_ob); \
       Py_DECREF(iid_ob); \
       }

Definition at line 565 of file xpcom.cpp.

Value:
{ \
       PyObject *ob = PyInt_FromLong(val); \
       PyDict_SetItemString(dict, #val, ob); \
       Py_DECREF(ob); \
       }

Definition at line 571 of file xpcom.cpp.


Function Documentation

Definition at line 55 of file PyGBase.cpp.

{
       return cGateways;
}

Definition at line 54 of file PyISupports.cpp.

{
       return cInterfaces;
}
void AddDefaultGateway ( PyObject *  instance,
nsISupports *  gateway 
)

Definition at line 799 of file PyGBase.cpp.

{
       // NOTE: Instance is the _policy_!
       PyObject *real_inst = PyObject_GetAttrString(instance, "_obj_");
       NS_ABORT_IF_FALSE(real_inst, "Could not get the '_obj_' element");
       if (!real_inst) return;
       if (!PyObject_HasAttrString(real_inst, PyXPCOM_szDefaultGatewayAttributeName)) {
              nsCOMPtr<nsISupportsWeakReference> swr( do_QueryInterface((nsISupportsWeakReference *)(gateway)) );
              NS_ABORT_IF_FALSE(swr, "Our gateway failed with a weak reference query");
              // Create the new default gateway - get a weak reference for our gateway.
              if (swr) {
                     nsIWeakReference *pWeakReference = NULL;
                     swr->GetWeakReference( &pWeakReference );
                     if (pWeakReference) {
                            PyObject *ob_new_weak = Py_nsISupports::PyObjectFromInterface(pWeakReference, 
                                                                         NS_GET_IID(nsIWeakReference),
                                                                         PR_FALSE, /* bAddRef */
                                                                         PR_FALSE ); /* bMakeNicePyObject */
                            // pWeakReference reference consumed.
                            if (ob_new_weak) {
                                   PyObject_SetAttrString(real_inst, PyXPCOM_szDefaultGatewayAttributeName, ob_new_weak);
                                   Py_DECREF(ob_new_weak);
                            }
                     }
              }
       }
       Py_DECREF(real_inst);
}

Here is the call graph for this function:

PyObject* AllocateBuffer ( PyObject *  self,
PyObject *  args 
)

Definition at line 439 of file xpcom.cpp.

{
       int bufSize;
       if (!PyArg_ParseTuple(args, "i", &bufSize))
              return NULL;
       return PyBuffer_New(bufSize);
}

Definition at line 583 of file xpcom.cpp.

             {
       PyObject *oModule;

       // ensure the framework has valid state to work with.
       if (!PyXPCOM_Globals_Ensure())
              return;

       // Must force Python to start using thread locks
       PyEval_InitThreads();

       // Create the module and add the functions
       oModule = Py_InitModule("_xpcom", xpcom_methods);

       PyObject *dict = PyModule_GetDict(oModule);
       PyObject *pycom_Error = PyXPCOM_Error;
       if (pycom_Error == NULL || PyDict_SetItemString(dict, "error", pycom_Error) != 0)
       {
              PyErr_SetString(PyExc_MemoryError, "can't define error");
              return;
       }
       PyDict_SetItemString(dict, "IIDType", (PyObject *)&Py_nsIID::type);

       // register our entry point.
       PyObject *obFuncPtr = PyLong_FromVoidPtr((void *)&PyXPCOM_NSGetModule);
       if (obFuncPtr)
              PyDict_SetItemString(dict, 
                                           "_NSGetModule_FuncPtr", 
                                           obFuncPtr);
       Py_XDECREF(obFuncPtr);

       REGISTER_IID(nsISupports);
       REGISTER_IID(nsISupportsCString);
       REGISTER_IID(nsIModule);
       REGISTER_IID(nsIFactory);
       REGISTER_IID(nsIWeakReference);
       REGISTER_IID(nsISupportsWeakReference);
       REGISTER_IID(nsIClassInfo);
       REGISTER_IID(nsIServiceManager);
       REGISTER_IID(nsIComponentRegistrar);
       // Register our custom interfaces.

       Py_nsISupports::InitType();
       Py_nsIComponentManager::InitType(dict);
       Py_nsIInterfaceInfoManager::InitType(dict);
       Py_nsIEnumerator::InitType(dict);
       Py_nsISimpleEnumerator::InitType(dict);
       Py_nsIInterfaceInfo::InitType(dict);
       Py_nsIInputStream::InitType(dict);
       Py_nsIClassInfo::InitType(dict);
       Py_nsIVariant::InitType(dict);
       // for backward compatibility:
       Py_nsIComponentManagerObsolete::InitType(dict);

    // We have special support for proxies - may as well add their constants!
    REGISTER_INT(PROXY_SYNC);
    REGISTER_INT(PROXY_ASYNC);
    REGISTER_INT(PROXY_ALWAYS);
}

Here is the call graph for this function:

PyObject* LogError ( PyObject *  self,
PyObject *  args 
)

Definition at line 457 of file xpcom.cpp.

{
       char *msg;
       if (!PyArg_ParseTuple(args, "s", &msg))
              return NULL;
       PyXPCOM_LogError("%s", msg);
       Py_INCREF(Py_None);
       return Py_None;
}

Here is the call graph for this function:

PyObject* LogWarning ( PyObject *  self,
PyObject *  args 
)

Definition at line 447 of file xpcom.cpp.

{
       char *msg;
       if (!PyArg_ParseTuple(args, "s", &msg))
              return NULL;
       PyXPCOM_LogWarning("%s", msg);
       Py_INCREF(Py_None);
       return Py_None;
}

Here is the call graph for this function:

PyObject* PyGetSpecialDirectory ( PyObject *  self,
PyObject *  args 
)

Definition at line 426 of file xpcom.cpp.

{
       char *dirname;
       if (!PyArg_ParseTuple(args, "s:GetSpecialDirectory", &dirname))
              return NULL;
       nsIFile *file = NULL;
       nsresult r = NS_GetSpecialDirectory(dirname, &file);
       if ( NS_FAILED(r) )
              return PyXPCOM_BuildPyException(r);
       // returned object swallows our reference.
       return Py_nsISupports::PyObjectFromInterface(file, NS_GET_IID(nsIFile), PR_FALSE);
}

Here is the call graph for this function:

Definition at line 496 of file xpcom.cpp.

{
       PRBool rc = PR_TRUE;

#ifndef PYXPCOM_USE_PYGILSTATE
       PyXPCOM_InterpreterState_Ensure();
#endif

       // The exception object - we load it from .py code!
       if (PyXPCOM_Error == NULL) {
              rc = PR_FALSE;
              PyObject *mod = NULL;

              mod = PyImport_ImportModule("xpcom");
              if (mod!=NULL) {
                     PyXPCOM_Error = PyObject_GetAttrString(mod, "Exception");
                     Py_DECREF(mod);
              }
              rc = (PyXPCOM_Error != NULL);
       }
       if (!rc)
              return rc;

       static PRBool bHaveInitXPCOM = PR_FALSE;
       if (!bHaveInitXPCOM) {
              nsCOMPtr<nsIThread> thread_check;
              // xpcom appears to assert if already initialized
              // Is there an official way to determine this?
              if (NS_FAILED(nsIThread::GetMainThread(getter_AddRefs(thread_check)))) {
                     // not already initialized.
#ifdef XP_WIN
                     // On Windows, we need to locate the Mozilla bin
                     // directory.  This by using locating a Moz DLL we depend
                     // on, and assume it lives in that bin dir.  Different
                     // moz build types (eg, xulrunner, suite) package
                     // XPCOM itself differently - but all appear to require
                     // nspr4.dll - so this is what we use.
                     char landmark[MAX_PATH+1];
                     HMODULE hmod = GetModuleHandle("nspr4.dll");
                     if (hmod==NULL) {
                            PyErr_SetString(PyExc_RuntimeError, "We dont appear to be linked against nspr4.dll.");
                            return PR_FALSE;
                     }
                     GetModuleFileName(hmod, landmark, sizeof(landmark)/sizeof(landmark[0]));
                     char *end = landmark + (strlen(landmark)-1);
                     while (end > landmark && *end != '\\')
                            end--;
                     if (end > landmark) *end = '\0';

                     nsCOMPtr<nsILocalFile> ns_bin_dir;
                     NS_ConvertASCIItoUCS2 strLandmark(landmark);
                     NS_NewLocalFile(strLandmark, PR_FALSE, getter_AddRefs(ns_bin_dir));
                     nsresult rv = NS_InitXPCOM2(nsnull, ns_bin_dir, nsnull);
#else
                     // Elsewhere, Mozilla can find it itself (we hope!)
                     nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
#endif // XP_WIN
                     if (NS_FAILED(rv)) {
                            PyErr_SetString(PyExc_RuntimeError, "The XPCOM subsystem could not be initialized");
                            return PR_FALSE;
                     }
              }
              // Even if xpcom was already init, we want to flag it as init!
              bHaveInitXPCOM = PR_TRUE;
       }
       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PyXPCOM_INTERFACE_DEFINE ( Py_nsIComponentManager  ,
nsIComponentManager  ,
PyMethods_IComponentManager   
)
PyMethods_IInterfaceInfoManager PyXPCOM_INTERFACE_DEFINE ( Py_nsIEnumerator  ,
nsIEnumerator  ,
PyMethods_IEnumerator   
)
PyMethods_IInterfaceInfoManager PyMethods_ISimpleEnumerator PyXPCOM_INTERFACE_DEFINE ( Py_nsIInterfaceInfo  ,
nsIInterfaceInfo  ,
PyMethods_IInterfaceInfo   
)
PyMethods_IInterfaceInfoManager PyMethods_ISimpleEnumerator PyMethods_IInputStream PyXPCOM_INTERFACE_DEFINE ( Py_nsIClassInfo  ,
nsIClassInfo  ,
PyMethods_IClassInfo   
)
PyMethods_IInterfaceInfoManager PyMethods_ISimpleEnumerator PyMethods_IInputStream PyMethods_IVariant PyXPCOM_INTERFACE_DEFINE ( Py_nsIComponentManagerObsolete  ,
nsIComponentManagerObsolete  ,
PyMethods_IComponentManagerObsolete   
)

Definition at line 74 of file dllmain.cpp.

{
       if (PyXPCOM_InterpreterState==NULL) {
              PyThreadState *threadStateSave = PyThreadState_Swap(NULL);
              if (threadStateSave==NULL)
                     Py_FatalError("Can not setup interpreter state, as current state is invalid");

              PyXPCOM_InterpreterState = threadStateSave->interp;
              PyThreadState_Swap(threadStateSave);
       }
}

Here is the caller graph for this function:

static PyObject* PyXPCOMMethod_GetProxyForObject ( PyObject *  self,
PyObject *  args 
) [static]

Definition at line 377 of file xpcom.cpp.

{
       PyObject *obQueue, *obIID, *obOb;
       int flags;
       if (!PyArg_ParseTuple(args, "OOOi", &obQueue, &obIID, &obOb, &flags))
              return NULL;
       nsIID iid;
       if (!Py_nsIID::IIDFromPyObject(obIID, &iid))
              return NULL;
       nsCOMPtr<nsISupports> pob;
       if (!Py_nsISupports::InterfaceFromPyObject(obOb, iid, getter_AddRefs(pob), PR_FALSE))
              return NULL;
       nsIEventQueue *pQueue = NULL;
       nsIEventQueue *pQueueRelease = NULL;

       if (PyInt_Check(obQueue)) {
              pQueue = (nsIEventQueue *)PyInt_AsLong(obQueue);
       } else {
              if (!Py_nsISupports::InterfaceFromPyObject(obQueue, NS_GET_IID(nsIEventQueue), (nsISupports **)&pQueue, PR_TRUE))
                     return NULL;
              pQueueRelease = pQueue;
       }

       nsresult rv_proxy;
       nsISupports *presult = nsnull;
       Py_BEGIN_ALLOW_THREADS;
       nsCOMPtr<nsIProxyObjectManager> proxyMgr = 
                do_GetService(kProxyObjectManagerCID, &rv_proxy);

       if ( NS_SUCCEEDED(rv_proxy) ) {
              rv_proxy = proxyMgr->GetProxyForObject(pQueue,
                            iid,
                            pob,
                            flags,
                            (void **)&presult);
       }
       if (pQueueRelease)
              pQueueRelease->Release();
       Py_END_ALLOW_THREADS;

       PyObject *result;
       if (NS_SUCCEEDED(rv_proxy) ) {
              result = Py_nsISupports::PyObjectFromInterface(presult, iid, PR_FALSE);
       } else {
              result = PyXPCOM_BuildPyException(rv_proxy);
       }
       return result;
}

Here is the call graph for this function:

PyObject* PyXPCOMMethod_IID ( PyObject *  self,
PyObject *  args 
)

Definition at line 57 of file PyIID.cpp.

{
       PyObject *obIID;
       PyObject *obBuf;
       if ( PyArg_ParseTuple(args, "O", &obBuf)) {
              if (PyBuffer_Check(obBuf)) {
                     PyBufferProcs *pb = NULL;
                     pb = obBuf->ob_type->tp_as_buffer;
                     void *buf = NULL;
                     int size = (*pb->bf_getreadbuffer)(obBuf, 0, &buf);
                     if (size != sizeof(nsIID) || buf==NULL) {
                            PyErr_Format(PyExc_ValueError, "A buffer object to be converted to an IID must be exactly %d bytes long", sizeof(nsIID));
                            return NULL;
                     }
                     nsIID iid;
                     unsigned char *ptr = (unsigned char *)buf;
                     iid.m0 = XPT_SWAB32(*((PRUint32 *)ptr));
                     ptr = ((unsigned char *)buf) + offsetof(nsIID, m1);
                     iid.m1 = XPT_SWAB16(*((PRUint16 *)ptr));
                     ptr = ((unsigned char *)buf) + offsetof(nsIID, m2);
                     iid.m2 = XPT_SWAB16(*((PRUint16 *)ptr));
                     ptr = ((unsigned char *)buf) + offsetof(nsIID, m3);
                     for (int i=0;i<8;i++) {
                            iid.m3[i] = *((PRUint8 *)ptr);
                            ptr += sizeof(PRUint8);
                     }
                     return new Py_nsIID(iid);
              }
       }
       PyErr_Clear();
       // @pyparm string/Unicode|iidString||A string representation of an IID, or a ContractID.
       if ( !PyArg_ParseTuple(args, "O", &obIID) )
              return NULL;

       nsIID iid;
       if (!Py_nsIID::IIDFromPyObject(obIID, &iid))
              return NULL;
       return new Py_nsIID(iid);
}

Variable Documentation

PyMethods_IInterfaceInfoManager PyMethods_ISimpleEnumerator PyMethods_IInputStream PyMethods_IVariant nsIFile* location

Definition at line 95 of file xpcom.cpp.

PyMethods_IInterfaceInfoManager PyMethods_ISimpleEnumerator nsIInputStream

Definition at line 85 of file xpcom.cpp.

Definition at line 81 of file xpcom.cpp.

Definition at line 83 of file xpcom.cpp.

PyMethods_IInterfaceInfoManager PyMethods_ISimpleEnumerator PyMethods_IInputStream nsIVariant

Definition at line 87 of file xpcom.cpp.

struct PyMethodDef[] [static]
Initial value:
{
       {"GetComponentManager", PyXPCOMMethod_GetComponentManager, 1},
       {"NS_GetGlobalComponentManager", PyXPCOMMethod_NS_GetGlobalComponentManager, 1}, 
       {"XPTI_GetInterfaceInfoManager", PyXPCOMMethod_XPTI_GetInterfaceInfoManager, 1},
       {"XPTC_InvokeByIndex", PyXPCOMMethod_XPTC_InvokeByIndex, 1},
       {"GetServiceManager", PyXPCOMMethod_GetServiceManager, 1},
       {"GetGlobalServiceManager", PyXPCOMMethod_GetGlobalServiceManager, 1}, 
       {"IID", PyXPCOMMethod_IID, 1}, 
       {"ID", PyXPCOMMethod_IID, 1}, 
       {"NS_ShutdownXPCOM", PyXPCOMMethod_NS_ShutdownXPCOM, 1},
       {"WrapObject", PyXPCOMMethod_WrapObject, 1},
       {"UnwrapObject", PyXPCOMMethod_UnwrapObject, 1},
       {"_GetInterfaceCount", PyXPCOMMethod_GetInterfaceCount, 1},
       {"_GetGatewayCount", PyXPCOMMethod_GetGatewayCount, 1},
       {"getProxyForObject", PyXPCOMMethod_GetProxyForObject, 1},
       {"GetProxyForObject", PyXPCOMMethod_GetProxyForObject, 1},
       {"GetSpecialDirectory", PyGetSpecialDirectory, 1},
       {"AllocateBuffer", AllocateBuffer, 1},
       {"LogWarning", LogWarning, 1},
       {"LogError", LogError, 1},
       { NULL }
}

Definition at line 469 of file xpcom.cpp.

Definition at line 68 of file xpcom.cpp.