Perl subroutines as callbacks

View: New views
1 Messages — Rating Filter:   Alert me  

Perl subroutines as callbacks

by Sri-26 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Where can I find working examples of Perl subroutines as callbacks from a C library?  Found some other prior posts on this topic, but couldnt find any concrete examples/answers.  I found one example in Dave's paper (Badger), but havent been able to solve my problem yet with it.  I'll admit I'm not a Perl expert :)

I have used swig to expose a C event-driven interface we use in our products into Perl with the aim to allow test team to exercise the API.  Invoking the API's in the .h files from perl seems straightforward.  However, I've hit a roadblock with callbacks that need to be in Perl.

Structure of our library interface:

- Invoke API functions to intiate some functionality.  Register a callback function as an argument to the API function to get results.
- API returns "immediately", but real results are returned by invoking the callback function registered.  The functions that invoke the callbacks are not part of the public interface.
- Callback function initiates further steps based on the results.
- There are lots of structures, unions.  Pointers of these are passed as input to APIs and received as output params in callbacks.

Is swig be able to do this?  As the C interface is designed with the end-product in mind, I will NOT be able to change it (much) to expose it in perl (i.e for QA purpose).  None of the developers of the C interface (nor me) are Perl experts.  Are there (opensource/free or otherwise) utilities that will simplify things from the API developers standpoint?

Thanks

Sample interface in C:

/*Callback, to be implemented by developer/QA engineer*/
typedef void (tMy_CBACK)(tMy_EVT event, tMy_CB_MSG *p_data);

/* API call, impl in the interface lib */
tSTATUS MySrvOpen(tMy_CBACK callback);



     

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user