2 * Win32 waitable timers
4 * Copyright 1999 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
31 #include "wine/unicode.h"
32 #include "file.h" /* for FILETIME routines */
33 #include "wine/server.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(timer);
39 /***********************************************************************
40 * CreateWaitableTimerA (KERNEL32.@)
42 HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR name )
44 WCHAR buffer[MAX_PATH];
46 if (!name) return CreateWaitableTimerW( sa, manual, NULL );
48 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
50 SetLastError( ERROR_FILENAME_EXCED_RANGE );
53 return CreateWaitableTimerW( sa, manual, buffer );
57 /***********************************************************************
58 * CreateWaitableTimerW (KERNEL32.@)
60 HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name )
63 DWORD len = name ? strlenW(name) : 0;
66 SetLastError( ERROR_FILENAME_EXCED_RANGE );
69 SERVER_START_REQ( create_timer )
72 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
73 wine_server_add_data( req, name, len * sizeof(WCHAR) );
75 wine_server_call_err( req );
83 /***********************************************************************
84 * OpenWaitableTimerA (KERNEL32.@)
86 HANDLE WINAPI OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name )
88 WCHAR buffer[MAX_PATH];
90 if (!name) return OpenWaitableTimerW( access, inherit, NULL );
92 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
94 SetLastError( ERROR_FILENAME_EXCED_RANGE );
97 return OpenWaitableTimerW( access, inherit, buffer );
101 /***********************************************************************
102 * OpenWaitableTimerW (KERNEL32.@)
104 HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
107 DWORD len = name ? strlenW(name) : 0;
110 SetLastError( ERROR_FILENAME_EXCED_RANGE );
113 SERVER_START_REQ( open_timer )
115 req->access = access;
116 req->inherit = inherit;
117 wine_server_add_data( req, name, len * sizeof(WCHAR) );
118 wine_server_call_err( req );
126 /***********************************************************************
127 * SetWaitableTimer (KERNEL32.@)
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 );
142 SERVER_START_REQ( set_timer )
144 if (!exp.s.LowPart && !exp.s.HighPart)
146 /* special case to start timeout on now+period without too many calculations */
155 ft.dwLowDateTime = exp.s.LowPart;
156 ft.dwHighDateTime = exp.s.HighPart;
157 req->sec = DOSFS_FileTimeToUnixTime( &ft, &remainder );
158 req->usec = remainder / 10; /* convert from 100-ns to us units */
160 req->handle = handle;
161 req->period = period;
162 req->callback = callback;
164 if (resume) SetLastError( ERROR_NOT_SUPPORTED ); /* set error but can still succeed */
165 ret = !wine_server_call_err( req );
172 /***********************************************************************
173 * CancelWaitableTimer (KERNEL32.@)
175 BOOL WINAPI CancelWaitableTimer( HANDLE handle )
178 SERVER_START_REQ( cancel_timer )
180 req->handle = handle;
181 ret = !wine_server_call_err( req );
188 /***********************************************************************
189 * CreateTimerQueue (KERNEL32.@)
191 HANDLE WINAPI CreateTimerQueue()
194 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
199 /***********************************************************************
200 * DeleteTimerQueueEx (KERNEL32.@)
202 BOOL WINAPI DeleteTimerQueueEx(HANDLE TimerQueue, HANDLE CompletionEvent)
204 FIXME("(%p, %p): stub\n", TimerQueue, CompletionEvent);
205 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
209 /***********************************************************************
210 * CreateTimerQueueTimer (KERNEL32.@)
212 * Creates a timer-queue timer. This timer expires at the specified due
213 * time (in ms), then after every specified period (in ms). When the timer
214 * expires, the callback function is called.
217 * nonzero on success or zero on faillure
222 BOOL WINAPI CreateTimerQueueTimer( PHANDLE phNewTimer, HANDLE TimerQueue,
223 WAITORTIMERCALLBACK Callback, PVOID Parameter,
224 DWORD DueTime, DWORD Period, ULONG Flags )
227 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
231 /***********************************************************************
232 * DeleteTimerQueueTimer (KERNEL32.@)
234 * Cancels a timer-queue timer.
237 * nonzero on success or zero on faillure
242 BOOL WINAPI DeleteTimerQueueTimer( HANDLE TimerQueue, HANDLE Timer,
243 HANDLE CompletionEvent )
246 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);