Re: Monitoring directory changes with gnomevfs
"Mikael Hermansson" <[email protected]> Fri, 5 Sep 2008 21:07:04 +0200
| Newsgroups | gmane.comp.gnome.vfs.general |
|---|---|
| Message-ID | <[email protected]> |
--===============1790844335== Content-Type: multipart/alternative; boundary="----=_Part_58650_12874282.1220641624406" ------=_Part_58650_12874282.1220641624406 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline You should use gvfs instead gnomevfs is deprecated 2008/8/28 Damien Moore <[email protected]> > 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.htmldoesn'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 > [email protected] > http://mail.gnome.org/mailman/listinfo/gnome-vfs-list > > ------=_Part_58650_12874282.1220641624406 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline <div dir="ltr">You should use gvfs instead gnomevfs is deprecated<br><br><div class="gmail_quote">2008/8/28 Damien Moore <span dir="ltr"><<a href="mailto:[email protected]">[email protected]</a>></span><br> <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><font style="font-size: 10pt;"> Hi List, <br> <br> 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 <a href="http://library.gnome.org/devel/gnome-vfs-2.0/unstable/gnome-vfs-20-gnome-vfs-monitor.html" target="_blank">http://library.gnome.org/devel/gnome-vfs-2.0/unstable/gnome-vfs-20-gnome-vfs-monitor.html</a> 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...)<br> <br> For example, I gather this program won't work because there is no GMainLoop in place to generate the callback:<br> <br> #include <libgnomevfs/gnome-vfs.h><br> <br> int exit=0;<br> <br> static void MonitorCallback(GnomeVFSMonitorHandle *handle, const gchar *monitor_uri, const gchar *info_uri, GnomeVFSMonitorEventType event_type, gpointer user_data)<br> {<br> exit=1;<br> }<br> <br> int main()<br> {<br> if(!gnome_vfs_initialized())<br> gnome_vfs_init();<br> GnomeVFSMonitorHandle *h;<br> gnome_vfs_monitor_add(&h, "/home/myusername", GNOME_VFS_MONITOR_DIRECTORY, MonitorCallback, NULL);<br> while(!exit);<br> gnome_vfs_monitor_cancel(h);<br> return 0;<br> }<br> <br> but something like this should work correctly?<br> <br> #include <glib.h><br> #include <libgnomevfs/gnome-vfs.h><br> <br> static void MonitorCallback(GnomeVFSMonitorHandle *handle, const gchar *monitor_uri, const gchar *info_uri, GnomeVFSMonitorEventType event_type, gpointer user_data)<br> {<br> g_print("Monitor event received, exiting...\n");<br> g_main_loop_quit((GMainLoop*)user_data);<br> }<br> <br> int main()<br> {<br> if(!gnome_vfs_initialized())<br> gnome_vfs_init();<br> GMainLoop *loop;<br> loop = g_main_loop_new(NULL, FALSE);<br> GnomeVFSMonitorHandle *h;<br> gnome_vfs_monitor_add(&h, "/home/myusername", GNOME_VFS_MONITOR_DIRECTORY, MonitorCallback, loop);<br> g_main_loop_run(loop);<br> gnome_vfs_monitor_cancel(h);<br> return 0;<br> }<br> <br> 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?).<br> <br> thanks,<br> D </font> <br>_______________________________________________<br> gnome-vfs-list mailing list<br> <a href="mailto:[email protected]">[email protected]</a><br> <a href="http://mail.gnome.org/mailman/listinfo/gnome-vfs-list" target="_blank">http://mail.gnome.org/mailman/listinfo/gnome-vfs-list</a><br> <br></blockquote></div><br></div> ------=_Part_58650_12874282.1220641624406-- --===============1790844335== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ gnome-vfs-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/gnome-vfs-list --===============1790844335==--