Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added TypeHeaderCode for QgsServerFiltersMap
  • Loading branch information
elpaso committed Aug 4, 2015
1 parent cf2f6b1 commit 2301960
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 2 deletions.
126 changes: 125 additions & 1 deletion python/server/qgsserverinterface.sip
Expand Up @@ -31,6 +31,130 @@

typedef QMultiMap<int, QgsServerFilter*> QgsServerFiltersMap;



template<int, TYPE2*>
%MappedType QMultiMap<int, TYPE2*>
{
%TypeHeaderCode
#include <QMultiMap>
%End

%ConvertFromTypeCode
// Create the dictionary.
PyObject *d = PyDict_New();

if (!d)
return NULL;

// Set the dictionary elements.
QMultiMap<int, TYPE2*>::iterator i = sipCpp->begin();

while (i != sipCpp->end())
{

const int t1 = i.key();
TYPE2 * t2 = i.value();
PyObject *t1obj = PyInt_FromSize_t(t1);
PyObject *t2obj = sipConvertFromType(t2, sipType_TYPE2, sipTransferObj);
///////PyObject *t2obj = sipConvertFromNewType(t2, sipType_TYPE2, sipTransferObj);
if (PyDict_GetItem(d, t1obj) == NULL) {
PyObject *lst = PyList_New(0);
PyDict_SetItem(d, t1obj, lst);
if (lst)
{
Py_DECREF(lst);
}
}

if (t1obj == NULL || t2obj == NULL ||
PyList_Append(PyDict_GetItem(d, t1obj), t2obj) < 0)
{
Py_DECREF(d);
if (t1obj)
{
Py_DECREF(t1obj);
}

if (t2obj)
{
Py_DECREF(t2obj);
}

return NULL;
}
Py_DECREF(t1obj);
Py_DECREF(t2obj);

++i;
}

return d;
%End

%ConvertToTypeCode
PyObject *t1obj, *t2obj;
#if PY_VERSION_HEX >= 0x02050000
Py_ssize_t i = 0;
#else
int i = 0;
#endif

// Check the type if that is all that is required.
if (sipIsErr == NULL)
{
if (!PyDict_Check(sipPy))
return 0;

while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
{
for (int i = 0; i < PyList_GET_SIZE(t2obj); ++i) {
if (!sipCanConvertToType(PyList_GET_ITEM(t2obj, i),
sipType_TYPE2, SIP_NOT_NONE))
return 0;
}
}

return 1;
}

QMultiMap<int, TYPE2*> *qm = new QMultiMap<int, TYPE2*>;
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
{
int state2;
int k = (int) PyInt_AsLong(t1obj);
for (int i = 0; i < PyList_GET_SIZE(t2obj); ++i) {
TYPE2 *t2 =
reinterpret_cast<TYPE2 *>(sipConvertToType(PyList_GET_ITEM(t2obj, i),
sipType_TYPE2,
sipTransferObj,
SIP_NOT_NONE,
&state2,
sipIsErr));

if (*sipIsErr)
{
sipReleaseType(t2, sipType_TYPE2, state2);

delete qm;
return 0;
}

qm->insert(k, t2);

sipReleaseType(t2, sipType_TYPE2, state2);
}
}

*sipCppPtr = qm;

return sipGetState(sipTransferObj);
%End
};




class QgsServerInterface
{
%TypeHeaderCode
Expand All @@ -50,7 +174,7 @@ class QgsServerInterface
virtual QString getEnv(const QString& name ) const = 0;
// Commented because of problems with typedef QgsServerFiltersMap, provided
// methods to alter the filters map into QgsRequestHandler API
// virtual QgsServerFiltersMap filters( ) = 0;
virtual QgsServerFiltersMap filters( ) = 0;
/** Returns the configFilePath as seen by the server, this value is only
* available after requestReady has been called.*/
virtual QString configFilePath( ) = 0;
Expand Down
5 changes: 4 additions & 1 deletion tests/src/python/test_qgsserver.py
Expand Up @@ -95,7 +95,10 @@ def responseComplete(self):


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

0 comments on commit 2301960

Please sign in to comment.