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"
33 /***********************************************************************
34 * CreateWaitableTimerA (KERNEL32.@)
36 HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR name )
38 WCHAR buffer[MAX_PATH];
40 if (!name) return CreateWaitableTimerW( sa, manual, NULL );
42 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
44 SetLastError( ERROR_FILENAME_EXCED_RANGE );
47 return CreateWaitableTimerW( sa, manual, buffer );
51 /***********************************************************************
52 * CreateWaitableTimerW (KERNEL32.@)
54 HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name )
57 DWORD len = name ? strlenW(name) : 0;
60 SetLastError( ERROR_FILENAME_EXCED_RANGE );
63 SERVER_START_REQ( create_timer )
66 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
67 wine_server_add_data( req, name, len * sizeof(WCHAR) );
69 wine_server_call_err( req );
77 /***********************************************************************
78 * OpenWaitableTimerA (KERNEL32.@)
80 HANDLE WINAPI OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name )
82 WCHAR buffer[MAX_PATH];
84 if (!name) return OpenWaitableTimerW( access, inherit, NULL );
86 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
88 SetLastError( ERROR_FILENAME_EXCED_RANGE );
91 return OpenWaitableTimerW( access, inherit, buffer );
95 /***********************************************************************
96 * OpenWaitableTimerW (KERNEL32.@)
98 HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
101 DWORD len = name ? strlenW(name) : 0;
104 SetLastError( ERROR_FILENAME_EXCED_RANGE );
107 SERVER_START_REQ( open_timer )
109 req->access = access;
110 req->inherit = inherit;
111 wine_server_add_data( req, name, len * sizeof(WCHAR) );
112 wine_server_call_err( req );
120 /***********************************************************************
121 * SetWaitableTimer (KERNEL32.@)
123 BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG period,
124 PTIMERAPCROUTINE callback, LPVOID arg, BOOL resume )
127 LARGE_INTEGER exp = *when;
129 if (exp.s.HighPart < 0) /* relative time */
132 NtQuerySystemTime( &now );
133 exp.QuadPart = RtlLargeIntegerSubtract( now.QuadPart, exp.QuadPart );
136 SERVER_START_REQ( set_timer )
138 if (!exp.s.LowPart && !exp.s.HighPart)
140 /* special case to start timeout on now+period without too many calculations */
147 req->sec = DOSFS_FileTimeToUnixTime( (FILETIME *)&exp, &remainder );
148 req->usec = remainder / 10; /* convert from 100-ns to us units */
150 req->handle = handle;
151 req->period = period;
152 req->callback = callback;
154 if (resume) SetLastError( ERROR_NOT_SUPPORTED ); /* set error but can still succeed */
155 ret = !wine_server_call_err( req );
162 /***********************************************************************
163 * CancelWaitableTimer (KERNEL32.@)
165 BOOL WINAPI CancelWaitableTimer( HANDLE handle )
168 SERVER_START_REQ( cancel_timer )
170 req->handle = handle;
171 ret = !wine_server_call_err( req );