Added version information.
[wine.git] / scheduler / timer.c
blob6ed81a0c3caa018b9fa215db36806e88e1baab84
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 "wine/server.h"
33 #include "wine/debug.h"
34 #include "ntdll_misc.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;
134 SERVER_START_REQ( set_timer )
136 if (!when->s.LowPart && !when->s.HighPart)
138 /* special case to start timeout on now+period without too many calculations */
139 req->expire.sec = 0;
140 req->expire.usec = 0;
142 else NTDLL_get_server_timeout( &req->expire, when );
144 req->handle = handle;
145 req->period = period;
146 req->callback = callback;
147 req->arg = arg;
148 if (resume) SetLastError( ERROR_NOT_SUPPORTED ); /* set error but can still succeed */
149 ret = !wine_server_call_err( req );
151 SERVER_END_REQ;
152 return ret;
156 /***********************************************************************
157 * CancelWaitableTimer (KERNEL32.@)
159 BOOL WINAPI CancelWaitableTimer( HANDLE handle )
161 BOOL ret;
162 SERVER_START_REQ( cancel_timer )
164 req->handle = handle;
165 ret = !wine_server_call_err( req );
167 SERVER_END_REQ;
168 return ret;
172 /***********************************************************************
173 * CreateTimerQueue (KERNEL32.@)
175 HANDLE WINAPI CreateTimerQueue()
177 FIXME("stub\n");
178 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
179 return NULL;
183 /***********************************************************************
184 * DeleteTimerQueueEx (KERNEL32.@)
186 BOOL WINAPI DeleteTimerQueueEx(HANDLE TimerQueue, HANDLE CompletionEvent)
188 FIXME("(%p, %p): stub\n", TimerQueue, CompletionEvent);
189 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
190 return 0;
193 /***********************************************************************
194 * CreateTimerQueueTimer (KERNEL32.@)
196 * Creates a timer-queue timer. This timer expires at the specified due
197 * time (in ms), then after every specified period (in ms). When the timer
198 * expires, the callback function is called.
200 * RETURNS
201 * nonzero on success or zero on faillure
203 * BUGS
204 * Unimplemented
206 BOOL WINAPI CreateTimerQueueTimer( PHANDLE phNewTimer, HANDLE TimerQueue,
207 WAITORTIMERCALLBACK Callback, PVOID Parameter,
208 DWORD DueTime, DWORD Period, ULONG Flags )
210 FIXME("stub\n");
211 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
212 return TRUE;
215 /***********************************************************************
216 * DeleteTimerQueueTimer (KERNEL32.@)
218 * Cancels a timer-queue timer.
220 * RETURNS
221 * nonzero on success or zero on faillure
223 * BUGS
224 * Unimplemented
226 BOOL WINAPI DeleteTimerQueueTimer( HANDLE TimerQueue, HANDLE Timer,
227 HANDLE CompletionEvent )
229 FIXME("stub\n");
230 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
231 return TRUE;