2 * Win32 file change notification functions
4 * Copyright 1998 Ulrich Weigand
20 static BOOL32
CHANGE_Signaled( K32OBJ
*obj
, DWORD thread_id
);
21 static BOOL32
CHANGE_Satisfied( K32OBJ
*obj
, DWORD thread_id
);
22 static void CHANGE_AddWait( K32OBJ
*obj
, DWORD thread_id
);
23 static void CHANGE_RemoveWait( K32OBJ
*obj
, DWORD thread_id
);
24 static void CHANGE_Destroy( K32OBJ
*obj
);
26 const K32OBJ_OPS CHANGE_Ops
=
28 CHANGE_Signaled
, /* signaled */
29 CHANGE_Satisfied
, /* satisfied */
30 CHANGE_AddWait
, /* add_wait */
31 CHANGE_RemoveWait
, /* remove_wait */
34 CHANGE_Destroy
/* destroy */
37 /* The change notification object */
46 THREAD_QUEUE wait_queue
;
51 /***********************************************************************
54 static BOOL32
CHANGE_Signaled( K32OBJ
*obj
, DWORD thread_id
)
56 CHANGE_OBJECT
*change
= (CHANGE_OBJECT
*)obj
;
57 assert( obj
->type
== K32OBJ_CHANGE
);
58 return change
->notify
;
61 /***********************************************************************
64 * Wait on this object has been satisfied.
66 static BOOL32
CHANGE_Satisfied( K32OBJ
*obj
, DWORD thread_id
)
68 assert( obj
->type
== K32OBJ_CHANGE
);
69 return FALSE
; /* Not abandoned */
72 /***********************************************************************
75 * Add thread to object wait queue.
77 static void CHANGE_AddWait( K32OBJ
*obj
, DWORD thread_id
)
79 CHANGE_OBJECT
*change
= (CHANGE_OBJECT
*)obj
;
80 assert( obj
->type
== K32OBJ_CHANGE
);
81 THREAD_AddQueue( &change
->wait_queue
, THREAD_ID_TO_THDB(thread_id
) );
84 /***********************************************************************
87 * Remove thread from object wait queue.
89 static void CHANGE_RemoveWait( K32OBJ
*obj
, DWORD thread_id
)
91 CHANGE_OBJECT
*change
= (CHANGE_OBJECT
*)obj
;
92 assert( obj
->type
== K32OBJ_CHANGE
);
93 THREAD_RemoveQueue( &change
->wait_queue
, THREAD_ID_TO_THDB(thread_id
) );
96 /****************************************************************************
99 static void CHANGE_Destroy( K32OBJ
*obj
)
101 CHANGE_OBJECT
*change
= (CHANGE_OBJECT
*)obj
;
102 assert( obj
->type
== K32OBJ_CHANGE
);
104 if ( change
->lpPathName
)
106 HeapFree( SystemHeap
, 0, change
->lpPathName
);
107 change
->lpPathName
= NULL
;
110 obj
->type
= K32OBJ_UNKNOWN
;
111 HeapFree( SystemHeap
, 0, change
);
114 /****************************************************************************
115 * FindFirstChangeNotification32A (KERNEL32.248)
117 HANDLE32 WINAPI
FindFirstChangeNotification32A( LPCSTR lpPathName
,
118 BOOL32 bWatchSubtree
,
119 DWORD dwNotifyFilter
)
122 CHANGE_OBJECT
*change
;
124 change
= HeapAlloc( SystemHeap
, 0, sizeof(CHANGE_OBJECT
) );
125 if (!change
) return INVALID_HANDLE_VALUE32
;
127 change
->header
.type
= K32OBJ_CHANGE
;
128 change
->header
.refcount
= 1;
130 change
->lpPathName
= HEAP_strdupA( SystemHeap
, 0, lpPathName
);
131 change
->bWatchSubtree
= bWatchSubtree
;
132 change
->dwNotifyFilter
= dwNotifyFilter
;
134 change
->wait_queue
= NULL
;
135 change
->notify
= FALSE
;
137 handle
= HANDLE_Alloc( PROCESS_Current(), &change
->header
,
138 FILE_ALL_ACCESS
/*FIXME*/, TRUE
, -1 );
139 /* If the allocation failed, the object is already destroyed */
140 if (handle
== INVALID_HANDLE_VALUE32
) change
= NULL
;
144 /****************************************************************************
145 * FindFirstChangeNotification32W (KERNEL32.249)
147 HANDLE32 WINAPI
FindFirstChangeNotification32W( LPCWSTR lpPathName
,
148 BOOL32 bWatchSubtree
,
149 DWORD dwNotifyFilter
)
151 LPSTR nameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpPathName
);
152 HANDLE32 ret
= FindFirstChangeNotification32A( nameA
, bWatchSubtree
,
154 if (nameA
) HeapFree( GetProcessHeap(), 0, nameA
);
158 /****************************************************************************
159 * FindNextChangeNotification (KERNEL32.252)
161 BOOL32 WINAPI
FindNextChangeNotification( HANDLE32 handle
)
163 CHANGE_OBJECT
*change
;
166 if (!(change
= (CHANGE_OBJECT
*)HANDLE_GetObjPtr( PROCESS_Current(),
167 handle
, K32OBJ_CHANGE
,
168 0 /*FIXME*/, NULL
)) )
174 change
->notify
= FALSE
;
175 K32OBJ_DecCount( &change
->header
);
180 /****************************************************************************
181 * FindCloseChangeNotification (KERNEL32.247)
183 BOOL32 WINAPI
FindCloseChangeNotification( HANDLE32 handle
)
185 return CloseHandle( handle
);