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
25 #include "wine/unicode.h"
26 #include "file.h" /* for FILETIME routines */
27 #include "wine/server.h"
30 /***********************************************************************
31 * CreateWaitableTimerA (KERNEL32.@)
33 HANDLE WINAPI
CreateWaitableTimerA( SECURITY_ATTRIBUTES
*sa
, BOOL manual
, LPCSTR name
)
35 WCHAR buffer
[MAX_PATH
];
37 if (!name
) return CreateWaitableTimerW( sa
, manual
, NULL
);
39 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, buffer
, MAX_PATH
))
41 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
44 return CreateWaitableTimerW( sa
, manual
, buffer
);
48 /***********************************************************************
49 * CreateWaitableTimerW (KERNEL32.@)
51 HANDLE WINAPI
CreateWaitableTimerW( SECURITY_ATTRIBUTES
*sa
, BOOL manual
, LPCWSTR name
)
54 DWORD len
= name
? strlenW(name
) : 0;
57 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
60 SERVER_START_REQ( create_timer
)
63 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
64 wine_server_add_data( req
, name
, len
* sizeof(WCHAR
) );
66 wine_server_call_err( req
);
74 /***********************************************************************
75 * OpenWaitableTimerA (KERNEL32.@)
77 HANDLE WINAPI
OpenWaitableTimerA( DWORD access
, BOOL inherit
, LPCSTR name
)
79 WCHAR buffer
[MAX_PATH
];
81 if (!name
) return OpenWaitableTimerW( access
, inherit
, NULL
);
83 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, buffer
, MAX_PATH
))
85 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
88 return OpenWaitableTimerW( access
, inherit
, buffer
);
92 /***********************************************************************
93 * OpenWaitableTimerW (KERNEL32.@)
95 HANDLE WINAPI
OpenWaitableTimerW( DWORD access
, BOOL inherit
, LPCWSTR name
)
98 DWORD len
= name
? strlenW(name
) : 0;
101 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
104 SERVER_START_REQ( open_timer
)
106 req
->access
= access
;
107 req
->inherit
= inherit
;
108 wine_server_add_data( req
, name
, len
* sizeof(WCHAR
) );
109 wine_server_call_err( req
);
117 /***********************************************************************
118 * SetWaitableTimer (KERNEL32.@)
120 BOOL WINAPI
SetWaitableTimer( HANDLE handle
, const LARGE_INTEGER
*when
, LONG period
,
121 PTIMERAPCROUTINE callback
, LPVOID arg
, BOOL resume
)
124 LARGE_INTEGER exp
= *when
;
126 if (exp
.s
.HighPart
< 0) /* relative time */
129 NtQuerySystemTime( &now
);
130 exp
.QuadPart
= RtlLargeIntegerSubtract( now
.QuadPart
, exp
.QuadPart
);
133 SERVER_START_REQ( set_timer
)
135 if (!exp
.s
.LowPart
&& !exp
.s
.HighPart
)
137 /* special case to start timeout on now+period without too many calculations */
144 req
->sec
= DOSFS_FileTimeToUnixTime( (FILETIME
*)&exp
, &remainder
);
145 req
->usec
= remainder
/ 10; /* convert from 100-ns to us units */
147 req
->handle
= handle
;
148 req
->period
= period
;
149 req
->callback
= callback
;
151 if (resume
) SetLastError( ERROR_NOT_SUPPORTED
); /* set error but can still succeed */
152 ret
= !wine_server_call_err( req
);
159 /***********************************************************************
160 * CancelWaitableTimer (KERNEL32.@)
162 BOOL WINAPI
CancelWaitableTimer( HANDLE handle
)
165 SERVER_START_REQ( cancel_timer
)
167 req
->handle
= handle
;
168 ret
= !wine_server_call_err( req
);