1 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
3 | *
|
---|
4 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
5 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
6 | * the License. You may obtain a copy of the License at
|
---|
7 | * http://www.mozilla.org/MPL/
|
---|
8 | *
|
---|
9 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
11 | * for the specific language governing rights and limitations under the
|
---|
12 | * License.
|
---|
13 | *
|
---|
14 | * The Original Code is the Python XPCOM language bindings.
|
---|
15 | *
|
---|
16 | * The Initial Developer of the Original Code is
|
---|
17 | * ActiveState Tool Corp.
|
---|
18 | * Portions created by the Initial Developer are Copyright (C) 2000
|
---|
19 | * the Initial Developer. All Rights Reserved.
|
---|
20 | *
|
---|
21 | * Contributor(s):
|
---|
22 | * Mark Hammond <mhammond@skippinet.com.au> (original author)
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | //
|
---|
39 | // This code is part of the XPCOM extensions for Python.
|
---|
40 | //
|
---|
41 | // Written May 2000 by Mark Hammond.
|
---|
42 | //
|
---|
43 | // Based heavily on the Python COM support, which is
|
---|
44 | // (c) Mark Hammond and Greg Stein.
|
---|
45 | //
|
---|
46 | // (c) 2000, ActiveState corp.
|
---|
47 |
|
---|
48 | #include "PyXPCOM_std.h"
|
---|
49 |
|
---|
50 | static nsIComponentManagerObsolete *GetI(PyObject *self) {
|
---|
51 | static const nsIID iid = NS_GET_IID(nsIComponentManagerObsolete);
|
---|
52 |
|
---|
53 | if (!Py_nsISupports::Check(self, iid)) {
|
---|
54 | PyErr_SetString(PyExc_TypeError, "This object is not the correct interface");
|
---|
55 | return NULL;
|
---|
56 | }
|
---|
57 | return (nsIComponentManagerObsolete *)Py_nsISupports::GetI(self);
|
---|
58 | }
|
---|
59 |
|
---|
60 | static PyObject *PyCreateInstanceByContractID(PyObject *self, PyObject *args)
|
---|
61 | {
|
---|
62 | char *pid, *notyet = NULL;
|
---|
63 | PyObject *obIID = NULL;
|
---|
64 | if (!PyArg_ParseTuple(args, "s|zO", &pid, ¬yet, &obIID))
|
---|
65 | return NULL;
|
---|
66 | if (notyet != NULL) {
|
---|
67 | PyErr_SetString(PyExc_ValueError, "2nd arg must be none");
|
---|
68 | return NULL;
|
---|
69 | }
|
---|
70 | nsIComponentManagerObsolete *pI = GetI(self);
|
---|
71 | if (pI==NULL)
|
---|
72 | return NULL;
|
---|
73 |
|
---|
74 | nsIID iid;
|
---|
75 | if (obIID==NULL)
|
---|
76 | iid = NS_GET_IID(nsISupports);
|
---|
77 | else
|
---|
78 | if (!Py_nsIID::IIDFromPyObject(obIID, &iid))
|
---|
79 | return NULL;
|
---|
80 |
|
---|
81 | nsISupports *pis;
|
---|
82 | nsresult r;
|
---|
83 | Py_BEGIN_ALLOW_THREADS;
|
---|
84 | r = pI->CreateInstanceByContractID(pid, NULL, iid, (void **)&pis);
|
---|
85 | Py_END_ALLOW_THREADS;
|
---|
86 | if ( NS_FAILED(r) )
|
---|
87 | return PyXPCOM_BuildPyException(r);
|
---|
88 |
|
---|
89 | /* Return a type based on the IID (with no extra ref) */
|
---|
90 | return Py_nsISupports::PyObjectFromInterface(pis, iid, PR_FALSE, PR_FALSE);
|
---|
91 | }
|
---|
92 |
|
---|
93 | static PyObject *PyContractIDToClassID(PyObject *self, PyObject *args)
|
---|
94 | {
|
---|
95 | char *pid;
|
---|
96 | if (!PyArg_ParseTuple(args, "s", &pid))
|
---|
97 | return NULL;
|
---|
98 | nsIComponentManagerObsolete *pI = GetI(self);
|
---|
99 | if (pI==NULL)
|
---|
100 | return NULL;
|
---|
101 |
|
---|
102 | nsIID iid;
|
---|
103 | nsresult r;
|
---|
104 | Py_BEGIN_ALLOW_THREADS;
|
---|
105 | r = pI->ContractIDToClassID(pid, &iid);
|
---|
106 | Py_END_ALLOW_THREADS;
|
---|
107 | if ( NS_FAILED(r) )
|
---|
108 | return PyXPCOM_BuildPyException(r);
|
---|
109 |
|
---|
110 | return Py_nsIID::PyObjectFromIID(iid);
|
---|
111 | }
|
---|
112 |
|
---|
113 | static PyObject *PyCLSIDToContractID(PyObject *self, PyObject *args)
|
---|
114 | {
|
---|
115 | PyObject *obIID;
|
---|
116 | if (!PyArg_ParseTuple(args, "O", &obIID))
|
---|
117 | return NULL;
|
---|
118 |
|
---|
119 | nsIID iid;
|
---|
120 | if (!Py_nsIID::IIDFromPyObject(obIID, &iid))
|
---|
121 | return NULL;
|
---|
122 | char *ret_pid = nsnull;
|
---|
123 | char *ret_class = nsnull;
|
---|
124 | nsIComponentManagerObsolete *pI = GetI(self);
|
---|
125 | if (pI==NULL)
|
---|
126 | return NULL;
|
---|
127 |
|
---|
128 | nsresult r;
|
---|
129 | Py_BEGIN_ALLOW_THREADS;
|
---|
130 | r = pI->CLSIDToContractID(iid, &ret_class, &ret_pid);
|
---|
131 | Py_END_ALLOW_THREADS;
|
---|
132 | if ( NS_FAILED(r) )
|
---|
133 | return PyXPCOM_BuildPyException(r);
|
---|
134 |
|
---|
135 | #if PY_MAJOR_VERSION <= 2
|
---|
136 | PyObject *ob_pid = PyString_FromString(ret_pid);
|
---|
137 | PyObject *ob_class = PyString_FromString(ret_class);
|
---|
138 | #else
|
---|
139 | PyObject *ob_pid = PyUnicode_FromString(ret_pid);
|
---|
140 | PyObject *ob_class = PyUnicode_FromString(ret_class);
|
---|
141 | #endif
|
---|
142 | PyObject *ret = Py_BuildValue("OO", ob_pid, ob_class);
|
---|
143 | nsMemory::Free(ret_pid);
|
---|
144 | nsMemory::Free(ret_class);
|
---|
145 | Py_XDECREF(ob_pid);
|
---|
146 | Py_XDECREF(ob_class);
|
---|
147 | return ret;
|
---|
148 | }
|
---|
149 |
|
---|
150 | static PyObject *PyEnumerateCLSIDs(PyObject *self, PyObject *args)
|
---|
151 | {
|
---|
152 | if (!PyArg_ParseTuple(args, ""))
|
---|
153 | return NULL;
|
---|
154 |
|
---|
155 | nsIComponentManagerObsolete *pI = GetI(self);
|
---|
156 | if (pI==NULL)
|
---|
157 | return NULL;
|
---|
158 |
|
---|
159 | nsIEnumerator *pRet;
|
---|
160 | nsresult r;
|
---|
161 | Py_BEGIN_ALLOW_THREADS;
|
---|
162 | r = pI->EnumerateCLSIDs(&pRet);
|
---|
163 | Py_END_ALLOW_THREADS;
|
---|
164 | if ( NS_FAILED(r) )
|
---|
165 | return PyXPCOM_BuildPyException(r);
|
---|
166 |
|
---|
167 | return Py_nsISupports::PyObjectFromInterface(pRet, NS_GET_IID(nsIEnumerator), PR_FALSE);
|
---|
168 | }
|
---|
169 |
|
---|
170 | static PyObject *PyEnumerateContractIDs(PyObject *self, PyObject *args)
|
---|
171 | {
|
---|
172 | if (!PyArg_ParseTuple(args, ""))
|
---|
173 | return NULL;
|
---|
174 |
|
---|
175 | nsIComponentManagerObsolete *pI = GetI(self);
|
---|
176 | if (pI==NULL)
|
---|
177 | return NULL;
|
---|
178 |
|
---|
179 | nsIEnumerator *pRet;
|
---|
180 | nsresult r;
|
---|
181 | Py_BEGIN_ALLOW_THREADS;
|
---|
182 | r = pI->EnumerateContractIDs(&pRet);
|
---|
183 | Py_END_ALLOW_THREADS;
|
---|
184 | if ( NS_FAILED(r) )
|
---|
185 | return PyXPCOM_BuildPyException(r);
|
---|
186 |
|
---|
187 | return Py_nsISupports::PyObjectFromInterface(pRet, NS_GET_IID(nsIEnumerator), PR_FALSE);
|
---|
188 | }
|
---|
189 |
|
---|
190 | struct PyMethodDef
|
---|
191 | PyMethods_IComponentManagerObsolete[] =
|
---|
192 | {
|
---|
193 | { "CreateInstanceByContractID", PyCreateInstanceByContractID, 1},
|
---|
194 | { "createInstanceByContractID", PyCreateInstanceByContractID, 1},
|
---|
195 | { "EnumerateCLSIDs", PyEnumerateCLSIDs, 1},
|
---|
196 | { "enumerateCLSIDs", PyEnumerateCLSIDs, 1},
|
---|
197 | { "EnumerateContractIDs", PyEnumerateContractIDs, 1},
|
---|
198 | { "enumerateContractIDs", PyEnumerateContractIDs, 1},
|
---|
199 | { "ContractIDToClassID", PyContractIDToClassID, 1},
|
---|
200 | { "contractIDToClassID", PyContractIDToClassID, 1},
|
---|
201 | { "CLSIDToContractID", PyCLSIDToContractID, 1},
|
---|
202 | {NULL}
|
---|
203 | };
|
---|