Beispiel #1
0
CARD32
GetTimeInMillis(void)
{
    struct timeval tv;

#ifdef MONOTONIC_CLOCK
    struct timespec tp;
    static clockid_t clockid;

    if (!clockid) {
#ifdef CLOCK_MONOTONIC_COARSE
        if (clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0 &&
            (tp.tv_nsec / 1000) <= 1000 &&
            clock_gettime(CLOCK_MONOTONIC_COARSE, &tp) == 0)
            clockid = CLOCK_MONOTONIC_COARSE;
        else
#endif
        if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
            clockid = CLOCK_MONOTONIC;
        else
            clockid = ~0L;
    }
    if (clockid != ~0L && clock_gettime(clockid, &tp) == 0)
        return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
#endif

    X_GETTIMEOFDAY(&tv);
    return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
}
Beispiel #2
0
static void InitTimes (
    Boolean block,
    unsigned long* howlong,
    wait_times_ptr_t wt)
{
    if (block) {
	X_GETTIMEOFDAY (&wt->cur_time);
	FIXUP_TIMEVAL(wt->cur_time);
	wt->start_time = wt->cur_time;
	if(howlong == NULL) { /* special case for ever */
#ifndef USE_POLL
	    wt->wait_time_ptr = NULL;
#else
	    wt->poll_wait = X_BLOCK;
#endif
	} else { /* block until at most */
	    wt->max_wait_time.tv_sec = *howlong/1000;
	    wt->max_wait_time.tv_usec = (*howlong %1000)*1000;
#ifndef USE_POLL
	    wt->wait_time_ptr = &wt->max_wait_time;
#else
	    wt->poll_wait = *howlong;
#endif
	}
    } else {  /* don't block */
	wt->max_wait_time = zero_time;
#ifndef USE_POLL
	wt->wait_time_ptr = &wt->max_wait_time;
#else
	wt->poll_wait = X_DONT_BLOCK;
#endif
    }
}
Beispiel #3
0
CARD32
GetTimeInMillis()
{
    struct timeval  tp;

    X_GETTIMEOFDAY(&tp);
    return(tp.tv_sec * 1000) + (tp.tv_usec / 1000);
}
Beispiel #4
0
long
GetTimeInMillis(void)
{
    struct timeval tp;

    X_GETTIMEOFDAY(&tp);
    return ((tp.tv_sec * 1000) + (tp.tv_usec / 1000));
}
/******************************************************************************
 *
 *	start_play_clock
 *
 *	start the clock for play back.
 */
static void
start_play_clock()
{
	X_GETTIMEOFDAY(&play_time);
	/*
	 * flag that play_time is valid
	 */
	play_clock = 1;
}
Beispiel #6
0
bool Connection::is_xim_sync_reply_timeout(void)
{
    struct timeval cur_time, time_spent;
    X_GETTIMEOFDAY(&cur_time);
    TIMEDELTA(time_spent, cur_time, mSyncStartTime);
    if (time_spent.tv_sec >= XIM_SYNC_REPLY_TIMEOUT_SEC) {
	fprintf(stderr, "Warning: XIM_SYNC_REPLY timeout\n");
	return true;
    } else
	return false;
}
Beispiel #7
0
CARD32
GetTimeInMillis(void)
{
    struct timeval tv;

#ifdef MONOTONIC_CLOCK
    struct timespec tp;
    if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
        return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
#endif

    X_GETTIMEOFDAY(&tv);
    return(tv.tv_sec * 1000) + (tv.tv_usec / 1000);
}
Beispiel #8
0
static void AdjustHowLong (
	unsigned long *howlong,
	struct timeval *start_time)
{
	struct timeval new_time, time_spent, lstart_time;

