Re: SIGALRM in a class member?
On Aug 13, 1:57 am, R Samuel Klatchko <r...@moocat.org> 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 w=
ay 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).
Not according to the standard. "All signal handlers shall have C
linkage" (=A718.7/5). And "A C language linkage is ignored for the
names of class members and the member function type of class
member functions" (=A77.5/4). A compiler is required to diagnose
this error (and some do).
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:
Note, however, that it is implementation defined whether you can
access said variable. Typically, if it is a pointer, you can,
but calling a member function on it, etc., is less sure.
Since you can only deal with one instance this way (and since at
least under Unix, SIGALRM only manages a single timer), the best
solution is to declare a sig_atomic_t with static lifetime, and
test it. (Except that most systems, or at least Unix and
Windows, offer even better facilities for managing time.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34