nsIComponentLoader is dead - long live nsIModuleLoader! Take the

opportunity to remove support for nsIComponentManagerObsolete, and
formalize a nice shutdown API.

Not part of the build.


git-svn-id: svn://10.0.0.236/trunk@186246 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mhammond%skippinet.com.au
2005-12-19 05:05:45 +00:00
parent d1179099dd
commit afc19f2f56
14 changed files with 123 additions and 551 deletions

View File

@@ -68,7 +68,6 @@ CPPSRCS= \
PyGWeakReference.cpp \
PyIClassInfo.cpp \
PyIComponentManager.cpp \
PyIComponentManagerObsolete.cpp \
PyIInputStream.cpp \
PyIEnumerator.cpp \
PyIID.cpp \

View File

@@ -48,7 +48,6 @@
#include "PyXPCOM_std.h"
#include <nsIModule.h>
#include <nsIComponentLoader.h>
#include <nsIInputStream.h>
static PRInt32 cGateways = 0;
@@ -58,7 +57,6 @@ PRInt32 _PyXPCOM_GetGatewayCount(void)
}
extern PyG_Base *MakePyG_nsIModule(PyObject *);
extern PyG_Base *MakePyG_nsIComponentLoader(PyObject *instance);
extern PyG_Base *MakePyG_nsIInputStream(PyObject *instance);
static char *PyXPCOM_szDefaultGatewayAttributeName = "_com_instance_default_gateway_";
@@ -77,8 +75,6 @@ PyG_Base::CreateNew(PyObject *pPyInstance, const nsIID &iid, void **ppResult)
// Hack for few extra gateways we support.
if (iid.Equals(NS_GET_IID(nsIModule)))
ret = MakePyG_nsIModule(pPyInstance);
else if (iid.Equals(NS_GET_IID(nsIComponentLoader)))
ret = MakePyG_nsIComponentLoader(pPyInstance);
else if (iid.Equals(NS_GET_IID(nsIInputStream)))
ret = MakePyG_nsIInputStream(pPyInstance);
else

View File

