Monitoring directory changes with gnomevfs
"Damien Moore" <[email protected]> Thu, 28 Aug 2008 10:01:41 -0400
| Newsgroups | gmane.comp.gnome.vfs.general |
|---|---|
| Message-ID | <[email protected]> |
--===============1010152738==
Content-Type: multipart/alternative; boundary="590610904-1219932101=:5385"
--590610904-1219932101=:5385
Content-transfer-encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
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=3D0;
static void MonitorCallback(GnomeVFSMonitorHandle *handle, const gchar
*monitor_uri, const gchar *info_uri, GnomeVFSMonitorEventType
event_type, gpointer user_data)
{
=C2=A0=C2=A0=C2=A0 exit=3D1;
}
int main()
{
=C2=A0=C2=A0=C2=A0 if(!gnome_vfs_initialized())
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 gnome_vfs_init();
=C2=A0=C2=A0=C2=A0 GnomeVFSMonitorHandle *h;
=C2=A0=C2=A0=C2=A0 gnome_vfs_monitor_add(&h, "/home/myusername", GNOME_VFS_M=
ONITOR_DIRECTORY, MonitorCallback, NULL);
=C2=A0=C2=A0=C2=A0 while(!exit);
=C2=A0=C2=A0=C2=A0 gnome_vfs_monitor_cancel(h);
=C2=A0=C2=A0=C2=A0 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)
{
=C2=A0=C2=A0=C2=A0 g_print("Monitor event received, exiting...\n");
=C2=A0=C2=A0=C2=A0 g_main_loop_quit((GMainLoop*)user_data);
}
int main()
{
=C2=A0=C2=A0=C2=A0 if(!gnome_vfs_initialized())
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 gnome_vfs_init();
=C2=A0=C2=A0=C2=A0 GMainLoop *loop;
=C2=A0=C2=A0=C2=A0 loop =3D g_main_loop_new(NULL, FALSE);
=C2=A0=C2=A0=C2=A0 GnomeVFSMonitorHandle *h;
=C2=A0=C2=A0=C2=A0 gnome_vfs_monitor_add(&h, "/home/myusername", GNOME_VFS_M=
ONITOR_DIRECTORY, MonitorCallback, loop);
=C2=A0=C2=A0=C2=A0 g_main_loop_run(loop);
=C2=A0=C2=A0=C2=A0 gnome_vfs_monitor_cancel(h);
=C2=A0=C2=A0=C2=A0 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 loo=
p, would it also generate callbacks?).
thanks,
D
--590610904-1219932101=:5385
Content-transfer-encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<font style=3D'{font-family: Arial,Verdana, Sans-Serif;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
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...)<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=3D0;<br>
<br>
static void MonitorCallback(GnomeVFSMonitorHandle *handle, const gchar
*monitor_uri, const gchar *info_uri, GnomeVFSMonitorEventType
event_type, gpointer user_data)<br>
{<br>
exit=3D1;<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_V=
FS_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 =3D g_main_loop_new(NULL, FALSE);<br>
GnomeVFSMonitorHandle *h;<br>
gnome_vfs_monitor_add(&h, "/home/myusername", GNOME_V=
FS_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 loo=
p, would it also generate callbacks?).<br>
<br>
thanks,<br>
D
</font>
--590610904-1219932101=:5385--
--===============1010152738==
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
--===============1010152738==--