	lstart_time = *start_time;
	X_GETTIMEOFDAY (&new_time);
	FIXUP_TIMEVAL(new_time);
	TIMEDELTA(time_spent, new_time, lstart_time);
	if(*howlong <= (unsigned long)(time_spent.tv_sec*1000+time_spent.tv_usec/1000))
	    *howlong = (unsigned long)0;  /* Timed out */
	else
	    *howlong -= (time_spent.tv_sec*1000+time_spent.tv_usec/1000);
}
Beispiel #9
0
void sunKbdWait()
{
    static struct timeval lastChngKbdTransTv;
    struct timeval tv;
    struct timeval lastChngKbdDeltaTv;
    unsigned int lastChngKbdDelta;

    X_GETTIMEOFDAY(&tv);
    if (!lastChngKbdTransTv.tv_sec)
	lastChngKbdTransTv = tv;
    tvminus(lastChngKbdDeltaTv, tv, lastChngKbdTransTv);
    lastChngKbdDelta = TVTOMILLI(lastChngKbdDeltaTv);
    if (lastChngKbdDelta < 750) {
	unsigned wait;
	/*
         * We need to guarantee at least 750 milliseconds between
	 * calls to KIOCTRANS. YUCK!
	 */
	wait = (750L - lastChngKbdDelta) * 1000L;
        usleep (wait);
        X_GETTIMEOFDAY(&tv);
    }
    lastChngKbdTransTv = tv;
}
char *
IceGenerateMagicCookie (
	int len
)
{
    char    *auth;
#ifndef HAVE_ARC4RANDOM_BUF
    long    ldata[2];
    int	    seed;
    int	    value;
    int	    i;
#endif

    if ((auth = malloc (len + 1)) == NULL)
	return (NULL);

#ifdef HAVE_ARC4RANDOM_BUF
    arc4random_buf(auth, len);
#else
#ifdef ITIMER_REAL
    {
	struct timeval  now;
	X_GETTIMEOFDAY (&now);
	ldata[0] = now.tv_sec;
	ldata[1] = now.tv_usec;
    }
#else
    {
	long    time ();
	ldata[0] = time ((long *) 0);
	ldata[1] = getpid ();
    }
#endif
    seed = (ldata[0]) + (ldata[1] << 16);
    srand (seed);
    for (i = 0; i < len; i++)
    {
	value = rand ();
	auth[i] = value & 0xff;
    }
#endif
    auth[len] = '\0';
    return (auth);
}
Beispiel #11
0
char *
IceGenerateMagicCookie (
	int len
)
{
    char    *auth;
    long    ldata[2];
    int	    seed;
    int	    value;
    int	    i;
    
    if ((auth = (char *) malloc (len + 1)) == NULL)
	return (NULL);

#ifdef ITIMER_REAL
    {
	struct timeval  now;
	X_GETTIMEOFDAY (&now);
	ldata[0] = now.tv_sec;
	ldata[1] = now.tv_usec;
    }
#else
    {
#ifndef __UNIXOS2__
	long    time ();
#endif
	ldata[0] = time ((long *) 0);
	ldata[1] = getpid ();
    }
#endif
    seed = (ldata[0]) + (ldata[1] << 16);
    srand (seed);
    for (i = 0; i < len; i++)
    {
	value = rand ();
	auth[i] = value & 0xff;
    }
    auth[len] = '\0';

    return (auth);
}
Beispiel #12
0
// taken from gdk.c
static long elapsedTime() {

    static struct timeval end;
    static struct timeval elapsed;
    long milliseconds;

    X_GETTIMEOFDAY(&end);

    if( alock_start_time.tv_usec > end.tv_usec ) {

        end.tv_usec += 1000000;
        end.tv_sec--;
    }

    elapsed.tv_sec = end.tv_sec - alock_start_time.tv_sec;
    elapsed.tv_usec = end.tv_usec - alock_start_time.tv_usec;

    milliseconds = (elapsed.tv_sec * 1000) + (elapsed.tv_usec / 1000);

    return milliseconds;
}
/*
 * mode: what input action packing mode to use.  one of 0, XTestPACKED_MOTION,
 * or XTestPACKED_ACTIONS; optionally 'or'ed with XTestEXCLUSIVE,
 */
void
steal_input(ClientPtr client, CARD32 mode)
{
	if (packet_index != 0) 
	{
		/*
		 * if there is a partially full input action event waiting
		 * when this function is called, send it to the client
		 */
		flush_input_actions();
	}
	else
	{	
		/*
		 * otherwise, set up a new input action event
		 */
		input_action_packet.type = XTestInputActionType;
		packet_index = 0;
	}
	/*
	 * set up the new input action packing mode
	 */
	packed_mode = mode & ~(XTestEXCLUSIVE);
	/*
	 * keep track of where the mouse is
	 */
	XTestGetPointerPos(&xtest_mousex, &xtest_mousey);
	/*
	 * keep track of which client is getting input actions
	 */
	current_xtest_client = client;
	/*
	 * find out what time it is
	 */
	X_GETTIMEOFDAY(&current_time);
	/*
	 * jump to the initial position of the mouse, using a device type of 0.
	 */
	XTestStealJumpData(xtest_mousex, xtest_mousey, 0);
}
/******************************************************************************
 *
 *	current_ms
 *
 *	Returns the number of milliseconds from the passed-in time to the
 *	current time, and then updates the passed-in time to the current time.
 */