@@ -53,7 +53,7 @@
#include "PyXPCOM_std.h"
#include <nsIModule.h>
#include <nsIComponentLoader.h>
#include <nsIFile.h>
class PyG_nsIModule : public PyG_Base, public nsIModule
{
@@ -156,142 +156,3 @@ PyG_nsIModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
Py_XDECREF(ret);
return nr;
}
///////////////////////////////////////////////////////////////////////////////////
class PyG_nsIComponentLoader : public PyG_Base, public nsIComponentLoader
{
public:
PyG_nsIComponentLoader(PyObject *instance) : PyG_Base(instance, NS_GET_IID(nsIComponentLoader)) {;}
PYGATEWAY_BASE_SUPPORT(nsIComponentLoader, PyG_Base);
NS_DECL_NSICOMPONENTLOADER
};
PyG_Base *MakePyG_nsIComponentLoader(PyObject *instance)
{
return new PyG_nsIComponentLoader(instance);
}
/* nsIFactory getFactory (in nsIIDRef aCID, in string aLocation, in string aType); */
NS_IMETHODIMP PyG_nsIComponentLoader::GetFactory(const nsIID & aCID, const char *aLocation, const char *aType, nsIFactory **_retval)
{
CEnterLeavePython _celp;
const char *methodName = "getFactory";
PyObject *iid = Py_nsIID::PyObjectFromIID(aCID);
PyObject *ret = NULL;
nsresult nr = InvokeNativeViaPolicy(methodName, &ret, "Ozz",
iid,
aLocation,
aType);
Py_XDECREF(iid);
if (NS_SUCCEEDED(nr)) {
Py_nsISupports::InterfaceFromPyObject(ret, NS_GET_IID(nsIFactory), (nsISupports **)_retval, PR_FALSE);
if (PyErr_Occurred())
nr = HandleNativeGatewayError(methodName);
}
Py_XDECREF(ret);
return nr;
}
/* void init (in nsIComponentManager aCompMgr, in nsISupports aRegistry); */
NS_IMETHODIMP PyG_nsIComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aRegistry)
{
CEnterLeavePython _celp;
const char *methodName = "init";
PyObject *c = Py_nsISupports::PyObjectFromInterface(aCompMgr, NS_GET_IID(nsIComponentManager), PR_TRUE);
PyObject *r = Py_nsISupports::PyObjectFromInterface(aRegistry, NS_GET_IID(nsISupports), PR_TRUE);
nsresult nr = InvokeNativeViaPolicy(methodName, NULL, "OO", c, r);
Py_XDECREF(c);
Py_XDECREF(r);
return nr;
}
/* void onRegister (in nsIIDRef aCID, in string aType, in string aClassName, in string aContractID, in string aLocation, in boolean aReplace, in boolean aPersist); */
NS_IMETHODIMP PyG_nsIComponentLoader::OnRegister(const nsIID & aCID, const char *aType, const char *aClassName, const char *aContractID, const char *aLocation, PRBool aReplace, PRBool aPersist)
{
CEnterLeavePython _celp;
const char *methodName = "onRegister";
PyObject *iid = Py_nsIID::PyObjectFromIID(aCID);
nsresult nr = InvokeNativeViaPolicy(methodName, NULL, "Ossssii",
iid,
aType,
aClassName,
aContractID,
aLocation,
aReplace,
aPersist);
Py_XDECREF(iid);
return nr;
}
/* void autoRegisterComponents (in long aWhen, in nsIFile aDirectory); */
NS_IMETHODIMP PyG_nsIComponentLoader::AutoRegisterComponents(PRInt32 aWhen, nsIFile *aDirectory)
{
CEnterLeavePython _celp;
const char *methodName = "autoRegisterComponents";
PyObject *c = Py_nsISupports::PyObjectFromInterface(aDirectory, NS_GET_IID(nsIFile), PR_TRUE);
nsresult nr = InvokeNativeViaPolicy(methodName, NULL, "iO", aWhen, c);
Py_XDECREF(c);
return nr;
}
/* boolean autoRegisterComponent (in long aWhen, in nsIFile aComponent); */
NS_IMETHODIMP PyG_nsIComponentLoader::AutoRegisterComponent(PRInt32 aWhen, nsIFile *aComponent, PRBool *_retval)
{
CEnterLeavePython _celp;
const char *methodName = "autoRegisterComponent";
PyObject *ret = NULL;
PyObject *c = Py_nsISupports::PyObjectFromInterface(aComponent, NS_GET_IID(nsIFile), PR_TRUE);
nsresult nr = InvokeNativeViaPolicy(methodName, &ret, "iO", aWhen, c);
Py_XDECREF(c);
if (NS_SUCCEEDED(nr)) {
*_retval = PyInt_AsLong(ret);
if (PyErr_Occurred())
nr = HandleNativeGatewayError(methodName);
}
Py_XDECREF(ret);
return nr;
}
/* boolean autoUnregisterComponent (in long aWhen, in nsIFile aComponent); */
NS_IMETHODIMP PyG_nsIComponentLoader::AutoUnregisterComponent(PRInt32 aWhen, nsIFile *aComponent, PRBool *_retval)
{
CEnterLeavePython _celp;
const char *methodName = "autoUnregisterComponent";
PyObject *ret = NULL;
PyObject *c = Py_nsISupports::PyObjectFromInterface(aComponent, NS_GET_IID(nsIFile), PR_TRUE);
nsresult nr = InvokeNativeViaPolicy(methodName, &ret, "iO", aWhen, c);
Py_XDECREF(c);
if (NS_SUCCEEDED(nr)) {
*_retval = PyInt_AsLong(ret);
if (PyErr_Occurred())
nr = HandleNativeGatewayError(methodName);
}
Py_XDECREF(ret);
return nr;
}
/* boolean registerDeferredComponents (in long aWhen); */
NS_IMETHODIMP PyG_nsIComponentLoader::RegisterDeferredComponents(PRInt32 aWhen, PRBool *_retval)
{
CEnterLeavePython _celp;
const char *methodName = "registerDeferredComponents";
PyObject *ret = NULL;
nsresult nr = InvokeNativeViaPolicy(methodName, &ret, "i", aWhen);
if (NS_SUCCEEDED(nr)) {
*_retval = PyInt_AsLong(ret);
if (PyErr_Occurred())
nr = HandleNativeGatewayError(methodName);
}
Py_XDECREF(ret);
return nr;
}
/* void unloadAll (in long aWhen); */
NS_IMETHODIMP PyG_nsIComponentLoader::UnloadAll(PRInt32 aWhen)
{
CEnterLeavePython _celp;
const char *methodName = "unloadAll";
return InvokeNativeViaPolicy(methodName, NULL, "i", aWhen);
}

