Fix signed/unsigned compilation warnings.
[wine.git] / scheduler / timer.c
blob41936bd9b360f8d43deff7836fa7dd3fe0fe6497
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>
26 #include "winerror.h"
27 #include "winnls.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 );
48 return 0;
50 return CreateWaitableTimerW( sa, manual, buffer );
54 /***********************************************************************
55 * CreateWaitableTimerW (KERNEL32.@)
57 HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name )
59 HANDLE ret;
60 DWORD len = name ? strlenW(name) : 0;
61 if (len >= MAX_PATH)
63 SetLastError( ERROR_FILENAME_EXCED_RANGE );
64 return 0;
66 SERVER_START_REQ( create_timer )
68 req->manual = manual;
69 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
70 wine_server_add_data( req, name, len * sizeof(WCHAR) );
71 SetLastError(0);
72 wine_server_call_err( req );
73 ret = reply->handle;
75 SERVER_END_REQ;
76 return ret;
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 );
92 return 0;
94 return OpenWaitableTimerW( access, inherit, buffer );
98 /***********************************************************************
99 * OpenWaitableTimerW (KERNEL32.@)
101 HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
103 HANDLE ret;
104 DWORD len = name ? strlenW(name) : 0;
105 if (len >= MAX_PATH)
107 SetLastError( ERROR_FILENAME_EXCED_RANGE );
108 return 0;
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 );
116 ret = reply->handle;
118 SERVER_END_REQ;
119 return ret;
123 /***********************************************************************
124 * SetWaitableTimer (KERNEL32.@)
126 BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG period,
127 PTIMERAPCROUTINE callback, LPVOID arg, BOOL resume )
129 BOOL ret;
130 LARGE_INTEGER exp = *when;
132 if (exp.s.HighPart < 0) /* relative time */
134 LARGE_INTEGER now;
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 */
144 req->sec = 0;
145 req->usec = 0;
147 else
149 DWORD remainder;
150 FILETIME ft;
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;
160 req->arg = arg;
161 if (resume) SetLastError( ERROR_NOT_SUPPORTED ); /* set error but can still succeed */
162 ret = !wine_server_call_err( req );
164 SERVER_END_REQ;
165 return ret;
169 /***********************************************************************
170 * CancelWaitableTimer (KERNEL32.@)
172 BOOL WINAPI CancelWaitableTimer( HANDLE handle )
174 BOOL ret;
175 SERVER_START_REQ( cancel_timer )
177 req->handle = handle;
178 ret = !wine_server_call_err( req );
180 SERVER_END_REQ;
181 return ret;
185 /***********************************************************************
186 * CreateTimerQueue (KERNEL32.@)
188 HANDLE WINAPI CreateTimerQueue()
190 FIXME("stub\n");
191 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
192 return NULL;
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);
203 return 0;
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.
213 * RETURNS
214 * nonzero on success or zero on faillure
216 * BUGS
217 * Unimplemented
219 BOOL WINAPI CreateTimerQueueTimer( PHANDLE phNewTimer, HANDLE TimerQueue,
220 WAITORTIMERCALLBACK Callback, PVOID Parameter,
221 DWORD DueTime, DWORD Period, ULONG Flags )
223 FIXME("stub\n");
224 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
225 return TRUE;
228 /***********************************************************************
229 * DeleteTimerQueueTimer (KERNEL32.@)
231 * Cancels a timer-queue timer.
233 * RETURNS
234 * nonzero on success or zero on faillure
236 * BUGS
237 * Unimplemented
239 BOOL WINAPI DeleteTimerQueueTimer( HANDLE TimerQueue, HANDLE Timer,
240 HANDLE CompletionEvent )
242 FIXME("stub\n");
243 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
244 return TRUE;