|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Monitoring directory changes with gnomevfs
Hi List,
I'm trying to use the directory monitoring API in gnomevfs, but I'm having difficulty understanding how it is supposed to be used. The documentation at http://library.gnome.org/devel/gnome-vfs-2.0/unstable/gnome-vfs-20-gnome-vfs-monitor.html doesn't have any examples and I haven't been able to find a simple example on the web. The API seems simple enough, but I'm not sure I understand how the callback mechanism is supposed to work. (This probably reflects a deeper lack of understanding of glib, but I'll persist...) For example, I gather this program won't work because there is no GMainLoop in place to generate the callback: #include <libgnomevfs/gnome-vfs.h> int exit=0; static void MonitorCallback(GnomeVFSMonitorHandle *handle, const gchar *monitor_uri, const gchar *info_uri, GnomeVFSMonitorEventType event_type, gpointer user_data) { exit=1; } int main() { if(!gnome_vfs_initialized()) gnome_vfs_init(); GnomeVFSMonitorHandle *h; gnome_vfs_monitor_add(&h, "/home/myusername", GNOME_VFS_MONITOR_DIRECTORY, MonitorCallback, NULL); while(!exit); gnome_vfs_monitor_cancel(h); return 0; } but something like this should work correctly? #include <glib.h> #include <libgnomevfs/gnome-vfs.h> static void MonitorCallback(GnomeVFSMonitorHandle *handle, const gchar *monitor_uri, const gchar *info_uri, GnomeVFSMonitorEventType event_type, gpointer user_data) { g_print("Monitor event received, exiting...\n"); g_main_loop_quit((GMainLoop*)user_data); } int main() { if(!gnome_vfs_initialized()) gnome_vfs_init(); GMainLoop *loop; loop = g_main_loop_new(NULL, FALSE); GnomeVFSMonitorHandle *h; gnome_vfs_monitor_add(&h, "/home/myusername", GNOME_VFS_MONITOR_DIRECTORY, MonitorCallback, loop); g_main_loop_run(loop); gnome_vfs_monitor_cancel(h); return 0; } Can someone can give me an idea of whether the above should work or what I would need to do to that simple example to get it working? Looking at the above I don't really understand how glib would know how to attach the MonitorCallback to the GMainLoop, which isn't even running yet (if I created and started another main loop inside the outer loop, would it also generate callbacks?). thanks, D _______________________________________________ gnome-vfs-list mailing list gnome-vfs-list@... http://mail.gnome.org/mailman/listinfo/gnome-vfs-list |
|
|
Re: Monitoring directory changes with gnomevfsOn Thu, 2008-08-28 at 10:01 -0400, Damien Moore wrote:
> Can someone can give me an idea of whether the above should work or > what I would need to do to that simple example to get it working? > Looking at the above I don't really understand how glib would know how > to attach the MonitorCallback to the GMainLoop, which isn't even > running yet (if I created and started another main loop inside the > outer loop, would it also generate callbacks?). You're correct that you must spin the main loop for callbacks to work. The default main loop is global, so gnome-vfs will be able to find it and add the callback even if it's not running or passed in. These days you should be using GIO/GVFS instead of gnome-vfs, though. Take a look at the documentation here: http://library.gnome.org/devel/gio/stable/ GIO is part of GLib. You can read more about main loops here: http://library.gnome.org/devel/glib/stable/glib-The-Main-Event-Loop.html -- Hans Petter _______________________________________________ gnome-vfs-list mailing list gnome-vfs-list@... http://mail.gnome.org/mailman/listinfo/gnome-vfs-list |
|
|
Re: Monitoring directory changes with gnomevfsYou should use gvfs instead gnomevfs is deprecated
2008/8/28 Damien Moore <damien.moore@...> Hi List, _______________________________________________ gnome-vfs-list mailing list gnome-vfs-list@... http://mail.gnome.org/mailman/listinfo/gnome-vfs-list |
| Free embeddable forum powered by Nabble | Forum Help |