[Gambas-devel] About gb.inotify
Benoît Minisini
gambas at ...1...
Thu Jan 23 03:34:51 CET 2014
Hi,
Here is a few remarks about gb.inotify, wrote as I read your code. So I
may say rubbish. :-)
1) inotify is a Linux kernel specific thing. So I strongly suggest
finding a generic name for the class and the component. "PathWatch", or
just "Watch". If you find better, you're welcome!
2) Don't do:
path = GB.NewZeroString(GB.ToZeroString(ARG(path)));
Do instead:
path = GB.NewString(STRING(path), LENGTH(path));
One useless string copy avoided.
3) You can use GB.CanRaise() to know which event is handled by a new
object. Consequently, you will be able to define the inotify_add_watch()
mask automatically if the user does not specify it. No need to watch
everything by default!
4) I don't think the ".InotifyEvents" class with one property for each
event flag is really useful. As soon as you defined constants in the
Inotify class for each event, you can define a Inotify.Events property
as a pseudo-array of booleans:
Inotify.Events[Inotify.Access] = True
Or you can use methods :
Inotify.Add(INotify.Access + INotify.Attribute)
Inotify.Remove(...)
5) The harder : portability! The inotify equivalent of other systems are
usually not as powerful.
You should look at something like
http://pnotify.googlecode.com/svn/trunk/README to get an idea of what
not to implement in the hope of being portable. Maybe you can include
that library in your component if it is good. I didn't really look at it
: it is not maintained anymore.
For a better alternative, you have to look at
http://www.heily.com/~mheily/proj/libkqueue/ instead, and
http://people.freebsd.org/~jlemon/papers/kqueue.pdf
I just noted that kqueue watch file by file descriptor, which may be
annoying. But it can associate a user pointer to any event, so no need
to scan a linked list of Gambas objects!
If it is too difficult for you, just keep gb.inotify and fix the
previous points.
Enough for now, let's go to bed!
Regards,
--
Benoît Minisini
More information about the Devel
mailing list