2 * Win32 file change notification functions
4 * Copyright 1998 Ulrich Weigand
21 static BOOL32
CHANGE_Signaled( K32OBJ
*obj
, DWORD thread_id
);
22 static BOOL32
CHANGE_Satisfied( K32OBJ
*obj
, DWORD thread_id
);
23 static void CHANGE_AddWait( K32OBJ
*obj
, DWORD thread_id
);
24 static void CHANGE_RemoveWait( K32OBJ
*obj
, DWORD thread_id
);
25 static void CHANGE_Destroy( K32OBJ
*obj
);
27 const K32OBJ_OPS CHANGE_Ops
=
29 CHANGE_Signaled
, /* signaled */
30 CHANGE_Satisfied
, /* satisfied */
31 CHANGE_AddWait
, /* add_wait */
32 CHANGE_RemoveWait
, /* remove_wait */
35 CHANGE_Destroy
/* destroy */
38 /* The change notification object */
47 THREAD_QUEUE wait_queue
;
52 /***********************************************************************
55 static BOOL32
CHANGE_Signaled( K32OBJ
*obj
, DWORD thread_id
)
57 CHANGE_OBJECT
*change
= (CHANGE_OBJECT
*)obj
;
58 assert( obj
->type
== K32OBJ_CHANGE
);
59 return change
->notify
;
62 /***********************************************************************
65 * Wait on this object has been satisfied.
67 static BOOL32
CHANGE_Satisfied( K32OBJ
*obj
, DWORD thread_id
)
69 assert( obj
->type
== K32OBJ_CHANGE
);
70 return FALSE
; /* Not abandoned */
73 /***********************************************************************
76 * Add thread to object wait queue.
78 static void CHANGE_AddWait( K32OBJ
*obj
, DWORD thread_id
)
80 CHANGE_OBJECT
*change
= (CHANGE_OBJECT
*)obj
;
81 assert( obj
->type
== K32OBJ_CHANGE
);
82 THREAD_AddQueue( &change
->wait_queue
, THREAD_ID_TO_THDB(thread_id
) );
85 /***********************************************************************
88 * Remove thread from object wait queue.
90 static void CHANGE_RemoveWait( K32OBJ
*obj
, DWORD thread_id
)
92 CHANGE_OBJECT
*change
= (CHANGE_OBJECT
*)obj
;
93 assert( obj
->type
== K32OBJ_CHANGE
);
94 THREAD_RemoveQueue( &change
->wait_queue
, THREAD_ID_TO_THDB(thread_id
) );
97 /****************************************************************************
100 static void CHANGE_Destroy( K32OBJ
*obj
)
102 CHANGE_OBJECT
*change
= (CHANGE_OBJECT
*)obj
;
103 assert( obj
->type
== K32OBJ_CHANGE
);
105 if ( change
->lpPathName
)
107 HeapFree( SystemHeap
, 0, change
->lpPathName
);
108 change
->lpPathName
= NULL
;
111 obj
->type
= K32OBJ_UNKNOWN
;
112 HeapFree( SystemHeap
, 0, change
);
115 /****************************************************************************
116 * FindFirstChangeNotification32A (KERNEL32.248)
118 HANDLE32 WINAPI
FindFirstChangeNotification32A( LPCSTR lpPathName
,
119 BOOL32 bWatchSubtree
,
120 DWORD dwNotifyFilter
)
123 CHANGE_OBJECT
*change
;
125 change
= HeapAlloc( SystemHeap
, 0, sizeof(CHANGE_OBJECT
) );
126 if (!change
) return INVALID_HANDLE_VALUE32
;
128 change
->header
.type
= K32OBJ_CHANGE
;
129 change
->header
.refcount
= 1;
131 change
->lpPathName
= HEAP_strdupA( SystemHeap
, 0, lpPathName
);
132 change
->bWatchSubtree
= bWatchSubtree
;
133 change
->dwNotifyFilter
= dwNotifyFilter
;
135 change
->wait_queue
= NULL
;
136 change
->notify
= FALSE
;
138 handle
= HANDLE_Alloc( PROCESS_Current(), &change
->header
,
139 FILE_ALL_ACCESS
/*FIXME*/, TRUE
, -1 );
140 /* If the allocation failed, the object is already destroyed */
141 if (handle
== INVALID_HANDLE_VALUE32
) change
= NULL
;
145 /****************************************************************************
146 * FindFirstChangeNotification32W (KERNEL32.249)
148 HANDLE32 WINAPI
FindFirstChangeNotification32W( LPCWSTR lpPathName
,
149 BOOL32 bWatchSubtree
,
150 DWORD dwNotifyFilter
)
152 LPSTR nameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpPathName
);
153 HANDLE32 ret
= FindFirstChangeNotification32A( nameA
, bWatchSubtree
,
155 if (nameA
) HeapFree( GetProcessHeap(), 0, nameA
);
159 /****************************************************************************
160 * FindNextChangeNotification (KERNEL32.252)
162 BOOL32 WINAPI
FindNextChangeNotification( HANDLE32 handle
)
164 CHANGE_OBJECT
*change
;
167 if (!(change
= (CHANGE_OBJECT
*)HANDLE_GetObjPtr( PROCESS_Current(),
168 handle
, K32OBJ_CHANGE
,
169 0 /*FIXME*/, NULL
)) )
175 change
->notify
= FALSE
;
176 K32OBJ_DecCount( &change
->header
);
181 /****************************************************************************
182 * FindCloseChangeNotification (KERNEL32.247)
184 BOOL32 WINAPI
FindCloseChangeNotification( HANDLE32 handle
)
186 return CloseHandle( handle
);