[PyKDE] Function pointer problem
David Boddie
david at boddie.org.uk
Sat Sep 9 00:44:23 BST 2006
On Friday 08 September 2006 05:07:49 +0100 (BST), jim j wrote:
> I have a problem while compiling the following code.
> the code is given below:
>
> %Module pyMyTimer
>
> typedef void (*TIMERFP)(long);
>
> struct _time
> {
> %TypeHeaderCode
> #include <mytimer.h>
> %End
>
> long expiryTime;
> TIMERFP pRoutine;
> long param;
> };
>
> %ModuleHeaderCode
> #include<cTimer.h>
> %End
>
> int myTimerStart(_time* , long , TIMERFP , long );
> long myTimerStop(_time* );
>
> I'm geting the following error ,
> sip: _time::pRoutine has an unsupported type.
>
> please ,help me to solve the problem... how will i deleare the Function
> pointer in a sip file? and howl will i use that as parameter in a function?
I thought this would be fairly easy, but I think you will have to try the
approach described in this message:
http://mats.gmd.de/pipermail/pykde/2003-May/005309.html
To summarise: you probably need to write a wrapper for Python callback
objects and create a C/C++ callback function that you register with the
myTimerStart() function. This C/C++ callback function is used as a proxy
for Python callbacks. I think you might need to write some %MethodCode
for the myTimerStart() function as well.
Alternatively, you might be able to just define TIMERFP as a mapped type,
using something like this:
typedef void (*TIMERFP)(long);
%MappedType TIMERFP
{
%TypeHeaderCode
#include <mytimer.h>
%End
%ConvertFromTypeCode
// Code to convert a C++ function pointer to a Python callable.
// Perhaps this would be used by a C++ proxy function to find a
// suitable Python callable to return.
%End
%ConvertToTypeCode
// Code to convert a Python callable into a suitable C++ function
// pointer. Perhaps the pointer to an existing C++ proxy function
// could be returned.
%End
};
All of the above is speculative. I haven't tried to do this with SIP, and I
couldn't find any existing examples except some on the web with really old
SIP syntax. I hope it helps you get started, anyway.
Good luck!
David
More information about the PyQt
mailing list