1999-11-29 02:58:35 +01:00
|
|
|
/*
|
|
|
|
* Win32 waitable timers
|
|
|
|
*
|
|
|
|
* Copyright 1999 Alexandre Julliard
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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 */
|
|
|
|
#include "server.h"
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateWaitableTimerA (KERNEL32.861)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR name )
|
|
|
|
{
|
2000-08-30 02:00:48 +02:00
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0;
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SERVER_START_REQ
|
|
|
|
{
|
|
|
|
struct create_timer_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) );
|
|
|
|
|
|
|
|
req->manual = manual;
|
|
|
|
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
|
|
|
|
if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len );
|
|
|
|
SetLastError(0);
|
|
|
|
server_call( REQ_CREATE_TIMER );
|
|
|
|
ret = req->handle;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
|
|
|
|
return ret;
|
1999-11-29 02:58:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CreateWaitableTimerW (KERNEL32.862)
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
SERVER_START_REQ
|
|
|
|
{
|
|
|
|
struct create_timer_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) );
|
|
|
|
|
|
|
|
req->manual = manual;
|
|
|
|
req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
|
|
|
|
memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) );
|
|
|
|
SetLastError(0);
|
|
|
|
server_call( REQ_CREATE_TIMER );
|
|
|
|
ret = req->handle;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
|
|
|
|
return ret;
|
1999-11-29 02:58:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OpenWaitableTimerA (KERNEL32.881)
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name )
|
|
|
|
{
|
2000-08-30 02:00:48 +02:00
|
|
|
HANDLE ret;
|
|
|
|
DWORD len = name ? MultiByteToWideChar( CP_ACP, 0, name, strlen(name), NULL, 0 ) : 0;
|
|
|
|
if (len >= MAX_PATH)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_FILENAME_EXCED_RANGE );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SERVER_START_REQ
|
|
|
|
{
|
|
|
|
struct open_timer_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) );
|
|
|
|
|
|
|
|
req->access = access;
|
|
|
|
req->inherit = inherit;
|
|
|
|
if (len) MultiByteToWideChar( CP_ACP, 0, name, strlen(name), server_data_ptr(req), len );
|
|
|
|
server_call( REQ_OPEN_TIMER );
|
|
|
|
ret = req->handle;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
|
|
|
|
return ret;
|
1999-11-29 02:58:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* OpenWaitableTimerW (KERNEL32.882)
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
SERVER_START_REQ
|
|
|
|
{
|
|
|
|
struct open_timer_request *req = server_alloc_req( sizeof(*req), len * sizeof(WCHAR) );
|
|
|
|
|
|
|
|
req->access = access;
|
|
|
|
req->inherit = inherit;
|
|
|
|
memcpy( server_data_ptr(req), name, len * sizeof(WCHAR) );
|
|
|
|
server_call( REQ_OPEN_TIMER );
|
|
|
|
ret = req->handle;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
if (ret == -1) ret = 0; /* must return 0 on failure, not -1 */
|
|
|
|
return ret;
|
1999-11-29 02:58:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SetWaitableTimer (KERNEL32.894)
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
2000-08-30 02:00:48 +02:00
|
|
|
SERVER_START_REQ
|
1999-12-13 02:42:03 +01:00
|
|
|
{
|
2000-08-30 02:00:48 +02:00
|
|
|
struct set_timer_request *req = server_alloc_req( sizeof(*req), 0 );
|
|
|
|
|
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 */
|
|
|
|
ret = !server_call( REQ_SET_TIMER );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* CancelWaitableTimer (KERNEL32.857)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CancelWaitableTimer( HANDLE handle )
|
|
|
|
{
|
2000-08-30 02:00:48 +02:00
|
|
|
BOOL ret;
|
|
|
|
SERVER_START_REQ
|
|
|
|
{
|
|
|
|
struct cancel_timer_request *req = server_alloc_req( sizeof(*req), 0 );
|
|
|
|
req->handle = handle;
|
|
|
|
ret = !server_call( REQ_CANCEL_TIMER );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
1999-11-29 02:58:35 +01:00
|
|
|
}
|