View File

@@ -1,198 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Python XPCOM language bindings.
*
* The Initial Developer of the Original Code is
* ActiveState Tool Corp.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mark Hammond <mhammond@skippinet.com.au> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
//
// 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 nsIComponentManagerObsolete *GetI(PyObject *self) {
static const nsIID iid = NS_GET_IID(nsIComponentManagerObsolete);
if (!Py_nsISupports::Check(self, iid)) {
PyErr_SetString(PyExc_TypeError, "This object is not the correct interface");
return NULL;
}
return (nsIComponentManagerObsolete *)Py_nsISupports::GetI(self);
}
static PyObject *PyCreateInstanceByContractID(PyObject *self, PyObject *args)
{
char *pid, *notyet = NULL;
PyObject *obIID = NULL;
if (!PyArg_ParseTuple(args, "s|zO", &pid, &notyet, &obIID))
return NULL;
if (notyet != NULL) {
PyErr_SetString(PyExc_ValueError, "2nd arg must be none");
return NULL;
}
nsIComponentManagerObsolete *pI = GetI(self);
if (pI==NULL)
return NULL;
nsIID iid;
if (obIID==NULL)
iid = NS_GET_IID(nsISupports);
else
if (!Py_nsIID::IIDFromPyObject(obIID, &iid))
return NULL;
nsISupports *pis;
nsresult r;
Py_BEGIN_ALLOW_THREADS;
r = pI->CreateInstanceByContractID(pid, NULL, iid, (void **)&pis);
Py_END_ALLOW_THREADS;
if ( NS_FAILED(r) )
return PyXPCOM_BuildPyException(r);
/* Return a type based on the IID (with no extra ref) */
return Py_nsISupports::PyObjectFromInterface(pis, iid, PR_FALSE, PR_FALSE);
}
static PyObject *PyContractIDToClassID(PyObject *self, PyObject *args)
{
char *pid;
if (!PyArg_ParseTuple(args, "s", &pid))
return NULL;
nsIComponentManagerObsolete *pI = GetI(self);
if (pI==NULL)
return NULL;
nsIID iid;
nsresult r;
Py_BEGIN_ALLOW_THREADS;
r = pI->ContractIDToClassID(pid, &iid);
Py_END_ALLOW_THREADS;
if ( NS_FAILED(r) )
return PyXPCOM_BuildPyException(r);
return Py_nsIID::PyObjectFromIID(iid);
}
static PyObject *PyCLSIDToContractID(PyObject *self, PyObject *args)
{
PyObject *obIID;
if (!PyArg_ParseTuple(args, "O", &obIID))
return NULL;
nsIID iid;
if (!Py_nsIID::IIDFromPyObject(obIID, &iid))
return NULL;
char *ret_pid = nsnull;
char *ret_class = nsnull;
nsIComponentManagerObsolete *pI = GetI(self);
if (pI==NULL)
return NULL;
nsresult r;
Py_BEGIN_ALLOW_THREADS;
r = pI->CLSIDToContractID(iid, &ret_class, &ret_pid);
Py_END_ALLOW_THREADS;
if ( NS_FAILED(r) )
return PyXPCOM_BuildPyException(r);
PyObject *ob_pid = PyString_FromString(ret_pid);
PyObject *ob_class = PyString_FromString(ret_class);
PyObject *ret = Py_BuildValue("OO", ob_pid, ob_class);
nsMemory::Free(ret_pid);
nsMemory::Free(ret_class);
Py_XDECREF(ob_pid);
Py_XDECREF(ob_class);
return ret;
}
static PyObject *PyEnumerateCLSIDs(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
nsIComponentManagerObsolete *pI = GetI(self);
if (pI==NULL)
return NULL;
nsIEnumerator *pRet;
nsresult r;
Py_BEGIN_ALLOW_THREADS;
r = pI->EnumerateCLSIDs(&pRet);
Py_END_ALLOW_THREADS;
if ( NS_FAILED(r) )
return PyXPCOM_BuildPyException(r);
return Py_nsISupports::PyObjectFromInterface(pRet, NS_GET_IID(nsIEnumerator), PR_FALSE);
}
static PyObject *PyEnumerateContractIDs(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
nsIComponentManagerObsolete *pI = GetI(self);
if (pI==NULL)
return NULL;
nsIEnumerator *pRet;
nsresult r;
Py_BEGIN_ALLOW_THREADS;
r = pI->EnumerateContractIDs(&pRet);
Py_END_ALLOW_THREADS;
if ( NS_FAILED(r) )
return PyXPCOM_BuildPyException(r);
return Py_nsISupports::PyObjectFromInterface(pRet, NS_GET_IID(nsIEnumerator), PR_FALSE);
}
struct PyMethodDef
PyMethods_IComponentManagerObsolete[] =
{
{ "CreateInstanceByContractID", PyCreateInstanceByContractID, 1},
{ "createInstanceByContractID", PyCreateInstanceByContractID, 1},
{ "EnumerateCLSIDs", PyEnumerateCLSIDs, 1},
{ "enumerateCLSIDs", PyEnumerateCLSIDs, 1},
{ "EnumerateContractIDs", PyEnumerateContractIDs, 1},
{ "enumerateContractIDs", PyEnumerateContractIDs, 1},
{ "ContractIDToClassID", PyContractIDToClassID, 1},
{ "contractIDToClassID", PyContractIDToClassID, 1},
{ "CLSIDToContractID", PyCLSIDToContractID, 1},
{NULL}
};

