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 |
---|
3 | Virtual File System. |
---|
4 | |
---|
5 | Copyright (C) 1999 Free Software Foundation |
---|
6 | |
---|
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. |
---|
11 | |
---|
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. |
---|
16 | |
---|
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. |
---|
21 | |
---|
22 | Author: Ettore Perazzoli <ettore@comm2000.it> */ |
---|
23 | |
---|
24 | |
---|
25 | #ifdef HAVE_CONFIG_H |
---|
26 | #include <config.h> |
---|
27 | #endif |
---|
28 | |
---|
29 | #include <gnome.h> |
---|
30 | #include <libgnorba/gnorba.h> |
---|
31 | |
---|
32 | #include "gnome-vfs.h" |
---|
33 | |
---|
34 | #ifdef WITH_CORBA |
---|
35 | CORBA_Environment ev; |
---|
36 | #endif |
---|
37 | |
---|
38 | #define BUFFER_SIZE 4096 |
---|
39 | |
---|
40 | |
---|
41 | static gboolean io_channel_callback (GIOChannel *source, |
---|
42 | GIOCondition condition, |
---|
43 | gpointer data) |
---|
44 | { |
---|
45 | gchar buffer[BUFFER_SIZE + 1]; |
---|
46 | guint bytes_read; |
---|
47 | |
---|
48 | printf ("\n\n************ IO Channel callback!\n"); |
---|
49 | |
---|
50 | if (condition & G_IO_IN) { |
---|
51 | g_io_channel_read (source, buffer, sizeof (buffer) - 1, &bytes_read); |
---|
52 | buffer[bytes_read] = 0; |
---|
53 | printf ("---> Read %d byte(s):\n%s\n\n(***END***)\n", |
---|
54 | bytes_read, buffer); |
---|
55 | fflush (stdout); |
---|
56 | } |
---|
57 | |
---|
58 | if (condition & G_IO_NVAL) { |
---|
59 | g_warning ("channel_callback got NVAL condition."); |
---|
60 | return FALSE; |
---|
61 | } |
---|
62 | |
---|
63 | if (condition & G_IO_HUP) { |
---|
64 | printf ("\n----- EOF -----\n"); |
---|
65 | fflush (stdout); |
---|
66 | g_io_channel_close (source); |
---|
67 | gtk_main_quit (); |
---|
68 | return FALSE; |
---|
69 | } |
---|
70 | |
---|
71 | return TRUE; |
---|
72 | } |
---|
73 | |
---|
74 | static void open_callback (GnomeVFSAsyncHandle *handle, |
---|
75 | GIOChannel *channel, |
---|
76 | GnomeVFSResult result, |
---|
77 | gpointer data) |
---|
78 | { |
---|
79 | if (result != GNOME_VFS_OK) { |
---|
80 | printf ("Error opening: %s.\n", |
---|
81 | gnome_vfs_result_to_string (result)); |
---|
82 | return; |
---|
83 | } |
---|
84 | |
---|
85 | printf ("Open successful, callback data `%s'.\n", (gchar *) data); |
---|
86 | g_io_add_watch_full (channel, |
---|
87 | G_PRIORITY_HIGH, |
---|
88 | G_IO_IN | G_IO_NVAL | G_IO_HUP, |
---|
89 | io_channel_callback, handle, |
---|
90 | NULL); |
---|
91 | |
---|
92 | g_io_channel_unref (channel); |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | int |
---|
97 | main (int argc, char **argv) |
---|
98 | { |
---|
99 | GnomeVFSAsyncHandle *handle; |
---|
100 | |
---|
101 | if (argc < 2) { |
---|
102 | fprintf (stderr, "Usage: %s <uri>\n", argv[0]); |
---|
103 | return 1; |
---|
104 | } |
---|
105 | |
---|
106 | #ifdef WITH_PTHREAD |
---|
107 | puts ("Initializing threads..."); |
---|
108 | g_thread_init (NULL); |
---|
109 | #endif |
---|
110 | |
---|
111 | #ifdef WITH_CORBA |
---|
112 | CORBA_exception_init (&ev); |
---|
113 | puts ("Initializing gnome-libs with CORBA..."); |
---|
114 | gnome_CORBA_init ("test-vfs", "0.0", &argc, argv, 0, &ev); |
---|
115 | #else |
---|
116 | puts ("Initializing gnome-libs..."); |
---|
117 | gnome_init ("test-vfs", "0.0", argc, argv); |
---|
118 | #endif |
---|
119 | |
---|
120 | puts ("Initializing gnome-vfs..."); |
---|
121 | gnome_vfs_init (); |
---|
122 | |
---|
123 | printf ("Starting open for `%s'...\n", argv[1]); |
---|
124 | gnome_vfs_async_open_as_channel (&handle, argv[1], |
---|
125 | GNOME_VFS_OPEN_READ, |
---|
126 | BUFFER_SIZE, |
---|
127 | open_callback, |
---|
128 | "open_callback"); |
---|
129 | |
---|
130 | puts ("GTK+ main loop running."); |
---|
131 | gtk_main (); |
---|
132 | |
---|
133 | puts ("GTK+ main loop finished."); |
---|
134 | |
---|
135 | #ifdef WITH_CORBA |
---|
136 | CORBA_exception_free (&ev); |
---|
137 | #endif |
---|
138 | |
---|
139 | puts ("All done"); |
---|
140 | |
---|
141 | while (1) |
---|
142 | ; |
---|
143 | |
---|
144 | return 0; |
---|
145 | } |
---|