2 * Win32 waitable timers
4 * Copyright 1999 Alexandre Julliard
11 #include "wine/unicode.h"
12 #include "file.h" /* for FILETIME routines */
16 /***********************************************************************
17 * CreateWaitableTimerA (KERNEL32.861)
19 HANDLE WINAPI
CreateWaitableTimerA( SECURITY_ATTRIBUTES
*sa
, BOOL manual
, LPCSTR name
)
22 DWORD len
= name
? MultiByteToWideChar( CP_ACP
, 0, name
, strlen(name
), NULL
, 0 ) : 0;
25 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
30 struct create_timer_request
*req
= server_alloc_req( sizeof(*req
), len
* sizeof(WCHAR
) );
33 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
34 if (len
) MultiByteToWideChar( CP_ACP
, 0, name
, strlen(name
), server_data_ptr(req
), len
);
36 server_call( REQ_CREATE_TIMER
);
44 /***********************************************************************
45 * CreateWaitableTimerW (KERNEL32.862)
47 HANDLE WINAPI
CreateWaitableTimerW( SECURITY_ATTRIBUTES
*sa
, BOOL manual
, LPCWSTR name
)
50 DWORD len
= name
? strlenW(name
) : 0;
53 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
58 struct create_timer_request
*req
= server_alloc_req( sizeof(*req
), len
* sizeof(WCHAR
) );
61 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
62 memcpy( server_data_ptr(req
), name
, len
* sizeof(WCHAR
) );
64 server_call( REQ_CREATE_TIMER
);
72 /***********************************************************************
73 * OpenWaitableTimerA (KERNEL32.881)
75 HANDLE WINAPI
OpenWaitableTimerA( DWORD access
, BOOL inherit
, LPCSTR name
)
78 DWORD len
= name
? MultiByteToWideChar( CP_ACP
, 0, name
, strlen(name
), NULL
, 0 ) : 0;
81 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
86 struct open_timer_request
*req
= server_alloc_req( sizeof(*req
), len
* sizeof(WCHAR
) );
89 req
->inherit
= inherit
;
90 if (len
) MultiByteToWideChar( CP_ACP
, 0, name
, strlen(name
), server_data_ptr(req
), len
);
91 server_call( REQ_OPEN_TIMER
);
99 /***********************************************************************
100 * OpenWaitableTimerW (KERNEL32.882)
102 HANDLE WINAPI
OpenWaitableTimerW( DWORD access
, BOOL inherit
, LPCWSTR name
)
105 DWORD len
= name
? strlenW(name
) : 0;
108 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
113 struct open_timer_request
*req
= server_alloc_req( sizeof(*req
), len
* sizeof(WCHAR
) );
115 req
->access
= access
;
116 req
->inherit
= inherit
;
117 memcpy( server_data_ptr(req
), name
, len
* sizeof(WCHAR
) );
118 server_call( REQ_OPEN_TIMER
);
126 /***********************************************************************
127 * SetWaitableTimer (KERNEL32.894)
129 BOOL WINAPI
SetWaitableTimer( HANDLE handle
, const LARGE_INTEGER
*when
, LONG period
,
130 PTIMERAPCROUTINE callback
, LPVOID arg
, BOOL resume
)
133 LARGE_INTEGER exp
= *when
;
135 if (exp
.s
.HighPart
< 0) /* relative time */
138 NtQuerySystemTime( &now
);
139 exp
.QuadPart
= RtlLargeIntegerSubtract( now
.QuadPart
, exp
.QuadPart
);
144 struct set_timer_request
*req
= server_alloc_req( sizeof(*req
), 0 );
146 if (!exp
.s
.LowPart
&& !exp
.s
.HighPart
)
148 /* special case to start timeout on now+period without too many calculations */
155 req
->sec
= DOSFS_FileTimeToUnixTime( (FILETIME
*)&exp
, &remainder
);
156 req
->usec
= remainder
/ 10; /* convert from 100-ns to us units */
158 req
->handle
= handle
;
159 req
->period
= period
;
160 req
->callback
= callback
;
162 if (resume
) SetLastError( ERROR_NOT_SUPPORTED
); /* set error but can still succeed */
163 ret
= !server_call( REQ_SET_TIMER
);
170 /***********************************************************************
171 * CancelWaitableTimer (KERNEL32.857)
173 BOOL WINAPI
CancelWaitableTimer( HANDLE handle
)
178 struct cancel_timer_request
*req
= server_alloc_req( sizeof(*req
), 0 );
179 req
->handle
= handle
;
180 ret
= !server_call( REQ_CANCEL_TIMER
);