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"
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
);
50 return CreateWaitableTimerW( sa
, manual
, buffer
);
54 /***********************************************************************
55 * CreateWaitableTimerW (KERNEL32.@)
57 HANDLE WINAPI
CreateWaitableTimerW( SECURITY_ATTRIBUTES
*sa
, BOOL manual
, LPCWSTR name
)
60 DWORD len
= name
? strlenW(name
) : 0;
63 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
66 SERVER_START_REQ( create_timer
)
69 req
->inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
70 wine_server_add_data( req
, name
, len
* sizeof(WCHAR
) );
72 wine_server_call_err( req
);
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
);
94 return OpenWaitableTimerW( access
, inherit
, buffer
);
98 /***********************************************************************
99 * OpenWaitableTimerW (KERNEL32.@)
101 HANDLE WINAPI
OpenWaitableTimerW( DWORD access
, BOOL inherit
, LPCWSTR name
)
104 DWORD len
= name
? strlenW(name
) : 0;
107 SetLastError( ERROR_FILENAME_EXCED_RANGE
);
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
);
123 /***********************************************************************
124 * SetWaitableTimer (KERNEL32.@)
126 BOOL WINAPI
SetWaitableTimer( HANDLE handle
, const LARGE_INTEGER
*when
, LONG period
,
127 PTIMERAPCROUTINE callback
, LPVOID arg
, BOOL resume
)
130 LARGE_INTEGER exp
= *when
;
132 if (exp
.s
.HighPart
< 0) /* relative time */
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 */
150 req
->sec
= DOSFS_FileTimeToUnixTime( (FILETIME
*)&exp
, &remainder
);
151 req
->usec
= remainder
/ 10; /* convert from 100-ns to us units */
153 req
->handle
= handle
;
154 req
->period
= period
;
155 req
->callback
= callback
;
157 if (resume
) SetLastError( ERROR_NOT_SUPPORTED
); /* set error but can still succeed */
158 ret
= !wine_server_call_err( req
);
165 /***********************************************************************
166 * CancelWaitableTimer (KERNEL32.@)
168 BOOL WINAPI
CancelWaitableTimer( HANDLE handle
)
171 SERVER_START_REQ( cancel_timer
)
173 req
->handle
= handle
;
174 ret
= !wine_server_call_err( req
);
181 /***********************************************************************
182 * CreateTimerQueueTimer (KERNEL32.@)
184 * Creates a timer-queue timer. This timer expires at the specified due
185 * time (in ms), then after every specified period (in ms). When the timer
186 * expires, the callback function is called.
189 * nonzero on success or zero on faillure
194 BOOL WINAPI
CreateTimerQueueTimer( PHANDLE phNewTimer
, HANDLE TimerQueue
,
195 WAITORTIMERCALLBACK Callback
, PVOID Parameter
,
196 DWORD DueTime
, DWORD Period
, ULONG Flags
)
199 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
203 /***********************************************************************
204 * DeleteTimerQueueTimer (KERNEL32.@)
206 * Cancels a timer-queue timer.
209 * nonzero on success or zero on faillure
214 BOOL WINAPI
DeleteTimerQueueTimer( HANDLE TimerQueue
, HANDLE Timer
,
215 HANDLE CompletionEvent
)
218 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);