2 * Win32 waitable timers
4 * Copyright 1999 Alexandre Julliard
11 #include "wine/unicode.h"
12 #include "file.h" /* for FILETIME routines */
13 #include "wine/server.h"
16 /***********************************************************************
17 * CreateWaitableTimerA (KERNEL32.@)
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
);
28 SERVER_START_VAR_REQ( create_timer
, len
* sizeof(WCHAR
) )
31 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
32 if (len
) MultiByteToWideChar( CP_ACP
, 0, name
, strlen(name
), server_data_ptr(req
), len
);
42 /***********************************************************************
43 * CreateWaitableTimerW (KERNEL32.@)
45 HANDLE WINAPI
CreateWaitableTimerW( SECURITY_ATTRIBUTES
*sa
, BOOL manual
, LPCWSTR name
)
48 DWORD len
= name
? strlenW(name
) : 0;
51 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
54 SERVER_START_VAR_REQ( create_timer
, len
* sizeof(WCHAR
) )
57 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
58 memcpy( server_data_ptr(req
), name
, len
* sizeof(WCHAR
) );
68 /***********************************************************************
69 * OpenWaitableTimerA (KERNEL32.@)
71 HANDLE WINAPI
OpenWaitableTimerA( DWORD access
, BOOL inherit
, LPCSTR name
)
74 DWORD len
= name
? MultiByteToWideChar( CP_ACP
, 0, name
, strlen(name
), NULL
, 0 ) : 0;
77 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
80 SERVER_START_VAR_REQ( open_timer
, len
* sizeof(WCHAR
) )
83 req
->inherit
= inherit
;
84 if (len
) MultiByteToWideChar( CP_ACP
, 0, name
, strlen(name
), server_data_ptr(req
), len
);
93 /***********************************************************************
94 * OpenWaitableTimerW (KERNEL32.@)
96 HANDLE WINAPI
OpenWaitableTimerW( DWORD access
, BOOL inherit
, LPCWSTR name
)
99 DWORD len
= name
? strlenW(name
) : 0;
102 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
105 SERVER_START_VAR_REQ( open_timer
, len
* sizeof(WCHAR
) )
107 req
->access
= access
;
108 req
->inherit
= inherit
;
109 memcpy( server_data_ptr(req
), name
, len
* sizeof(WCHAR
) );
118 /***********************************************************************
119 * SetWaitableTimer (KERNEL32.@)
121 BOOL WINAPI
SetWaitableTimer( HANDLE handle
, const LARGE_INTEGER
*when
, LONG period
,
122 PTIMERAPCROUTINE callback
, LPVOID arg
, BOOL resume
)
125 LARGE_INTEGER exp
= *when
;
127 if (exp
.s
.HighPart
< 0) /* relative time */
130 NtQuerySystemTime( &now
);
131 exp
.QuadPart
= RtlLargeIntegerSubtract( now
.QuadPart
, exp
.QuadPart
);
134 SERVER_START_REQ( set_timer
)
136 if (!exp
.s
.LowPart
&& !exp
.s
.HighPart
)
138 /* special case to start timeout on now+period without too many calculations */
145 req
->sec
= DOSFS_FileTimeToUnixTime( (FILETIME
*)&exp
, &remainder
);
146 req
->usec
= remainder
/ 10; /* convert from 100-ns to us units */
148 req
->handle
= handle
;
149 req
->period
= period
;
150 req
->callback
= callback
;
152 if (resume
) SetLastError( ERROR_NOT_SUPPORTED
); /* set error but can still succeed */
153 ret
= !SERVER_CALL_ERR();
160 /***********************************************************************
161 * CancelWaitableTimer (KERNEL32.@)
163 BOOL WINAPI
CancelWaitableTimer( HANDLE handle
)
166 SERVER_START_REQ( cancel_timer
)
168 req
->handle
= handle
;
169 ret
= !SERVER_CALL_ERR();