1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* test-channel.c - Test for the `open_as_channel' functionality of the GNOME
5 Copyright (C) 1999 Free Software Foundation
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.
22 Author: Ettore Perazzoli <ettore@comm2000.it> */
26 #include <glib/gconvert.h> /* workaround for bug in giochannel.h */
27 #include <glib/giochannel.h>
28 #include <glib/gmain.h>
29 #include <glib/gmessages.h>
30 #include <libgnomevfs/gnome-vfs-async-ops.h>
31 #include <libgnomevfs/gnome-vfs-init.h>
34 #define BUFFER_SIZE 4096
36 static GMainLoop *main_loop;
39 io_channel_callback (GIOChannel *source,
40 GIOCondition condition,
43 gchar buffer[BUFFER_SIZE + 1];
46 printf ("\n\n************ IO Channel callback!\n");
48 if (condition & G_IO_IN) {
49 g_io_channel_read_chars (source, buffer, sizeof (buffer) - 1, &bytes_read, NULL);
50 buffer[bytes_read] = 0;
51 printf ("---> Read %lu byte(s):\n%s\n\n(***END***)\n",
52 (gulong)bytes_read, buffer);
56 if (condition & G_IO_NVAL) {
57 g_warning ("channel_callback got NVAL condition.");
61 if (condition & G_IO_HUP) {
62 printf ("\n----- EOF -----\n");
64 g_io_channel_shutdown (source, FALSE, NULL);
65 g_main_loop_quit (main_loop);
72 static void open_callback (GnomeVFSAsyncHandle *handle,
74 GnomeVFSResult result,
77 if (result != GNOME_VFS_OK) {
78 printf ("Error opening: %s.\n",
79 gnome_vfs_result_to_string (result));
83 printf ("Open successful, callback data `%s'.\n", (gchar *) data);
84 g_io_add_watch_full (channel,
86 G_IO_IN | G_IO_NVAL | G_IO_HUP,
87 io_channel_callback, handle,
90 g_io_channel_unref (channel);
95 main (int argc, char **argv)
97 GnomeVFSAsyncHandle *handle;
100 fprintf (stderr, "Usage: %s <uri>\n", argv[0]);
104 puts ("Initializing gnome-vfs...");
107 printf ("Starting open for `%s'...\n", argv[1]);
108 gnome_vfs_async_open_as_channel (&handle, argv[1],
115 puts ("GTK+ main loop running.");
116 main_loop = g_main_loop_new (NULL, TRUE);
117 g_main_loop_run (main_loop);
118 g_main_loop_unref (main_loop);
120 puts ("GTK+ main loop finished.");