Add few SFGAO_CAN* attributes to supported list.
[wine/hacks.git] / scheduler / timer.c
blobb67563c2d1cb353ee3dd8c41200270041a8074c0
1 /*
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <string.h>
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
29 #include "winerror.h"
30 #include "winnls.h"
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 );
51 return 0;
53 return CreateWaitableTimerW( sa, manual, buffer );
57 /***********************************************************************
58 * CreateWaitableTimerW (KERNEL32.@)
60 HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name )
62 HANDLE ret;
63 DWORD len = name ? strlenW(name) : 0;
64 if (len >= MAX_PATH)
66 SetLastError( ERROR_FILENAME_EXCED_RANGE );
67 return 0;
69 SERVER_START_REQ( create_timer )
71 req->manual = manual;
72 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
73 wine_server_add_data( req, name, len * sizeof(WCHAR) );
74 SetLastError(0);
75 wine_server_call_err( req );
76 ret = reply->handle;
78 SERVER_END_REQ;
79 return ret;
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 );
95 return 0;
97 return OpenWaitableTimerW( access, inherit, buffer );
101 /***********************************************************************
102 * OpenWaitableTimerW (KERNEL32.@)
104 HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
106 HANDLE ret;
107 DWORD len = name ? strlenW(name) : 0;
108 if (len >= MAX_PATH)
110 SetLastError( ERROR_FILENAME_EXCED_RANGE );
111 return 0;
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 );
119 ret = reply->handle;
121 SERVER_END_REQ;
122 return ret;
126 /***********************************************************************
127 * SetWaitableTimer (KERNEL32.@)
129 BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG period,
130 PTIMERAPCROUTINE callback, LPVOID arg, BOOL resume )
132 BOOL ret;
133 LARGE_INTEGER exp = *when;
135 if (exp.s.HighPart < 0) /* relative time */
137 LARGE_INTEGER now;
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 */
147 req->sec = 0;
148 req->usec = 0;
150 else
152 DWORD remainder;
153 FILETIME ft;
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;
163 req->arg = arg;
164 if (resume) SetLastError( ERROR_NOT_SUPPORTED ); /* set error but can still succeed */
165 ret = !wine_server_call_err( req );
167 SERVER_END_REQ;
168 return ret;
172 /***********************************************************************
173 * CancelWaitableTimer (KERNEL32.@)
175 BOOL WINAPI CancelWaitableTimer( HANDLE handle )
177 BOOL ret;
178 SERVER_START_REQ( cancel_timer )
180 req->handle = handle;
181 ret = !wine_server_call_err( req );
183 SERVER_END_REQ;
184 return ret;
188 /***********************************************************************
189 * CreateTimerQueue (KERNEL32.@)
191 HANDLE WINAPI CreateTimerQueue()
193 FIXME("stub\n");
194 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
195 return NULL;
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);
206 return 0;
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.
216 * RETURNS
217 * nonzero on success or zero on faillure
219 * BUGS
220 * Unimplemented
222 BOOL WINAPI CreateTimerQueueTimer( PHANDLE phNewTimer, HANDLE TimerQueue,
223 WAITORTIMERCALLBACK Callback, PVOID Parameter,
224 DWORD DueTime, DWORD Period, ULONG Flags )
226 FIXME("stub\n");
227 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
228 return TRUE;
231 /***********************************************************************
232 * DeleteTimerQueueTimer (KERNEL32.@)
234 * Cancels a timer-queue timer.
236 * RETURNS
237 * nonzero on success or zero on faillure
239 * BUGS
240 * Unimplemented
242 BOOL WINAPI DeleteTimerQueueTimer( HANDLE TimerQueue, HANDLE Timer,
243 HANDLE CompletionEvent )
245 FIXME("stub\n");
246 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
247 return TRUE;