B
brekehan
I am going to try and keep this non-OS specific, especially when I am
trying to implement this on multiple OSes
The need has arisen for a callback mechanism. Currently, things are
going to go something like this:
1) Application requests some work to be done from API and supplies a
memory buffer that cannot be modified until called back
2) API does work, fills buffer, and calls back Application when
completed <--I am working on this part
This is to minimize copying of large amounts of data, but still keep
things running independantly of each other without complicating things
with threads.
My question is:
Do callbacks need to be C style functions?
If not,
Can a callback be a method of a class (and static)
If so, can it be private (and static)?
I really hate to make things ugly by implementing global functions
outside a class to communicate between 'modules' (APP and API lib),
get data from the callback, then post something to an instance of a
class. that would require all kinds of seperate methods for posting
back to the class instance from outside....and they would have to be
public and exposed to the user whom is going to say to himself,"wth
are these?"
I am not aiming to use anything Windows or Linux specific such as the
CALLBACK definition in windows.h. I will be making my own callback
definition:
something like
typedef void (* API_NAME_CALLBACK) ( arguments);
then the APP can call an API method like:
someclass->dostuff(char * mybuffer, API_NAME_CALLBACK routine);
and be notiied when his buffer is ready to be released.
trying to implement this on multiple OSes
The need has arisen for a callback mechanism. Currently, things are
going to go something like this:
1) Application requests some work to be done from API and supplies a
memory buffer that cannot be modified until called back
2) API does work, fills buffer, and calls back Application when
completed <--I am working on this part
This is to minimize copying of large amounts of data, but still keep
things running independantly of each other without complicating things
with threads.
My question is:
Do callbacks need to be C style functions?
If not,
Can a callback be a method of a class (and static)
If so, can it be private (and static)?
I really hate to make things ugly by implementing global functions
outside a class to communicate between 'modules' (APP and API lib),
get data from the callback, then post something to an instance of a
class. that would require all kinds of seperate methods for posting
back to the class instance from outside....and they would have to be
public and exposed to the user whom is going to say to himself,"wth
are these?"
I am not aiming to use anything Windows or Linux specific such as the
CALLBACK definition in windows.h. I will be making my own callback
definition:
something like
typedef void (* API_NAME_CALLBACK) ( arguments);
then the APP can call an API method like:
someclass->dostuff(char * mybuffer, API_NAME_CALLBACK routine);
and be notiied when his buffer is ready to be released.