I'm creating an application in C++ for an embedded system. Therefore I'm tied to some C libraries, and do not have the freedom to use a lot of std functionality.
I have a callback signature:
typedef int (*callback_fn)(int a, int b);
A list with pointers to the registered callbacks:
callback_fn my_callback_functions[10];
And a function which adds callbacks to this list:
void add_callback(int function_iterator, callback_fn fn)
{
my_callback_functions[function_iterator] = fn;
}
The callbacks then get passed to this library, and it calls the callbacks upon some events.
Now I'd like to add a little routine to every callback, so I can reset a timer every time a call has been made:
myTimer.reset();
How can I add this to every call without changing the signature, or moving away from function pointers (which I need to interact with the library)?
I tried some things with templates but couldn't find the right way to make this work.