2 * Win32 waitable timers
4 * Copyright 1999 Alexandre Julliard
10 #include "file.h" /* for FILETIME routines */
14 /***********************************************************************
15 * CreateWaitableTimerA (KERNEL32.861)
17 HANDLE WINAPI
CreateWaitableTimerA( SECURITY_ATTRIBUTES
*sa
, BOOL manual
, LPCSTR name
)
19 struct create_timer_request
*req
= get_req_buffer();
22 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
23 server_strcpyAtoW( req
->name
, name
);
25 server_call( REQ_CREATE_TIMER
);
26 if (req
->handle
== -1) return 0;
31 /***********************************************************************
32 * CreateWaitableTimerW (KERNEL32.862)
34 HANDLE WINAPI
CreateWaitableTimerW( SECURITY_ATTRIBUTES
*sa
, BOOL manual
, LPCWSTR name
)
36 struct create_timer_request
*req
= get_req_buffer();
39 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
40 server_strcpyW( req
->name
, name
);
42 server_call( REQ_CREATE_TIMER
);
43 if (req
->handle
== -1) return 0;
48 /***********************************************************************
49 * OpenWaitableTimerA (KERNEL32.881)
51 HANDLE WINAPI
OpenWaitableTimerA( DWORD access
, BOOL inherit
, LPCSTR name
)
53 struct open_timer_request
*req
= get_req_buffer();
56 req
->inherit
= inherit
;
57 server_strcpyAtoW( req
->name
, name
);
58 server_call( REQ_OPEN_TIMER
);
59 if (req
->handle
== -1) return 0; /* must return 0 on failure, not -1 */
64 /***********************************************************************
65 * OpenWaitableTimerW (KERNEL32.882)
67 HANDLE WINAPI
OpenWaitableTimerW( DWORD access
, BOOL inherit
, LPCWSTR name
)
69 struct open_timer_request
*req
= get_req_buffer();
72 req
->inherit
= inherit
;
73 server_strcpyW( req
->name
, name
);
74 server_call( REQ_OPEN_TIMER
);
75 if (req
->handle
== -1) return 0; /* must return 0 on failure, not -1 */
80 /***********************************************************************
81 * SetWaitableTimer (KERNEL32.894)
83 BOOL WINAPI
SetWaitableTimer( HANDLE handle
, const LARGE_INTEGER
*when
, LONG period
,
84 PTIMERAPCROUTINE callback
, LPVOID arg
, BOOL resume
)
88 struct set_timer_request
*req
= get_req_buffer();
90 if (when
->s
.HighPart
< 0) /* relative time */
93 GetSystemTimeAsFileTime( &ft
);
94 low
= ft
.dwLowDateTime
;
95 ft
.dwLowDateTime
-= when
->s
.LowPart
;
96 ft
.dwHighDateTime
-= when
->s
.HighPart
;
97 if (low
< ft
.dwLowDateTime
) ft
.dwHighDateTime
--; /* overflow */
99 else /* absolute time */
101 ft
.dwLowDateTime
= when
->s
.LowPart
;
102 ft
.dwHighDateTime
= when
->s
.HighPart
;
105 if (!ft
.dwLowDateTime
&& !ft
.dwHighDateTime
)
107 /* special case to start timeout on now+period without too many calculations */
113 req
->sec
= DOSFS_FileTimeToUnixTime( &ft
, &remainder
);
114 req
->usec
= remainder
/ 10; /* convert from 100-ns to us units */
116 req
->handle
= handle
;
117 req
->period
= period
;
118 req
->callback
= callback
;
120 if (resume
) SetLastError( ERROR_NOT_SUPPORTED
); /* set error but can still succeed */
121 return !server_call( REQ_SET_TIMER
);
125 /***********************************************************************
126 * CancelWaitableTimer (KERNEL32.857)
128 BOOL WINAPI
CancelWaitableTimer( HANDLE handle
)
130 struct cancel_timer_request
*req
= get_req_buffer();
131 req
->handle
= handle
;
132 return !server_call( REQ_CANCEL_TIMER
);