static CARD32
current_ms(struct timeval *otime)
{	
	struct timeval	tval;
	unsigned long	the_ms;
	unsigned long	sec;
	unsigned long	usec;

	/*
	 * get the current time
	 */
	X_GETTIMEOFDAY(&tval);
	if (tval.tv_usec < otime->tv_usec)
	{
		/*
		 * borrow a second's worth of microseconds if needed
		 */
		usec = tval.tv_usec - otime->tv_usec + 1000000;
		sec = tval.tv_sec - 1 - otime->tv_sec;
	}
	else
	{
		usec = tval.tv_usec - otime->tv_usec;
		sec = tval.tv_sec - otime->tv_sec;
	}
	/*
	 * update the passed-in time to the new time
	 */
	*otime = tval;
	/*
	 * compute the number of milliseconds contained in
	 * 'sec' seconds and 'usec' microseconds
	 */
	the_ms = (sec * 1000000L + usec) / 1000L;
	return (the_ms);
}
Beispiel #15
0
void Connection::setSyncFlag()
{
    mSyncFlag = true;
    X_GETTIMEOFDAY(&mSyncStartTime);
}
/******************************************************************************
 *
 *	compute_action_time
 *
 *	Set the play clock to the time when the next input action should be put
 *	into the server's input queue.  Fill the rtime structure with values
 *	for the delta until the time for the next input action.
 */
static void
compute_action_time(struct timeval *rtime)
{
	/*
	 * holds the delay time in milliseconds
	 */
	unsigned long	dtime;
	/*
	 * holds the number of microseconds in the sum of the dtime value
	 * and the play_time value
	 */
	unsigned long	tot_usec;
	/*
	 * holds the number of seconds and microseconds in the
	 * dtime value
	 */
	unsigned long 	sec;
	unsigned long 	usec;
	/*
	 * holds the current time
	 */
	struct timeval	btime;

	/*
	 * Put the time from the current input action in dtime
	 */
	dtime = action_array[read_index].delay_time;
	/*
	 * If the current input action is a delay input action,
	 * add in the time from the following input action.
	 */
	if ((action_array[read_index].type == XTestDELAY_ACTION) &&
	    ((read_index + 1) < write_index))
	{  
		read_index++;
		dtime = dtime + action_array[read_index].delay_time;
	}
	/*
	 * compute the number of seconds and microseconds in the
	 * dtime value
	 */
  	sec = dtime / 1000;
  	usec = (dtime % 1000) * 1000;
	/*
	 * get the current time in btime
	 */
	X_GETTIMEOFDAY(&btime);
	/*
	 * compute the number of microseconds in the sum of the dtime value
	 * and the current usec value
	 */
	tot_usec = btime.tv_usec + usec;
	/*
	 * if it is greater than one second's worth, adjust the seconds
	 */
	if (tot_usec >= 1000000)
	{ 
		tot_usec -= 1000000;
		sec++;
	}
	play_time.tv_usec = tot_usec;
	play_time.tv_sec = btime.tv_sec + sec;
	/*
	 * put the time until the next input action in rtime
	 */
	rtime->tv_sec = sec;
	rtime->tv_usec = usec;
}
/******************************************************************************
 *
 *	find_residual_time
 *
 *	Find the time interval from the current time to the value in play_time.
 *	This is the time to wait till putting the next input action into the
 *	server's input queue.  If the time is already up, reset play_time to
 *	the current time.
 */
