1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* test-monitor.c - Test program for file monitoringu in the GNOME Virtual
5 Copyright (C) 2001 Ian McKellar
7 The Gnome Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 The Gnome Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the Gnome Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
23 Ian McKellar <yakk@yakk.net>
26 #include <libgnomevfs/gnome-vfs.h>
33 static GMainLoop *main_loop;
36 timeout_cb (gpointer data)
42 unlink ("/tmp/test-monitor");
43 g_spawn_command_line_sync ("touch /tmp/test-monitor",
44 NULL, NULL, NULL, NULL);
49 unlink ("/tmp/test-monitor");
58 show_result (GnomeVFSResult result, const gchar *what, const gchar *text_uri)
60 fprintf (stderr, "%s `%s': %s\n",
61 what, text_uri, gnome_vfs_result_to_string (result));
62 if (result != GNOME_VFS_OK)
67 callback (GnomeVFSMonitorHandle *handle,
68 const gchar *monitor_uri,
69 const gchar *info_uri,
70 GnomeVFSMonitorEventType event_type,
74 g_print ("Got a callback: ");
76 case GNOME_VFS_MONITOR_EVENT_CHANGED:
77 g_print ("GNOME_VFS_MONITOR_EVENT_CHANGED");
79 case GNOME_VFS_MONITOR_EVENT_DELETED:
80 g_print ("GNOME_VFS_MONITOR_EVENT_DELETED");
82 case GNOME_VFS_MONITOR_EVENT_STARTEXECUTING:
83 g_print ("GNOME_VFS_MONITOR_EVENT_STARTEXECUTING");
85 case GNOME_VFS_MONITOR_EVENT_STOPEXECUTING:
86 g_print ("GNOME_VFS_MONITOR_EVENT_STOPEXECUTING");
88 case GNOME_VFS_MONITOR_EVENT_CREATED:
89 g_print ("GNOME_VFS_MONITOR_EVENT_CREATED");
91 case GNOME_VFS_MONITOR_EVENT_METADATA_CHANGED:
92 g_print ("GNOME_VFS_MONITOR_EVENT_METADATA_CHANGED");
95 g_print ("Unknown monitor type, exiting...");
99 g_print (" (%s)", info_uri);
107 main (int argc, char **argv)
109 GnomeVFSResult result;
110 gchar *text_uri = "/tmp/";
111 GnomeVFSMonitorHandle *handle;
113 if (! gnome_vfs_init ()) {
114 fprintf (stderr, "Cannot initialize gnome-vfs.\n");
122 result = gnome_vfs_monitor_add (&handle, text_uri,
123 GNOME_VFS_MONITOR_DIRECTORY, callback, "user data");
124 printf ("handle is %p\n", handle);
125 show_result (result, "monitor_add", text_uri);
127 g_timeout_add (1000, timeout_cb, NULL);
129 if (result == GNOME_VFS_OK) {
130 main_loop = g_main_loop_new (NULL, TRUE);
131 g_main_loop_run (main_loop);
132 g_main_loop_unref (main_loop);