My C program uses callback functions which are periodically called. I want to be able to handle the callback functions in a Java or C# program. How should I write the .i fil
C# solution : you must use delegates. look at the code sample
public delegate void DoSome(object sender);
public class MyClass{
public event DoSome callbackfunc;
public void DoWork(){
// do work here
if(callbackfunc != null)
callbackfunc(something);
}
}
this is also like event handling mechanism but by theory both of have same implementation in c#
Java solution: you must use interfaces, look at this sample code
interface Notification{
public void somthingHappend(Object obj);
}
class MyClass{
private Notification iNotifer;
public void setNotificationReciver(Notification in){
this.iNotifier = in;
}
public void doWork(){
//some work to do
if(something heppens){ iNotifier.somthingHappend(something);}
}
}
actually you can use a List of Notification to implement a set of callback receivers