[EXAMPLES]

* NEW: WatchGambasDirectory: gb.inotify example to demonstrate basic usage.



git-svn-id: svn://localhost/gambas/trunk@6401 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Tobias Boege 2014-07-28 03:10:33 +00:00
parent d3ec79a214
commit 70cbbe1879
6 changed files with 1332 additions and 0 deletions

View File

@ -0,0 +1,2 @@
[Desktop Entry]
Icon=./.icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -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 <tobias@gambas-buch.de>, GPLv2+."
TabSize=2
SourcePath=/tmp
Packager=1

View File

@ -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

View File

@ -0,0 +1,8 @@
MMain
WatchGambasDirectory
0
0
3.5.91
gb.inotify

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 53 KiB