1999-11-29 02:58:35 +01:00
|
|
|
/*
|
|
|
|
* Win32 waitable timers
|
|
|
|
*
|
|
|
|
* Copyright 1999 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1999-11-29 02:58:35 +01:00
|
|
|
*/
|
|
|
|
|
2002-08-29 01:42:34 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
1999-11-29 02:58:35 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "winerror.h"
|
2000-09-26 01:30:56 +02:00
|
|
|
#include "winnls.h"
|
2000-08-30 02:00:48 +02:00
|
|
|
#include "wine/unicode.h"
|
1999-11-29 02:58:35 +01:00
|
|
|
#include "file.h" /* for FILETIME routines */
|
2001-07-19 02:39:09 +02:00
|
|
|
#include "wine/server.h"
|
2002-10-07 23:46:02 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(timer);
|
1999-11-29 02:58:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateWaitableTimerA (KERNEL32.@)
|
1999-11-29 02:58:35 +01:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR name )
|
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return CreateWaitableTimerW( sa, manual, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2000-08-30 02:00:48 +02:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
return CreateWaitableTimerW( sa, manual, buffer );
|
1999-11-29 02:58:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CreateWaitableTimerW (KERNEL32.@)
|
1999-11-29 02:58:35 +01:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name )
|
|
|
|
{
|
2000-08-30 02:00:48 +02:00
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? strlenW(name) : 0;
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_START_REQ( create_timer )
|
2000-08-30 02:00:48 +02:00
|
|
|
{
|
|
|
|
req->manual = manual;
|
|
|
|
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
|
2001-11-30 19:46:42 +01:00
|
|
|
wine_server_add_data( req, name, len * sizeof(WCHAR) );
|
2000-08-30 02:00:48 +02:00
|
|
|
SetLastError(0);
|
2001-11-30 19:46:42 +01:00
|
|
|
wine_server_call_err( req );
|
|
|
|
ret = reply->handle;
|
2000-08-30 02:00:48 +02:00
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_END_REQ;
|
2000-08-30 02:00:48 +02:00
|
|
|
return ret;
|
1999-11-29 02:58:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* OpenWaitableTimerA (KERNEL32.@)
|
1999-11-29 02:58:35 +01:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name )
|
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
|
|
|
if (!name) return OpenWaitableTimerW( access, inherit, NULL );
|
|
|
|
|
|
|
|
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
|
2000-08-30 02:00:48 +02:00
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
return OpenWaitableTimerW( access, inherit, buffer );
|
1999-11-29 02:58:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* OpenWaitableTimerW (KERNEL32.@)
|
1999-11-29 02:58:35 +01:00
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
|
|
|
|
{
|
2000-08-30 02:00:48 +02:00
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? strlenW(name) : 0;
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_START_REQ( open_timer )
|
2000-08-30 02:00:48 +02:00
|
|
|
{
|
|
|
|
req->access = access;
|
|
|
|
req->inherit = inherit;
|
2001-11-30 19:46:42 +01:00
|
|
|
wine_server_add_data( req, name, len * sizeof(WCHAR) );
|
|
|
|
wine_server_call_err( req );
|
|
|
|
ret = reply->handle;
|
2000-08-30 02:00:48 +02:00
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_END_REQ;
|
2000-08-30 02:00:48 +02:00
|
|
|
return ret;
|
1999-11-29 02:58:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* SetWaitableTimer (KERNEL32.@)
|
1999-11-29 02:58:35 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG period,
|
|
|
|
PTIMERAPCROUTINE callback, LPVOID arg, BOOL resume )
|
|
|
|
{
|
2000-08-30 02:00:48 +02:00
|
|
|
BOOL ret;
|
2000-10-01 03:40:42 +02:00
|
|
|
LARGE_INTEGER exp = *when;
|
1999-11-29 02:58:35 +01:00
|
|
|
|
2000-10-01 03:40:42 +02:00
|
|
|
if (exp.s.HighPart < 0) /* relative time */
|
1999-11-29 02:58:35 +01:00
|
|
|
{
|
2000-10-01 03:40:42 +02:00
|
|
|
LARGE_INTEGER now;
|
|
|
|
NtQuerySystemTime( &now );
|
|
|
|
exp.QuadPart = RtlLargeIntegerSubtract( now.QuadPart, exp.QuadPart );
|
1999-11-29 02:58:35 +01:00
|
|
|
}
|
1999-12-13 02:42:03 +01:00
|
|
|
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_REQ( set_timer )
|
1999-12-13 02:42:03 +01:00
|
|
|
{
|
2000-10-01 03:40:42 +02:00
|
|
|
if (!exp.s.LowPart && !exp.s.HighPart)
|
2000-08-30 02:00:48 +02:00
|
|
|
{
|
|
|
|
/* special case to start timeout on now+period without too many calculations */
|
|
|
|
req->sec = 0;
|
|
|
|
req->usec = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-01 03:40:42 +02:00
|
|
|
DWORD remainder;
|
|
|
|
req->sec = DOSFS_FileTimeToUnixTime( (FILETIME *)&exp, &remainder );
|
2000-08-30 02:00:48 +02:00
|
|
|
req->usec = remainder / 10; /* convert from 100-ns to us units */
|
|
|
|
}
|
|
|
|
req->handle = handle;
|
|
|
|
req->period = period;
|
|
|
|
req->callback = callback;
|
|
|
|
req->arg = arg;
|
|
|
|
if (resume) SetLastError( ERROR_NOT_SUPPORTED ); /* set error but can still succeed */
|
2001-11-30 19:46:42 +01:00
|
|
|
ret = !wine_server_call_err( req );
|
1999-12-13 02:42:03 +01:00
|
|
|
}
|
2000-08-30 02:00:48 +02:00
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
1999-11-29 02:58:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-13 22:13:18 +02:00
|
|
|
* CancelWaitableTimer (KERNEL32.@)
|
1999-11-29 02:58:35 +01:00
|
|
|
*/
|
|
|
|
BOOL WINAPI CancelWaitableTimer( HANDLE handle )
|
|
|
|
{
|
2000-08-30 02:00:48 +02:00
|
|
|
BOOL ret;
|
2001-02-27 03:09:16 +01:00
|
|
|
SERVER_START_REQ( cancel_timer )
|
2000-08-30 02:00:48 +02:00
|
|
|
{
|
|
|
|
req->handle = handle;
|
2001-11-30 19:46:42 +01:00
|
|
|
ret = !wine_server_call_err( req );
|
2000-08-30 02:00:48 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
1999-11-29 02:58:35 +01:00
|
|
|
}
|
2002-10-07 23:46:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateTimerQueueTimer (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Creates a timer-queue timer. This timer expires at the specified due
|
|
|
|
* time (in ms), then after every specified period (in ms). When the timer
|
|
|
|
* expires, the callback function is called.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* nonzero on success or zero on faillure
|
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* Unimplemented
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CreateTimerQueueTimer( PHANDLE phNewTimer, HANDLE TimerQueue,
|
|
|
|
WAITORTIMERCALLBACK Callback, PVOID Parameter,
|
|
|
|
DWORD DueTime, DWORD Period, ULONG Flags )
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DeleteTimerQueueTimer (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Cancels a timer-queue timer.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* nonzero on success or zero on faillure
|
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* Unimplemented
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DeleteTimerQueueTimer( HANDLE TimerQueue, HANDLE Timer,
|
|
|
|
HANDLE CompletionEvent )
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return TRUE;
|
|
|
|
}
|