Fixed handling of DGA2.0 keyboard events.
[wine] / scheduler / timer.c
1 /*
2  * Win32 waitable timers
3  *
4  * Copyright 1999 Alexandre Julliard
5  */
6
7 #include <assert.h>
8 #include <string.h>
9 #include "winerror.h"
10 #include "file.h"  /* for FILETIME routines */
11 #include "server.h"
12
13
14 /***********************************************************************
15  *           CreateWaitableTimerA    (KERNEL32.861)
16  */
17 HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR name )
18 {
19     struct create_timer_request *req = get_req_buffer();
20
21     req->manual  = manual;
22     req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
23     server_strcpyAtoW( req->name, name );
24     SetLastError(0);
25     server_call( REQ_CREATE_TIMER );
26     if (req->handle == -1) return 0;
27     return req->handle;
28 }
29
30
31 /***********************************************************************
32  *           CreateWaitableTimerW    (KERNEL32.862)
33  */
34 HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name )
35 {
36     struct create_timer_request *req = get_req_buffer();
37
38     req->manual  = manual;
39     req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
40     server_strcpyW( req->name, name );
41     SetLastError(0);
42     server_call( REQ_CREATE_TIMER );
43     if (req->handle == -1) return 0;
44     return req->handle;
45 }
46
47
48 /***********************************************************************
49  *           OpenWaitableTimerA    (KERNEL32.881)
50  */
51 HANDLE WINAPI OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name )
52 {
53     struct open_timer_request *req = get_req_buffer();
54
55     req->access  = access;
56     req->inherit = inherit;
57     server_strcpyAtoW( req->name, name );
58     server_call( REQ_OPEN_TIMER );
59     if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */
60     return req->handle;
61 }
62
63
64 /***********************************************************************
65  *           OpenWaitableTimerW    (KERNEL32.882)
66  */
67 HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
68 {
69     struct open_timer_request *req = get_req_buffer();
70
71     req->access  = access;
72     req->inherit = inherit;
73     server_strcpyW( req->name, name );
74     server_call( REQ_OPEN_TIMER );
75     if (req->handle == -1) return 0; /* must return 0 on failure, not -1 */
76     return req->handle;
77 }
78
79
80 /***********************************************************************
81  *           SetWaitableTimer    (KERNEL32.894)
82  */
83 BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG period,
84                               PTIMERAPCROUTINE callback, LPVOID arg, BOOL resume )
85 {
86     FILETIME ft;
87     DWORD remainder;
88     struct set_timer_request *req = get_req_buffer();
89
90     if (when->s.HighPart < 0)  /* relative time */
91     {
92         DWORD low = ft.dwLowDateTime;
93         GetSystemTimeAsFileTime( &ft );
94         ft.dwLowDateTime -= when->s.LowPart;
95         ft.dwHighDateTime -= when->s.HighPart;
96         if (low < ft.dwLowDateTime) ft.dwHighDateTime--; /* overflow */
97     }
98     else  /* absolute time */
99     {
100         ft.dwLowDateTime = when->s.LowPart;
101         ft.dwHighDateTime = when->s.HighPart;
102     }
103     req->handle   = handle;
104     req->sec      = DOSFS_FileTimeToUnixTime( &ft, &remainder );
105     req->usec     = remainder / 10;  /* convert from 100-ns to us units */
106     req->period   = period;
107     req->callback = callback;
108     req->arg      = arg;
109     if (resume) SetLastError( ERROR_NOT_SUPPORTED ); /* set error but can still succeed */
110     return !server_call( REQ_SET_TIMER );
111 }
112
113
114 /***********************************************************************
115  *           CancelWaitableTimer    (KERNEL32.857)
116  */
117 BOOL WINAPI CancelWaitableTimer( HANDLE handle )
118 {
119     struct cancel_timer_request *req = get_req_buffer();
120     req->handle = handle;
121     return !server_call( REQ_CANCEL_TIMER );
122 }