From 90825e2392b2d70e43c7a25b8a3752299a933894 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- dcoppython/shell/marshal_funcs.data | 597 ++++++++++++++++++++++++++++++++++++ 1 file changed, 597 insertions(+) create mode 100644 dcoppython/shell/marshal_funcs.data (limited to 'dcoppython/shell/marshal_funcs.data') diff --git a/dcoppython/shell/marshal_funcs.data b/dcoppython/shell/marshal_funcs.data new file mode 100644 index 00000000..abb3a43e --- /dev/null +++ b/dcoppython/shell/marshal_funcs.data @@ -0,0 +1,597 @@ +// This file contains the C++ code necessary marshal and demarshal +// all the _simple_ types that dcoppython can understand. +// "Simple" types are types that do not contain other types. +// So, int and QString are simple types; QDict, QMap and QStringList are not. +// This file is processed by gen_marshal_code.py to produce a header +// file, which is included by marshaller.cpp +// +// Marshalling: +// The code in the "marshal" section has the following variables available: +// PyObject * obj; // the object to marshal +// QDataStream *str; // the stream to marshal to +// The function should return true if the object can be marshalled. +// str may be NULL. If so, the function should ignore the actually marshalling +// and merely return true or false, depending on whether the object _could_ +// be marshalled. +// +// Demarshalling: +// The code in the "demarshal" section has the following variables available: +// QDataStream *str; // the stream to demarshal from +// The function should return a PyObject* which is a reference to the +// newly created object. Ownership of the reference should be passed to +// the caller. The function can return null if for any reason it +// could not demarshal. + +type: void +%% marshall +{ + Q_UNUSED(str); // stop warnings + Q_UNUSED(obj); + return true; +} +%% demarshal +{ + Q_UNUSED(str); // stop warnings + Py_INCREF(Py_None); + return Py_None; +} + +type: bool +%doc as int b (1=True, 2=False) +%doc info Any Python object is converted to bool by the standard Python truth test. +%% from_pyobj + { + *ok=true; + return PyObject_IsTrue(obj); + } +%% to_pyobj + { + return PyInt_FromLong(val ? 1 : 0); + } +%% marshal + { + if (str) { + bool ok; + bool b = fromPyObject_bool(obj,&ok); + (*str) << (Q_INT8)b; + } + return true; + } +%% demarshal + { + Q_INT8 i; + (*str) >> i; + return toPyObject_bool(i!=0); + } +%% + +type:int +%doc as int i +%% marshal + { + if (!PyInt_Check(obj)) return false; + if (str) { + (*str) << (Q_INT32)PyInt_AsLong(obj); + } + return true; + } +%% demarshal + { + Q_INT32 i; + (*str) >> i; + return PyInt_FromLong( (long)i ); + } +%% + +type:uint +%doc as int i +%% marshal + { + if (!PyInt_Check(obj)) return false; + if (str) { + (*str) << (Q_INT32)PyInt_AsLong(obj); + } + return true; + } +%% demarshal + { + Q_INT32 i; + (*str) >> i; + return PyInt_FromLong( (long)i ); + } +%% + +type:double +%doc as float i +%% marshal + { + if (!PyFloat_Check(obj)) return false; + if (str) { + (*str) << PyFloat_AsDouble(obj); + } + return true; + } +%% demarshal + { + double d; + (*str) >> d; + return PyFloat_FromDouble(d); + } +%% + +type:uchar +%doc as str c +%doc as int c +%% marshal + { + if (PyString_Check(obj) && PyString_Size(obj)==1) { + if (str) { + char *c = PyString_AsString(obj); + (*str) << (*c); + } + return true; + } + + if (PyInt_Check(obj)) { + if (str) { + long l = PyInt_AsLong(obj); + Q_UINT8 c = (Q_UINT8)(l & 0xff); + (*str) << c; + } + return true; + } + + return false; + } +%%demarshal + { + Q_UINT8 c; + (*str) >> c; + return PyString_FromStringAndSize((const char *)(&c),1); + } +%% + +type:char +%doc as int c +%% marshal + { + if (PyInt_Check(obj)) { + if (str) { + long l = PyInt_AsLong(obj); + Q_INT8 c = (Q_INT8)(l & 0xff); + (*str) << c; + } + return true; + } + + return false; + } +%%demarshal + { + Q_INT8 c; + (*str) >> c; + return PyInt_FromLong((long)c); + } +%% + + +type:QByteArray +%% marshal + { + PyBufferProcs *pb = obj->ob_type->tp_as_buffer; + + if ( pb && pb->bf_getreadbuffer && pb->bf_getsegcount ) + { + // Get the number of buffer segments + int seg_count = (pb->bf_getsegcount)(obj, 0); + + if ( seg_count != 1 ) + // Can't handle more (or less) than 1 buffer segment + // at the moment + return false; + + // Get buffer size and data + void *data; + int size; + + if ( (size = (pb->bf_getreadbuffer)(obj, 0, &data)) < 0 ) + return false; + + if (str) { + QByteArray a; + a.setRawData( (const char*)data, size ); + (*str) << a; + a.resetRawData( (const char*)data, size ); + } + + return true; + } + else + // obj does not implement the buffer interface + return false; + } +%% demarshal + { + // Demarshal to a writable buffer object + QByteArray a; + (*str) >> a; + + uint size = a.size(); + char *data = a.data(); + + // Create a new buffer object and copy the data. + // Don't use PyBuffer_FromMemory() and the likes since + // that wouldn't give correct allocation and deallocation. + + PyObject *buffer_obj = PyBuffer_New( size ); + + if ( !buffer_obj ) + return NULL; + + PyBufferProcs *pb = buffer_obj->ob_type->tp_as_buffer; + + void *buffer_data; + + (pb->bf_getwritebuffer)( buffer_obj, 0, &buffer_data ); + + for ( uint i = 0; i < size; i++ ) + ((char*)buffer_data)[i] = data[i]; + + return buffer_obj; + } +%% + +type:QString +%doc as str s +%% marshal + { + if (!PyString_Check(obj)) return false; + if (str) { + QString s( PyString_AsString(obj) ); + (*str) << s; + } + return true; + } +%% demarshal + { + QString s; + (*str) >> s; + return PyString_FromString( s.utf8().data() ); + } +%% + +type:QCString +%doc as str s +%% marshal + { + if (!PyString_Check(obj)) return false; + if (str) { + QCString s( PyString_AsString(obj) ); + (*str) << s; + } + return true; + } +%% demarshal + { + QCString s; + (*str) >> s; + return PyString_FromString( s.data() ); + } +%% + +type:QRect +%doc as ( (int x1, int y1), (int x2, int y2) ) +%doc as ( int x1, int y1, int x2, int y2 ) +%% from_pyobj +{ + int xp1, yp1, xp2, yp2; + QRect r; + *ok=false; + if (!PyTuple_Check(obj)) return r; + if (!PyArg_ParseTuple(obj, (char*)"(ii)(ii)", &xp1, &yp1, &xp2, &yp2) && + !PyArg_ParseTuple(obj, (char*)"iiii", &xp1, &yp1, &xp2, &yp2)) + return r; + r.setCoords( xp1, yp1, xp2, yp2 ); + *ok=true; + return r; +} +%% to_pyobj +{ + int xp1, yp1, xp2, yp2; + val.coords(&xp1,&yp1,&xp2,&yp2); + return Py_BuildValue((char*)"(ii)(ii)", xp1, yp1, xp2, yp2); +} + +%% marshal +%defaultcode +%% demarshal +%defaultcode +%% + +type:QPoint +%doc as (int x, int y) +%% from_pyobj +{ + int x,y; + QPoint p; + *ok=false; + if (!PyTuple_Check(obj)) return p; + if (!PyArg_ParseTuple(obj, (char*)"ii", &x, &y)) + return p; + p.setX(x); + p.setY(y); + *ok=true; + return p; +} +%% to_pyobj +{ + return Py_BuildValue((char*)"ii", val.x(), val.y() ); +} +%% marshall +%defaultcode +%% demarshall +%defaultcode +%% + +type:QSize +%doc as (int width, int height) +%% from_pyobj +{ + int w,h; + QSize sz; + *ok=false; + if (!PyTuple_Check(obj)) return sz; + if (!PyArg_ParseTuple(obj, (char*)"ii", &w, &h)) + return sz; + sz.setWidth(w); + sz.setHeight(h); + *ok=true; + return sz; +} +%% to_pyobj +{ + return Py_BuildValue((char*)"ii", val.width(), val.height() ); +} +%% marshall +%defaultcode +%% demarshall +%defaultcode +%% + +type:QColor +%doc as (int red, int green, int blue) +%% from_pyobj +{ + int r,g,b; + QColor c; + *ok=false; + if (!PyTuple_Check(obj)) return c; + if (!PyArg_ParseTuple(obj, (char*)"iii", &r, &g, &b)) + return c; + c.setRgb(r,g,b); + *ok=true; + return c; +} +%% to_pyobj +{ + return Py_BuildValue((char*)"iii", val.red(), val.green(), val.blue() ); +} +%% marshall +%defaultcode +%% demarshall +%defaultcode +%% + +type:QPointArray +%doc as [ (int x, int y), (int x, int y), (int x, int y), ... ] +%% from_pyobj +{ + *ok=false; + if (!PyList_Check(obj)) return QPointArray(); + int size = PyList_Size(obj); + QPointArray pa(size); + for(int c=0;ccreateDCOPObject(val.app(), val.object() ); +} +%% marshal +%defaultcode +%% demarshal +%defaultcode +%% + + +// type:DCOPRef +// %doc as (str app, str obj, str type) +// %doc as (str app, str obj) +// %% from_pyobj +// { +// *ok=false; +// char *dcopref_app=NULL, *dcopref_obj=NULL, *dcopref_type=NULL; +// if (PyArg_ParseTuple(obj,(char*)"ss|s", &dcopref_app, &dcopref_obj, &dcopref_type)) { +// *ok=true; +// if (dcopref_type) { +// DCOPRef dr(QCString(dcopref_app), QCString(dcopref_obj), QCString(dcopref_type)); +// return dr; +// } +// DCOPRef dr(QCString(dcopref_app), QCString(dcopref_obj)); +// return dr; +// } +// return DCOPRef(); +// } +// %% to_pyobj +// { +// return Py_BuildValue((char*)"sss", val.app().data(), val.obj().data(), val.type().data() ); +// } +// %% marshal +// %defaultcode +// %% demarshal +// %defaultcode +// %% + +// type:QFont +// %% marshal +// %constructor ("default") +// %dict-map family:string,rawName:string +// %% demarshal +// %dict-map +// %% -- cgit v1.2.1