diff --git a/examples/examples/Misc/WatchGambasDirectory/.directory b/examples/examples/Misc/WatchGambasDirectory/.directory new file mode 100644 index 000000000..06dab1c8a --- /dev/null +++ b/examples/examples/Misc/WatchGambasDirectory/.directory @@ -0,0 +1,2 @@ +[Desktop Entry] +Icon=./.icon.png diff --git a/examples/examples/Misc/WatchGambasDirectory/.icon.png b/examples/examples/Misc/WatchGambasDirectory/.icon.png new file mode 100644 index 000000000..bba91fad1 Binary files /dev/null and b/examples/examples/Misc/WatchGambasDirectory/.icon.png differ diff --git a/examples/examples/Misc/WatchGambasDirectory/.project b/examples/examples/Misc/WatchGambasDirectory/.project new file mode 100644 index 000000000..1677162fb --- /dev/null +++ b/examples/examples/Misc/WatchGambasDirectory/.project @@ -0,0 +1,12 @@ +# Gambas Project File 3.0 +# Compiled with Gambas 3.5.90 +Title=WatchGambasDirectory +Startup=MMain +Icon=watch.svg +Version=3.5.91 +Component=gb.inotify +Description="Watch the Gambas temporary directory, /tmp/gambas.UID, to detect starting and ending Gambas processes.\n\nThis project shows basic usage of gb.inotify's Watch class without going very far in demonstrating its capabilities/available events." +Authors="(C) 2014 Tobias Boege , GPLv2+." +TabSize=2 +SourcePath=/tmp +Packager=1 diff --git a/examples/examples/Misc/WatchGambasDirectory/.src/MMain.module b/examples/examples/Misc/WatchGambasDirectory/.src/MMain.module new file mode 100644 index 000000000..741e520e4 --- /dev/null +++ b/examples/examples/Misc/WatchGambasDirectory/.src/MMain.module @@ -0,0 +1,53 @@ +' Gambas module file + +Private $hWatch As Watch + +Public Sub Main() + ' The watched events are determined automatically by the event handlers defined + $hWatch = New Watch("/tmp/gambas." & Str$(User.Id), True) As "GambasDirectory" + $hWatch.Tag = New Collection ' Save descendants here + + Print "I'm watching... You may now start Gambas projects." + Print "Return toggles Pause/Resume. Enter \"quit\" to quit." +End + +Public Sub Application_Read() + Dim sBuf As String + + Line Input sBuf + If sBuf = "quit" Then Quit + $hWatch.IsPaused = Not $hWatch.IsPaused + Print "Currently";; IIf($hWatch.IsPaused, "inactive", "active") +End + +Public Sub GambasDirectory_Create() + If Not Watch.IsDir Then Return ' Skip files + Print "New Gambas process:";; + ' Watch.Name is the PID of the new Gambas process. Try to get its name + ' from the /proc filesystem. + With Split(File.Load("/proc" &/ Watch.Name &/ "cmdline"), "/") + Last.Tag[Watch.Name] = Left$(.[.Max], -1) + Print Last.Tag[Watch.Name] + End With + + Catch + ' Opening the /proc file may fail because the directory may have been + ' deleted already (if the process was relatively short-lived and this + ' event took longer than that to get from the kernel to us). +End + +Public Sub GambasDirectory_Delete() + Dim sName As String + + If Not Watch.IsDir Then Return + sName = Last.Tag[Watch.Name] + ' Sadly, we can only provide a name for dying processes that we watched + ' being created -- the /proc file is already gone at this point. + ' + ' Note that if the interpreter crashes (the process ends abnormally), + ' directories won't be removed so we won't notice that the process is + ' gone. + If Not sName Then sName = "(unknown)" + Print sName;; "terminated (normally)" + Last.Tag.Remove(Watch.Name) +End diff --git a/examples/examples/Misc/WatchGambasDirectory/.startup b/examples/examples/Misc/WatchGambasDirectory/.startup new file mode 100644 index 000000000..5acb6dbda --- /dev/null +++ b/examples/examples/Misc/WatchGambasDirectory/.startup @@ -0,0 +1,8 @@ +MMain +WatchGambasDirectory +0 +0 +3.5.91 + +gb.inotify + diff --git a/examples/examples/Misc/WatchGambasDirectory/watch.svg b/examples/examples/Misc/WatchGambasDirectory/watch.svg new file mode 100644 index 000000000..758d0b7aa --- /dev/null +++ b/examples/examples/Misc/WatchGambasDirectory/watch.svg @@ -0,0 +1,1257 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file