Skip to content

Commit 2301960

Browse files
committed
Added TypeHeaderCode for QgsServerFiltersMap
1 parent cf2f6b1 commit 2301960

File tree

2 files changed

+129
-2
lines changed

2 files changed

+129
-2
lines changed

python/server/qgsserverinterface.sip

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,130 @@
3131

3232
typedef QMultiMap<int, QgsServerFilter*> QgsServerFiltersMap;
3333

34+
35+
36+
template<int, TYPE2*>
37+
%MappedType QMultiMap<int, TYPE2*>
38+
{
39+
%TypeHeaderCode
40+
#include <QMultiMap>
41+
%End
42+
43+
%ConvertFromTypeCode
44+
// Create the dictionary.
45+
PyObject *d = PyDict_New();
46+
47+
if (!d)
48+
return NULL;
49+
50+
// Set the dictionary elements.
51+
QMultiMap<int, TYPE2*>::iterator i = sipCpp->begin();
52+
53+
while (i != sipCpp->end())
54+
{
55+
56+
const int t1 = i.key();
57+
TYPE2 * t2 = i.value();
58+
PyObject *t1obj = PyInt_FromSize_t(t1);
59+
PyObject *t2obj = sipConvertFromType(t2, sipType_TYPE2, sipTransferObj);
60+
///////PyObject *t2obj = sipConvertFromNewType(t2, sipType_TYPE2, sipTransferObj);
61+
if (PyDict_GetItem(d, t1obj) == NULL) {
62+
PyObject *lst = PyList_New(0);
63+
PyDict_SetItem(d, t1obj, lst);
64+
if (lst)
65+
{
66+
Py_DECREF(lst);
67+
}
68+
}
69+
70+
if (t1obj == NULL || t2obj == NULL ||
71+
PyList_Append(PyDict_GetItem(d, t1obj), t2obj) < 0)
72+
{
73+
Py_DECREF(d);
74+
if (t1obj)
75+
{
76+
Py_DECREF(t1obj);
77+
}
78+
79+
if (t2obj)
80+
{
81+
Py_DECREF(t2obj);
82+
}
83+
84+
return NULL;
85+
}
86+
Py_DECREF(t1obj);
87+
Py_DECREF(t2obj);
88+
89+
++i;
90+
}
91+
92+
return d;
93+
%End
94+
95+
%ConvertToTypeCode
96+
PyObject *t1obj, *t2obj;
97+
#if PY_VERSION_HEX >= 0x02050000
98+
Py_ssize_t i = 0;
99+
#else
100+
int i = 0;
101+
#endif
102+
103+
// Check the type if that is all that is required.
104+
if (sipIsErr == NULL)
105+
{
106+
if (!PyDict_Check(sipPy))
107+
return 0;
108+
109+
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
110+
{
111+
for (int i = 0; i < PyList_GET_SIZE(t2obj); ++i) {
112+
if (!sipCanConvertToType(PyList_GET_ITEM(t2obj, i),
113+
sipType_TYPE2, SIP_NOT_NONE))
114+
return 0;
115+
}
116+
}
117+
118+
return 1;
119+
}
120+
121+
QMultiMap<int, TYPE2*> *qm = new QMultiMap<int, TYPE2*>;
122+
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
123+
{
124+
int state2;
125+
int k = (int) PyInt_AsLong(t1obj);
126+
for (int i = 0; i < PyList_GET_SIZE(t2obj); ++i) {
127+
TYPE2 *t2 =
128+
reinterpret_cast<TYPE2 *>(sipConvertToType(PyList_GET_ITEM(t2obj, i),
129+
sipType_TYPE2,
130+
sipTransferObj,
131+
SIP_NOT_NONE,
132+
&state2,
133+
sipIsErr));
134+
135+
if (*sipIsErr)
136+
{
137+
sipReleaseType(t2, sipType_TYPE2, state2);
138+
139+
delete qm;
140+
return 0;
141+
}
142+
143+
qm->insert(k, t2);
144+
145+
sipReleaseType(t2, sipType_TYPE2, state2);
146+
}
147+
}
148+
149+
*sipCppPtr = qm;
150+
151+
return sipGetState(sipTransferObj);
152+
%End
153+
};
154+
155+
156+
157+
34158
class QgsServerInterface
35159
{
36160
%TypeHeaderCode
@@ -50,7 +174,7 @@ class QgsServerInterface
50174
virtual QString getEnv(const QString& name ) const = 0;
51175
// Commented because of problems with typedef QgsServerFiltersMap, provided
52176
// methods to alter the filters map into QgsRequestHandler API
53-
// virtual QgsServerFiltersMap filters( ) = 0;
177+
virtual QgsServerFiltersMap filters( ) = 0;
54178
/** Returns the configFilePath as seen by the server, this value is only
55179
* available after requestReady has been called.*/
56180
virtual QString configFilePath( ) = 0;

tests/src/python/test_qgsserver.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ def responseComplete(self):
9595

9696

9797
serverIface = self.server.serverInterface()
98-
serverIface.registerFilter(SimpleHelloFilter(serverIface), 100 )
98+
filter = SimpleHelloFilter(serverIface)
99+
serverIface.registerFilter(filter, 100 )
100+
# Get registered filters
101+
self.assertEqual(filter, serverIface.filters()[100][0])
99102
response = str(self.server.handleRequest('service=simple'))
100103
expected = 'Content-type: text/plain\n\nHello from SimpleServer!'
101104
self.assertEqual(response, expected)

0 commit comments

Comments
 (0)