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"
28 #include "wine/unicode.h"
29 #include "file.h" /* for FILETIME routines */
30 #include "wine/server.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(timer);
36 /***********************************************************************
37 * CreateWaitableTimerA (KERNEL32.@)
39 HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR name )
41 WCHAR buffer[MAX_PATH];
43 if (!name) return CreateWaitableTimerW( sa, manual, NULL );
45 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
47 SetLastError( ERROR_FILENAME_EXCED_RANGE );
50 return CreateWaitableTimerW( sa, manual, buffer );
54 /***********************************************************************
55 * CreateWaitableTimerW (KERNEL32.@)
57 HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name )
60 DWORD len = name ? strlenW(name) : 0;
63 SetLastError( ERROR_FILENAME_EXCED_RANGE );
66 SERVER_START_REQ( create_timer )
69 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
70 wine_server_add_data( req, name, len * sizeof(WCHAR) );
72 wine_server_call_err( req );
80 /***********************************************************************
81 * OpenWaitableTimerA (KERNEL32.@)
83 HANDLE WINAPI OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name )
85 WCHAR buffer[MAX_PATH];
87 if (!name) return OpenWaitableTimerW( access, inherit, NULL );
89 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
91 SetLastError( ERROR_FILENAME_EXCED_RANGE );
94 return OpenWaitableTimerW( access, inherit, buffer );
98 /***********************************************************************
99 * OpenWaitableTimerW (KERNEL32.@)
101 HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
104 DWORD len = name ? strlenW(name) : 0;
107 SetLastError( ERROR_FILENAME_EXCED_RANGE );
110 SERVER_START_REQ( open_timer )
112 req->access = access;
113 req->inherit = inherit;
114 wine_server_add_data( req, name, len * sizeof(WCHAR) );
115 wine_server_call_err( req );
123 /***********************************************************************
124 * SetWaitableTimer (KERNEL32.@)
126 BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG period,
127 PTIMERAPCROUTINE callback, LPVOID arg, BOOL resume )
130 LARGE_INTEGER exp = *when;
132 if (exp.s.HighPart < 0) /* relative time */
135 NtQuerySystemTime( &now );
136 exp.QuadPart = RtlLargeIntegerSubtract( now.QuadPart, exp.QuadPart );
139 SERVER_START_REQ( set_timer )
141 if (!exp.s.LowPart && !exp.s.HighPart)
143 /* special case to start timeout on now+period without too many calculations */
152 ft.dwLowDateTime = exp.s.LowPart;
153 ft.dwHighDateTime = exp.s.HighPart;
154 req->sec = DOSFS_FileTimeToUnixTime( &ft, &remainder );
155 req->usec = remainder / 10; /* convert from 100-ns to us units */
157 req->handle = handle;
158 req->period = period;
159 req->callback = callback;
161 if (resume) SetLastError( ERROR_NOT_SUPPORTED ); /* set error but can still succeed */
162 ret = !wine_server_call_err( req );
169 /***********************************************************************
170 * CancelWaitableTimer (KERNEL32.@)
172 BOOL WINAPI CancelWaitableTimer( HANDLE handle )
175 SERVER_START_REQ( cancel_timer )
177 req->handle = handle;
178 ret = !wine_server_call_err( req );
185 /***********************************************************************
186 * CreateTimerQueue (KERNEL32.@)
188 HANDLE WINAPI CreateTimerQueue()
191 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
196 /***********************************************************************
197 * DeleteTimerQueueEx (KERNEL32.@)
199 BOOL WINAPI DeleteTimerQueueEx(HANDLE TimerQueue, HANDLE CompletionEvent)
201 FIXME("(%p, %p): stub\n", TimerQueue, CompletionEvent);
202 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
206 /***********************************************************************
207 * CreateTimerQueueTimer (KERNEL32.@)
209 * Creates a timer-queue timer. This timer expires at the specified due
210 * time (in ms), then after every specified period (in ms). When the timer
211 * expires, the callback function is called.
214 * nonzero on success or zero on faillure
219 BOOL WINAPI CreateTimerQueueTimer( PHANDLE phNewTimer, HANDLE TimerQueue,
220 WAITORTIMERCALLBACK Callback, PVOID Parameter,
221 DWORD DueTime, DWORD Period, ULONG Flags )
224 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
228 /***********************************************************************
229 * DeleteTimerQueueTimer (KERNEL32.@)
231 * Cancels a timer-queue timer.
234 * nonzero on success or zero on faillure
239 BOOL WINAPI DeleteTimerQueueTimer( HANDLE TimerQueue, HANDLE Timer,
240 HANDLE CompletionEvent )
243 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);