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