// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
+using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using System.Security.Permissions;
using System.Threading;
namespace System.IO {
bool disposed;
string mangledFilter;
static IFileWatcher watcher;
- static object lockobj = new object ();
#endregion // Fields
InitWatcher ();
}
- [EnvironmentPermission (SecurityAction.Assert, Read="MONO_MANAGED_WATCHER")]
void InitWatcher ()
{
- lock (lockobj) {
+ lock (typeof (FileSystemWatcher)) {
if (watcher != null)
return;
mode = InternalSupportsFSW ();
bool ok = false;
- switch (mode) {
- case 1: // windows
+ if (mode == 3)
+ ok = KeventWatcher.GetInstance (out watcher);
+ else if (mode == 2)
+ ok = FAMWatcher.GetInstance (out watcher);
+ else if (mode == 1)
ok = DefaultWatcher.GetInstance (out watcher);
//ok = WindowsWatcher.GetInstance (out watcher);
- break;
- case 2: // libfam
- ok = FAMWatcher.GetInstance (out watcher, false);
- break;
- case 3: // kevent
- ok = KeventWatcher.GetInstance (out watcher);
- break;
- case 4: // libgamin
- ok = FAMWatcher.GetInstance (out watcher, true);
- break;
- case 5: // inotify
- ok = InotifyWatcher.GetInstance (out watcher, true);
- break;
- }
if (mode == 0 || !ok)
DefaultWatcher.GetInstance (out watcher);
throw new NotImplementedException ();
}
- enum EventType {
- FileSystemEvent,
- ErrorEvent,
- RenameEvent
- }
- private void RaiseEvent (Delegate ev, EventArgs arg, EventType evtype)
+ private void RaiseEvent (Delegate ev, EventArgs arg)
{
if (ev == null)
return;
+ object [] args = new object [] {this, arg};
+
if (synchronizingObject == null) {
- Delegate [] delegates = ev.GetInvocationList ();
- if (evtype == EventType.RenameEvent) {
- foreach (RenamedEventHandler d in delegates){
- d.BeginInvoke (this, (RenamedEventArgs) arg, null, null);
- }
- } else if (evtype == EventType.ErrorEvent) {
- foreach (ErrorEventHandler d in delegates){
- d.BeginInvoke (this, (ErrorEventArgs) arg, null, null);
- }
- } else {
- foreach (FileSystemEventHandler d in delegates){
- d.BeginInvoke (this, (FileSystemEventArgs) arg, null, null);
- }
- }
+ ev.DynamicInvoke (args);
return;
}
- synchronizingObject.BeginInvoke (ev, new object [] {this, arg});
+ synchronizingObject.BeginInvoke (ev, args);
}
protected void OnChanged (FileSystemEventArgs e)
{
- RaiseEvent (Changed, e, EventType.FileSystemEvent);
+ RaiseEvent (Changed, e);
}
protected void OnCreated (FileSystemEventArgs e)
{
- RaiseEvent (Created, e, EventType.FileSystemEvent);
+ RaiseEvent (Created, e);
}
protected void OnDeleted (FileSystemEventArgs e)
{
- RaiseEvent (Deleted, e, EventType.FileSystemEvent);
+ RaiseEvent (Deleted, e);
}
protected void OnError (ErrorEventArgs e)
{
- RaiseEvent (Error, e, EventType.ErrorEvent);
+ RaiseEvent (Error, e);
}
protected void OnRenamed (RenamedEventArgs e)
{
- RaiseEvent (Renamed, e, EventType.RenameEvent);
+ RaiseEvent (Renamed, e);
}
public WaitForChangedResult WaitForChanged (WatcherChangeTypes changeType)
}
lastData.OldName = filename;
lastData.ChangeType = WatcherChangeTypes.Renamed;
- renamed = new RenamedEventArgs (WatcherChangeTypes.Renamed, path, filename, "");
+ renamed = new RenamedEventArgs (WatcherChangeTypes.Renamed, path, null, filename);
break;
case FileAction.RenamedNewName:
lastData.Name = filename;
lastData.ChangeType = WatcherChangeTypes.Renamed;
- if (renamed == null) {
- renamed = new RenamedEventArgs (WatcherChangeTypes.Renamed, path, "", filename);
+ if (renamed != null) {
+ renamed.SetName (filename);
+ } else {
+ renamed = new RenamedEventArgs (WatcherChangeTypes.Renamed, path, filename, null);
}
OnRenamed (renamed);
renamed = null;
/* 0 -> not supported */
/* 1 -> windows */
/* 2 -> FAM */
- /* 3 -> Kevent */
- /* 4 -> gamin */
- /* 5 -> inotify */
[MethodImplAttribute(MethodImplOptions.InternalCall)]
static extern int InternalSupportsFSW ();
+
+ /*[MethodImplAttribute(MethodImplOptions.InternalCall)]
+ static extern IntPtr InternalOpenDirectory (string path, IntPtr reserved);
+
+ [MethodImplAttribute(MethodImplOptions.InternalCall)]
+ static extern IntPtr InternalCloseDirectory (IntPtr handle);
+
+ [MethodImplAttribute(MethodImplOptions.InternalCall)]
+ static extern bool InternalReadDirectoryChanges (IntPtr handle,
+ byte [] buffer,
+ bool includeSubdirectories,
+ NotifyFilters notifyFilter,
+ out NativeOverlapped overlap,
+ OverlappedHandler overlappedCallback);
+
+ */
}
}
-