static int
find_residual_time(struct timeval *the_residual)
{
	/*
	 * if > 0, there is time to wait.  If < 0, then don't wait
	 */
	int		wait = 1;
	/*
	 * holds the current time
	 */
	struct timeval	btime;
	/*
	 * holds the current time in seconds and microseconds
	 */
	unsigned long	bsec;
	unsigned long	busec;
	/*
	 * holds the playback time in seconds and microseconds
	 */
	unsigned long	psec;
	unsigned long	pusec;

	/*
	 * get the current time in btime
	 */
	X_GETTIMEOFDAY(&btime);
	/*
	 * get the current time in seconds and microseconds
	 */
	bsec = btime.tv_sec;
	busec = btime.tv_usec;
	/*
	 * get the playback time in seconds and microseconds
	 */
	psec = play_time.tv_sec;
	pusec = play_time.tv_usec;
	/*
	 * if the current time is already later than the playback time,
	 * we don't need to wait
	 */
	if (bsec > psec)	
	{
	    wait = -1;
	}
	else
	{ 
		if (bsec == psec)
		{ 
			/*
			 * if the current and playback times have the same
			 * second value, then compare the microsecond values
			 */
			if ( busec >= pusec) 
			{ 
				/*
				 * if the current time is already later than
				 * the playback time, we don't need to wait
				 */
				wait = -1;
			}
			else
			{ 
				the_residual->tv_usec = pusec - busec;
				the_residual->tv_sec = 0;
			}
		}
		else	
		{ 
			if (busec > pusec)
			{ 
				/*
				 * 'borrow' a second's worth of microseconds
				 * from the seconds left to wait
				 */
				the_residual->tv_usec = 1000000 - busec + pusec;
				psec--;
				the_residual->tv_sec = psec - bsec;
			}
			else
			{ 
				the_residual->tv_sec = psec - bsec;
				the_residual->tv_usec = pusec - busec;
			}
		}
	}
	if (wait < 0)
	{ 
		/*
		 * if don't need to wait, set the playback time
		 * to the current time
		 */
		X_GETTIMEOFDAY(&play_time);
		/*
		 * set the time to wait to 0
		 */
		the_residual->tv_sec = 0;
		the_residual->tv_usec = 0;
	}
	return(wait);
}
Beispiel #18
0
static void
rightNow(struct timeval *tv)
{
    X_GETTIMEOFDAY(tv);
}
Beispiel #19
0
EIF_BOOLEAN basic_gui_initialize(EIF_POINTER display_name,
				 EIF_BOOLEAN sync,
				 EIF_BOOLEAN no_xshm,
				 EIF_POINTER name,
				 EIF_POINTER progclass,
				 EIF_POINTER gxid_host,
				 EIF_INTEGER gxid_port) {
  /*
     Called only once at the very beginning to initialize the Window Manager.
  */
  int synchronize = sync;
  XKeyboardState keyboard_state;
  XClassHint *class_hint;
  X_GETTIMEOFDAY (&start);
  gdk_display_name = display_name;
  XSetErrorHandler (gui_x_error);
  XSetIOErrorHandler (gui_x_io_error);
  g_get_prgname = name;
  gdk_display_name = display_name;
  if (no_xshm) gdk_use_xshm = FALSE;
  gdk_progclass = progclass;
#ifdef XINPUT_GXI
  gdk_input_gxid_host = gxid_host;
  gdk_input_gxid_port = gxid_port;
#endif

  gdk_display = XOpenDisplay (gdk_display_name);
  if (!gdk_display)
    return FALSE;

  if (synchronize)
    XSynchronize (gdk_display, True);

  gdk_screen = DefaultScreen (gdk_display);

  gdk_root_window = RootWindow (gdk_display, gdk_screen);

  gdk_leader_window = XCreateSimpleWindow(gdk_display, gdk_root_window,
					  10, 10, 10, 10, 0, 0 , 0);
  class_hint = XAllocClassHint();
  class_hint->res_name = g_get_prgname;
  if (gdk_progclass == NULL) {
    gdk_progclass = g_get_prgname;
  }
  class_hint->res_class = gdk_progclass;
  XmbSetWMProperties (gdk_display, gdk_leader_window,
		      NULL, NULL, se_argv, se_argc,
		      NULL, NULL, class_hint);
  XFree (class_hint);
  gdk_wm_delete_window = XInternAtom (gdk_display, "WM_DELETE_WINDOW", False);
  gdk_wm_take_focus = XInternAtom (gdk_display, "WM_TAKE_FOCUS", False);
  gdk_wm_protocols = XInternAtom (gdk_display, "WM_PROTOCOLS", False);
  gdk_wm_window_protocols[0] = gdk_wm_delete_window;
  gdk_wm_window_protocols[1] = gdk_wm_take_focus;
  gdk_selection_property = XInternAtom (gdk_display, "GDK_SELECTION", False);

  XGetKeyboardControl (gdk_display, &keyboard_state);

  autorepeat = keyboard_state.global_auto_repeat;

  timer.tv_sec = 0;
  timer.tv_usec = 0;
  timerp = NULL;

  /* @@@ Keep This ?:
     gdk_events_init ();
     gdk_visual_init ();
     gdk_window_init ();
     gdk_image_init ();
     gdk_input_init ();
     gdk_dnd_init ();

#ifdef USE_XIM
  gdk_im_open ();
#endif
  */
  return 1;
}
Beispiel #20
0
static void initStartTime() {
    X_GETTIMEOFDAY(&alock_start_time);
}