View File

@@ -102,7 +102,6 @@ PyXPCOM_TypeObject::Py_setattr(PyObject *op, char *name, PyObject *v)
/*static*/int
PyXPCOM_TypeObject::Py_cmp(PyObject *self, PyObject *other)
{
// @comm NOTE: Copied from COM - have not confirmed these rules are true for XPCOM
// @comm As per the XPCOM rules for object identity, both objects are queried for nsISupports, and these values compared.
// The only meaningful test is for equality - the result of other comparisons is undefined
// (ie, determined by the object's relative addresses in memory.

View File

@@ -49,7 +49,6 @@
#undef HAVE_LONG_LONG
#endif
#include "nsIComponentLoader.h"
#include "nsISupports.h"
#include "nsIModule.h"
#include "nsDirectoryServiceDefs.h"

View File

@@ -53,7 +53,6 @@
#include "nsIFile.h"
#include "nsILocalFile.h"
#include "nsIComponentRegistrar.h"
#include "nsIComponentManagerObsolete.h"
#ifdef XP_WIN
#ifndef WIN32_LEAN_AND_MEAN
@@ -85,8 +84,6 @@ PyXPCOM_INTERFACE_DEFINE(Py_nsIInterfaceInfo, nsIInterfaceInfo, PyMethods_IInter
PyXPCOM_INTERFACE_DEFINE(Py_nsIInputStream, nsIInputStream, PyMethods_IInputStream)
PyXPCOM_INTERFACE_DEFINE(Py_nsIClassInfo, nsIClassInfo, PyMethods_IClassInfo)
PyXPCOM_INTERFACE_DEFINE(Py_nsIVariant, nsIVariant, PyMethods_IVariant)
// deprecated, but retained for backward compatibility:
PyXPCOM_INTERFACE_DEFINE(Py_nsIComponentManagerObsolete, nsIComponentManagerObsolete, PyMethods_IComponentManagerObsolete)
////////////////////////////////////////////////////////////
// This is the main entry point called by the Python component
@@ -149,29 +146,6 @@ done:
// "boot-strap" methods - interfaces we need to get the base
// interface support!
/* deprecated, included for backward compatibility */
static PyObject *
PyXPCOMMethod_NS_GetGlobalComponentManager(PyObject *self, PyObject *args)
{
if (PyErr_Warn(PyExc_DeprecationWarning, "Use GetComponentManager instead") < 0)
return NULL;
if (!PyArg_ParseTuple(args, ""))
return NULL;
nsIComponentManager* cm;
nsresult rv;
Py_BEGIN_ALLOW_THREADS;
rv = NS_GetComponentManager(&cm);
Py_END_ALLOW_THREADS;
if ( NS_FAILED(rv) )
return PyXPCOM_BuildPyException(rv);
nsCOMPtr<nsIComponentManagerObsolete> ocm(do_QueryInterface(cm, &rv));
if ( NS_FAILED(rv) )
return PyXPCOM_BuildPyException(rv);
return Py_nsISupports::PyObjectFromInterface(cm, NS_GET_IID(nsIComponentManagerObsolete), PR_FALSE, PR_FALSE);
}
static PyObject *
PyXPCOMMethod_GetComponentManager(PyObject *self, PyObject *args)
{
@@ -205,16 +179,6 @@ PyXPCOMMethod_GetServiceManager(PyObject *self, PyObject *args)
return Py_nsISupports::PyObjectFromInterface(sm, NS_GET_IID(nsIServiceManager), PR_FALSE);
}
/* deprecated, included for backward compatibility */
static PyObject *
PyXPCOMMethod_GetGlobalServiceManager(PyObject *self, PyObject *args)
{
if (PyErr_Warn(PyExc_DeprecationWarning, "Use GetServiceManager instead") < 0)
return NULL;
return PyXPCOMMethod_GetComponentManager(self, args);
}
static PyObject *
PyXPCOMMethod_XPTI_GetInterfaceInfoManager(PyObject *self, PyObject *args)
{
@@ -467,11 +431,9 @@ extern PyObject *PyXPCOMMethod_IID(PyObject *self, PyObject *args);
static struct PyMethodDef xpcom_methods[]=
{
{"GetComponentManager", PyXPCOMMethod_GetComponentManager, 1},
{"NS_GetGlobalComponentManager", PyXPCOMMethod_NS_GetGlobalComponentManager, 1}, // deprecated
{"XPTI_GetInterfaceInfoManager", PyXPCOMMethod_XPTI_GetInterfaceInfoManager, 1},
{"XPTC_InvokeByIndex", PyXPCOMMethod_XPTC_InvokeByIndex, 1},
{"GetServiceManager", PyXPCOMMethod_GetServiceManager, 1},
{"GetGlobalServiceManager", PyXPCOMMethod_GetGlobalServiceManager, 1}, // deprecated
{"IID", PyXPCOMMethod_IID, 1}, // IID is wrong - deprecated - not just IID, but CID, etc.
{"ID", PyXPCOMMethod_IID, 1}, // This is the official name.
{"NS_ShutdownXPCOM", PyXPCOMMethod_NS_ShutdownXPCOM, 1},
@@ -628,8 +590,6 @@ init_xpcom() {
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);