Re: SIGALRM in a class member?
R Samuel Klatchko wrote:
Ron Eggler wrote:
signal( SIGALRM, sendHeartbeat );
alarm(atoi(INITSource::XMLread(inBufstr,"Cyclic").c_str()));
but the problem is signal wouldn't allow me to have a function pointer to
a member method like INITSource::sendHeartbeat. If I need to do it this
way I would end up in crazy static declarations and linker conflicts - I
have gone there already and apparently didn't solve it...
You can do this with a forwarding function that is a static member (you
can also do it with a non-member function). Because signal does not
give you a way to attach some caller defined data, you will also need a
static member variable to hold a pointer to the instance of the class
you want to use:
foo.h:
class foo
{
public:
foo()
{
signal(SIGALRM, sighandler_trampoline);
singleton = this;
}
private:
static void sighandler_trampoline(int sig)
{
singleton->sighandler(sig);
}
void sighandler(int sig)
{
// add your logic here
}
static foo *singleton;
};
foo.cpp:
foo *foo::singleton = 0;
samuel
Hey Samuel,
This is kinda what I do -see my other posting except that I copy my instance
like this:
gps = new INITSource(source, 51001, log, gpsDataObj, false);
Glob_INIT_i = dynamic_cast<INITSource*>(gps);
I have to cast it again because gps is from a different type (mother class
of INITSource)
--
weeks of software enineering safe hours of planing ;)