Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
PyGBase.cpp File Reference
#include "PyXPCOM_std.h"
#include <nsIModule.h>
#include <nsIComponentLoader.h>
#include <nsIInputStream.h>

Go to the source code of this file.

Functions

PRInt32 _PyXPCOM_GetGatewayCount (void)
PyG_Base * MakePyG_nsIModule (PyObject *)
PyG_Base * MakePyG_nsIComponentLoader (PyObject *instance)
PyG_Base * MakePyG_nsIInputStream (PyObject *instance)
PyG_Base * GetDefaultGateway (PyObject *instance)
void AddDefaultGateway (PyObject *instance, nsISupports *gateway)
PRBool CheckDefaultGateway (PyObject *real_inst, REFNSIID iid, nsISupports **ret_gateway)
static nsresult do_dispatch (PyObject *pPyObject, PyObject **ppResult, const char *szMethodName, const char *szFormat, va_list va)

Variables

static PRInt32 cGateways = 0
static char * PyXPCOM_szDefaultGatewayAttributeName = "_com_instance_default_gateway_"

Function Documentation

Definition at line 55 of file PyGBase.cpp.

{
       return cGateways;
}
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:

PRBool CheckDefaultGateway ( PyObject *  real_inst,
REFNSIID  iid,
nsISupports **  ret_gateway 
)

Definition at line 764 of file PyGBase.cpp.

{
       NS_ABORT_IF_FALSE(real_inst, "Did not have an _obj_ attribute");
       if (real_inst==NULL) {
              PyErr_Clear();
              return PR_FALSE;
       }
       PyObject *ob_existing_weak = PyObject_GetAttrString(real_inst, PyXPCOM_szDefaultGatewayAttributeName);
       if (ob_existing_weak != NULL) {
              // We have an existing default, but as it is a weak reference, it
              // may no longer be valid.  Check it.
              PRBool ok = PR_TRUE;
              nsCOMPtr<nsIWeakReference> pWeakRef;
              ok = NS_SUCCEEDED(Py_nsISupports::InterfaceFromPyObject(ob_existing_weak, 
                                                     NS_GET_IID(nsIWeakReference), 
                                                     getter_AddRefs(pWeakRef), 
                                                     PR_FALSE));
              Py_DECREF(ob_existing_weak);
              if (ok) {
                     Py_BEGIN_ALLOW_THREADS;
                     ok = NS_SUCCEEDED(pWeakRef->QueryReferent( iid, (void **)(ret_gateway)));
                     Py_END_ALLOW_THREADS;
              }
              if (!ok) {
                     // We have the attribute, but not valid - wipe it
                     // before restoring it.
                     if (0 != PyObject_DelAttrString(real_inst, PyXPCOM_szDefaultGatewayAttributeName))
                            PyErr_Clear();
              }
              return ok;
       }
       PyErr_Clear();
       return PR_FALSE;
}

Here is the call graph for this function:

static nsresult do_dispatch ( PyObject *  pPyObject,
PyObject **  ppResult,
const char *  szMethodName,
const char *  szFormat,
va_list  va 
) [static]

Definition at line 500 of file PyGBase.cpp.

{
       NS_PRECONDITION(ppResult, "Must provide a result buffer");
       *ppResult = nsnull;
       // Build the Invoke arguments...
       PyObject *args = NULL;
       PyObject *method = NULL;
       PyObject *real_ob = NULL;
       nsresult ret = NS_ERROR_FAILURE;
       if ( szFormat )
              args = Py_VaBuildValue((char *)szFormat, va);
       else
              args = PyTuple_New(0);
       if ( !args )
              goto done;

       // make sure a tuple.
       if ( !PyTuple_Check(args) ) {
              PyObject *a = PyTuple_New(1);
              if ( a == NULL )
              {
                     Py_DECREF(args);
                     goto done;
              }
              PyTuple_SET_ITEM(a, 0, args);
              args = a;
       }
       // Bit to a hack here to maintain the use of a policy.
       // We actually get the policies underlying object
       // to make the call on.
       real_ob = PyObject_GetAttrString(pPyObject, "_obj_");
       if (real_ob == NULL) {
              PyErr_Format(PyExc_AttributeError, "The policy object does not have an '_obj_' attribute.");
              goto done;
       }
       method = PyObject_GetAttrString(real_ob, (char *)szMethodName);
       if ( !method ) {
              PyErr_Clear();
              ret = NS_PYXPCOM_NO_SUCH_METHOD;
              goto done;
       }
       // Make the call
       *ppResult = PyEval_CallObject(method, args);
       ret = *ppResult ? NS_OK : NS_ERROR_FAILURE;
done:
       Py_XDECREF(method);
       Py_XDECREF(real_ob);
       Py_XDECREF(args);
       return ret;
}

Here is the call graph for this function:

PyG_Base * GetDefaultGateway ( PyObject *  instance)

Definition at line 736 of file PyGBase.cpp.

{
       // NOTE: Instance is the policy, not the real instance
       PyObject *instance = PyObject_GetAttrString(policy, "_obj_");
       if (instance == nsnull)
              return nsnull;
       PyObject *ob_existing_weak = PyObject_GetAttrString(instance, PyXPCOM_szDefaultGatewayAttributeName);
       Py_DECREF(instance);
       if (ob_existing_weak != NULL) {
              PRBool ok = PR_TRUE;
              nsCOMPtr<nsIWeakReference> pWeakRef;
              ok = NS_SUCCEEDED(Py_nsISupports::InterfaceFromPyObject(ob_existing_weak, 
                                                     NS_GET_IID(nsIWeakReference), 
                                                     getter_AddRefs(pWeakRef),
                                                     PR_FALSE));
              Py_DECREF(ob_existing_weak);
              nsISupports *pip;
              if (ok) {
                     nsresult nr = pWeakRef->QueryReferent( NS_GET_IID(nsIInternalPython), (void **)&pip);
                     if (NS_FAILED(nr))
                            return nsnull;
                     return (PyG_Base *)(nsIInternalPython *)pip;
              }
       } else
              PyErr_Clear();
       return nsnull;
}

Here is the call graph for this function:

PyG_Base* MakePyG_nsIComponentLoader ( PyObject *  instance)

Definition at line 171 of file PyGModule.cpp.

{
       return new PyG_nsIComponentLoader(instance);
}
PyG_Base* MakePyG_nsIInputStream ( PyObject *  instance)

Definition at line 66 of file PyGInputStream.cpp.

{
       return new PyG_nsIInputStream(instance);
}
PyG_Base* MakePyG_nsIModule ( PyObject *  )

Definition at line 67 of file PyGModule.cpp.

{
       return new PyG_nsIModule(instance);
}

Variable Documentation

PRInt32 cGateways = 0 [static]

Definition at line 54 of file PyGBase.cpp.

char* PyXPCOM_szDefaultGatewayAttributeName = "_com_instance_default_gateway_" [static]

Definition at line 64 of file PyGBase.cpp.