Re: XForms: timers

From: Steve Lamont (spl@szechuan.ucsd.edu)
Date: Mon Apr 03 2000 - 12:41:03 EDT

  • Next message: Danny G. Holstein: "Re: XForms: timers"

    # To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

    > Because, I don't want to use a callback. I'm processing a device
    > with a long age process and want to update the parameters screen and
    > check for faults on a short interval (handled by timers) but want to
    > log the results and increase the load on a much longer interval, my
    > sleep() command is part of this slower loop and I want the execution
    > to stay within that loop. ...

    I'm not sure I'm able to parse that sentence or understand what you're
    trying to accomplish. I'm also not clear why you don't wish to use a
    callback.

    I suppose you could implement this with a select() call.

            void fl_sleep( int seconds )

            {

                    struct timeval initial;
                    double time_remaining = seconds;

                    gettimeofday( &initial, NULL );

                    do {

                            fd_set read_fds;
                            struct timeval current;
                            struct timeval timeout;

                            timeout.tv_sec = ( int ) time_remaining;
                            timeout.tv_usec =
                                    ( time_remaining - timeout.tv_sec ) *
                                            1.0e6;
                            FD_ZERO( &read_fds );
                            FD_SET( ConnectionNumber( fl_get_display() ),
                                     &read_fds );
                            if ( select( FD_SETSIZE,
                                         &read_fds,
                                         NULL,
                                         NULL,
                                         &timeout ) > 0 )
                                    fl_check_forms();
                            else
                                    perror( "select error" );

                            gettimeofday( &current, NULL );

                            time_remaining = seconds -
                                    ( ( current.tv_sec - initial.tv_sec ) +
                                    ( ( current.tv_usec - initial.tv_usec ) *
                                            1.0e-6 ) );

                    } while ( time_remaining > 0.0 );

            }

    This may need some tweaking for syntax and function, since I just
    whipped this up while typing this message and haven't tested the code
    at all. There are problems, however, in that the XForms timers would
    be ignored.

    Refer to the appropriate manual pages for details on function and
    macro use. ConnectionNumber() is an Xlib macro returning the file
    descriptor of the connection ot the X server.

                                                            spl
    _________________________________________________
    To unsubscribe, send the message "unsubscribe" to
    xforms-request@bob.usuhs.mil or see
    http://bob.usuhs.mil/mailserv/xforms.html
    XForms Home Page: http://world.std.com/~xforms
    List Archive: http://bob.usuhs.mil/mailserv/list-archives/



    This archive was generated by hypermail 2b29 : Mon Apr 03 2000 - 12:53:30 EDT