KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > resources > refresh > win32 > Win32Natives


1 /*******************************************************************************
2  * Copyright (c) 2002, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.resources.refresh.win32;
12
13
14 /**
15  * Hooks for native methods involved with win32 auto-refresh callbacks.
16  */

17 public class Win32Natives {
18     /* general purpose */
19     /**
20      * A general use constant expressing the value of an
21      * invalid handle.
22      */

23     public static final long INVALID_HANDLE_VALUE;
24     /**
25      * An error constant which indicates that the previous function
26      * succeeded.
27      */

28     public static final int ERROR_SUCCESS;
29     /**
30      * An error constant which indicates that a handle is or has become
31      * invalid.
32      */

33     public static final int ERROR_INVALID_HANDLE;
34     /**
35      * The combination of all of the error constants.
36      */

37     public static int FILE_NOTIFY_ALL;
38     /**
39      * A constant which indicates the maximum number of objects
40      * that can be passed into WaitForMultipleObjects.
41      */

42     public static final int MAXIMUM_WAIT_OBJECTS;
43     /**
44      * A constant which indicates the maximum length of a pathname.
45      */

46     public static final int MAX_PATH;
47     /**
48      * A constant which expresses the concept of the infinite.
49      */

50     public static final int INFINITE;
51
52     /* wait return values */
53     /**
54      * A constant used returned WaitForMultipleObjects when the function times out.
55      */

56     public static final int WAIT_TIMEOUT;
57     /**
58      * A constant used by WaitForMultipleObjects to indicate the object which was
59      * signaled.
60      */

61     public static final int WAIT_OBJECT_0;
62     /**
63      * A constant returned by WaitForMultipleObjects which indicates
64      * that the wait failed.
65      */

66     public static final int WAIT_FAILED;
67
68     /* wait notification filter masks */
69     /**
70      * Change filter for monitoring file rename, creation or deletion.
71      */

72     public static final int FILE_NOTIFY_CHANGE_FILE_NAME;
73     /**
74      * Change filter for monitoring directory creation or deletion.
75      */

76     public static final int FILE_NOTIFY_CHANGE_DIR_NAME;
77     /**
78      * Change filter for monitoring file/directory attribute changes.
79      */

80     public static final int FILE_NOTIFY_CHANGE_ATTRIBUTES;
81     /**
82      * Change filter for monitoring file size changes.
83      */

84     public static final int FILE_NOTIFY_CHANGE_SIZE;
85     /**
86      * Change filter for monitoring the file write timestamp
87      */

88     public static final int FILE_NOTIFY_CHANGE_LAST_WRITE;
89     /**
90      * Change filter for monitoring the security descriptors
91      * of files.
92      */

93     public static final int FILE_NOTIFY_CHANGE_SECURITY;
94
95     /**
96      * Flag indicating whether or not the OS supports unicode calls.
97      */

98     public static final boolean UNICODE;
99     /*
100      * Make requests to set the constants.
101      */

102     static {
103         System.loadLibrary("win32refresh"); //$NON-NLS-1$
104
UNICODE= IsUnicode();
105         INVALID_HANDLE_VALUE= INVALID_HANDLE_VALUE();
106         ERROR_SUCCESS= ERROR_SUCCESS();
107         ERROR_INVALID_HANDLE= ERROR_INVALID_HANDLE();
108         
109         MAXIMUM_WAIT_OBJECTS= MAXIMUM_WAIT_OBJECTS();
110         MAX_PATH= MAX_PATH();
111         INFINITE= INFINITE();
112         
113         WAIT_TIMEOUT= WAIT_TIMEOUT();
114         WAIT_OBJECT_0= WAIT_OBJECT_0();
115         WAIT_FAILED= WAIT_FAILED();
116         
117         FILE_NOTIFY_CHANGE_FILE_NAME= FILE_NOTIFY_CHANGE_FILE_NAME();
118         FILE_NOTIFY_CHANGE_DIR_NAME= FILE_NOTIFY_CHANGE_DIR_NAME();
119         FILE_NOTIFY_CHANGE_ATTRIBUTES= FILE_NOTIFY_CHANGE_ATTRIBUTES();
120         FILE_NOTIFY_CHANGE_SIZE= FILE_NOTIFY_CHANGE_SIZE();
121         FILE_NOTIFY_CHANGE_LAST_WRITE= FILE_NOTIFY_CHANGE_LAST_WRITE();
122         FILE_NOTIFY_CHANGE_SECURITY= FILE_NOTIFY_CHANGE_SECURITY();
123         FILE_NOTIFY_ALL=
124             FILE_NOTIFY_CHANGE_FILE_NAME |
125             FILE_NOTIFY_CHANGE_DIR_NAME |
126             FILE_NOTIFY_CHANGE_ATTRIBUTES |
127             FILE_NOTIFY_CHANGE_SIZE |
128             FILE_NOTIFY_CHANGE_LAST_WRITE |
129             FILE_NOTIFY_CHANGE_SECURITY;
130     }
131
132     /**
133      * Creates a change notification object for the given path. The notification
134      * object allows the client to monitor changes to the directory and the
135      * subtree under the directory using FindNextChangeNotification or
136      * WaitForMultipleObjects.
137      * <p>
138      * If the OS supports unicode the path must be no longer than 2^15 - 1 characters.
139      * Otherwise, the path cannot be longer than MAX_PATH. In either case, if the given
140      * path is too long ERROR_INVALID_HANDLE is returned.
141      *
142      * @param lpPathName The path of the file.
143      * @param bWatchSubtree If <code>true</code>, specifies that the entire
144      * tree under the given path should be monitored. If <code>false</code>
145      * specifies that just the named path should be monitored.
146      * @param dwNotifyFilter Any combination of FILE_NOTIFY_CHANGE_FILE_NAME,
147      * FILE_NOTIFY_CHANGE_DIR_NAME, FILE_NOTIFY_CHANGE_ATTRIBUTES,
148      * FILE_NOTIFY_CHANGE_SIZE, FILE_NOTIFY_CHANGE_LAST_WRITE, or
149      * FILE_NOTIFY_CHANGE_SECURITY.
150      * @return long The handle to the find change notification object or
151      * ERROR_INVALID_HANDLE if the attempt fails.
152      */

153     public static long FindFirstChangeNotification(String JavaDoc lpPathName, boolean bWatchSubtree, int dwNotifyFilter) {
154         if (UNICODE)
155             return FindFirstChangeNotificationW(lpPathName, bWatchSubtree, dwNotifyFilter);
156         return FindFirstChangeNotificationA(Convert.toPlatformBytes(lpPathName), bWatchSubtree, dwNotifyFilter);
157     }
158     /**
159      * Creates a change notification object for the given path. This notification object
160      * allows the client to monitor changes to the directory and the subtree
161      * under the directory using FindNextChangeNotification or
162      * WaitForMultipleObjects.
163      *
164      * @param lpPathName The path to the directory to be monitored. Cannot be <code>null</code>,
165      * or longer than 2^15 - 1 characters.
166      * @param bWatchSubtree If <code>true</code>, specifies that the entire
167      * tree under the given path should be monitored. If <code>false</code>
168      * specifies that just the named path should be monitored.
169      * @param dwNotifyFilter Any combination of FILE_NOTIFY_CHANGE_FILE_NAME,
170      * FILE_NOTIFY_CHANGE_DIR_NAME, FILE_NOTIFY_CHANGE_ATTRIBUTES,
171      * FILE_NOTIFY_CHANGE_SIZE, FILE_NOTIFY_CHANGE_LAST_WRITE, or
172      * FILE_NOTIFY_CHANGE_SECURITY.
173      * @return long The handle to the find change notification object or
174      * ERROR_INVALID_HANDLE if the attempt fails.
175      */

176     private static native long FindFirstChangeNotificationW(String JavaDoc lpPathName, boolean bWatchSubtree, int dwNotifyFilter);
177     
178     /**
179      * Creates a change notification object for the given path. This notification object
180      * allows the client to monitor changes to the directory and the subtree
181      * under the directory using FindNextChangeNotification or
182      * WaitForMultipleObjects.
183      *
184      * @param lpPathName The path to the directory to be monitored, cannot be <code>null</code>,
185      * or be longer
186      * than MAX_PATH. This path must be in platform bytes converted.
187      * @param bWatchSubtree If <code>true</code>, specifies that the entire
188      * tree under the given path should be monitored. If <code>false</code>
189      * specifies that just the named path should be monitored.
190      * @param dwNotifyFilter Any combination of FILE_NOTIFY_CHANGE_FILE_NAME,
191      * FILE_NOTIFY_CHANGE_DIR_NAME, FILE_NOTIFY_CHANGE_ATTRIBUTES,
192      * FILE_NOTIFY_CHANGE_SIZE, FILE_NOTIFY_CHANGE_LAST_WRITE, or
193      * FILE_NOTIFY_CHANGE_SECURITY.
194      * @return long The handle to the find change notification object or
195      * ERROR_INVALID_HANDLE if the attempt fails.
196      */

197     private static native long FindFirstChangeNotificationA(byte[] lpPathName, boolean bWatchSubtree, int dwNotifyFilter);
198
199
200     /**
201      * Stops and disposes of the change notification object that corresponds to the given
202      * handle. The handle cannot be used in future calls to FindNextChangeNotification or
203      * WaitForMultipleObjects
204      *
205      * @param hChangeHandle a handle which was created with FindFirstChangeNotification
206      * @return boolean <code>true</code> if the method succeeds, <code>false</code>
207      * otherwise.
208      */

209     public static native boolean FindCloseChangeNotification(long hChangeHandle);
210
211     /**
212      * Requests that the next change detected be signaled. This method should only be
213      * called after FindFirstChangeNotification or WaitForMultipleObjects. Once this
214      * method has been called on a given handle, further notification requests can be made
215      * through the WaitForMultipleObjects call.
216      * @param hChangeHandle a handle which was created with FindFirstChangeNotification
217      * @return boolean <code>true</code> if the method succeeds, <code>false</code> otherwise.
218      */

219     public static native boolean FindNextChangeNotification(long hChangeHandle);
220
221     /**
222      * Returns when one of the following occurs.
223      * <ul>
224      * <li>One of the objects is signaled, when bWaitAll is <code>false</code></li>
225      * <li>All of the objects are signaled, when bWaitAll is <code>true</code></li>
226      * <li>The timeout interval of dwMilliseconds elapses.</li>
227      * </ul>
228      * @param nCount The number of handles, cannot be greater than MAXIMUM_WAIT_OBJECTS.
229      * @param lpHandles The array of handles to objects to be waited upon cannot contain
230      * duplicate handles.
231      * @param bWaitAll If <code>true</code> requires all objects to be signaled before this
232      * method returns. If <code>false</code>, indicates that only one object need be
233      * signaled for this method to return.
234      * @param dwMilliseconds A timeout value in milliseconds. If zero, the function tests
235      * the objects and returns immediately. If INFINITE, the function will only return
236      * when the objects have been signaled.
237      * @return int WAIT_TIMEOUT when the function times out before recieving a signal.
238      * WAIT_OBJECT_0 + n when a signal for the handle at index n. WAIT_FAILED when this
239      * function fails.
240      */

241     public static native int WaitForMultipleObjects(int nCount, long[] lpHandles, boolean bWaitAll, int dwMilliseconds);
242     
243     /**
244      * Answers <code>true</code> if the operating system supports
245      * long filenames.
246      * @return boolean <code>true</code> if the operating system supports
247      * long filenames, <code>false</code> otherwise.
248      */

249     private static native boolean IsUnicode();
250     
251     /**
252      * Answers the last error set in the current thread.
253      * @return int the last error
254      */

255     public static native int GetLastError();
256
257     /**
258      * Returns the constant FILE_NOTIFY_CHANGE_LAST_WRITE.
259      * @return int
260      */

261     private static native int FILE_NOTIFY_CHANGE_LAST_WRITE();
262     
263     /**
264      * Returns the constant FILE_NOTIFY_CHANGE_DIR_NAME.
265      * @return int
266      */

267     private static native int FILE_NOTIFY_CHANGE_DIR_NAME();
268     
269     /**
270      * Returns the constant FILE_NOTIFY_CHANGE_ATTRIBUTES.
271      * @return int
272      */

273     private static native int FILE_NOTIFY_CHANGE_ATTRIBUTES();
274     
275     /**
276      * Returns the constant FILE_NOTIFY_CHANGE_SIZE.
277      * @return int
278      */

279     private static native int FILE_NOTIFY_CHANGE_SIZE();
280     
281     /**
282      * Returns the constant FILE_NOTIFY_CHANGE_FILE_NAME.
283      * @return int
284      */

285     private static native int FILE_NOTIFY_CHANGE_FILE_NAME();
286     
287     /**
288      * Returns the constant FILE_NOTIFY_CHANGE_SECURITY.
289      * @return int
290      */

291     private static native int FILE_NOTIFY_CHANGE_SECURITY();
292
293     /**
294      * Returns the constant MAXIMUM_WAIT_OBJECTS.
295      * @return int
296      */

297     private static native int MAXIMUM_WAIT_OBJECTS();
298     
299     /**
300      * Returns the constant MAX_PATH.
301      * @return int
302      */

303     private static native int MAX_PATH();
304
305     /**
306      * Returns the constant INFINITE.
307      * @return int
308      */

309     private static native int INFINITE();
310         
311     /**
312      * Returns the constant WAIT_OBJECT_0.
313      * @return int
314      */

315     private static native int WAIT_OBJECT_0();
316
317     /**
318      * Returns the constant WAIT_FAILED.
319      * @return int
320      */

321     private static native int WAIT_FAILED();
322     
323     /**
324      * Returns the constant WAIT_TIMEOUT.
325      * @return int
326      */

327     private static native int WAIT_TIMEOUT();
328     
329     /**
330      * Returns the constant ERROR_INVALID_HANDLE.
331      * @return int
332      */

333     private static native int ERROR_INVALID_HANDLE();
334     
335     /**
336      * Returns the constant ERROR_SUCCESS.
337      * @return int
338      */

339     private static native int ERROR_SUCCESS();
340     
341     /**
342      * Returns the constant INVALID_HANDLE_VALUE.
343      * @return long
344      */

345     private static native long INVALID_HANDLE_VALUE();
346
347 }
348
Popular Tags