source: trunk/third/gnome-vfs/test/test-async.c @ 15595

Revision 15595, 3.5 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r15594, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2/* test-vfs.c - Test program for the GNOME Virtual File System.
3
4   Copyright (C) 1999 Free Software Foundation
5
6   The Gnome Library is free software; you can redistribute it and/or
7   modify it under the terms of the GNU Library General Public License as
8   published by the Free Software Foundation; either version 2 of the
9   License, or (at your option) any later version.
10
11   The Gnome Library is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   Library General Public License for more details.
15
16   You should have received a copy of the GNU Library General Public
17   License along with the Gnome Library; see the file COPYING.LIB.  If not,
18   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   Boston, MA 02111-1307, USA.
20
21   Author: Ettore Perazzoli <ettore@comm2000.it>
22*/
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
35CORBA_Environment ev;
36#endif
37
38/* Callbacks.  */
39static void
40close_callback (GnomeVFSAsyncHandle *handle,
41                GnomeVFSResult result,
42                gpointer callback_data)
43{
44        printf ("Close: %s.\n", gnome_vfs_result_to_string (result));
45        gtk_main_quit ();
46}
47
48static void
49read_callback (GnomeVFSAsyncHandle *handle,
50               GnomeVFSResult result,
51               gpointer buffer,
52               GnomeVFSFileSize bytes_requested,
53               GnomeVFSFileSize bytes_read,
54               gpointer callback_data)
55{
56        if (result != GNOME_VFS_OK) {
57                printf ("Read failed: %s", gnome_vfs_result_to_string (result));
58        } else {
59                printf ("%"GNOME_VFS_SIZE_FORMAT_STR"/"
60                        "%"GNOME_VFS_SIZE_FORMAT_STR" "
61                        "byte(s) read, callback data `%s'\n",
62                        bytes_read, bytes_requested, (gchar *) callback_data);
63                *((gchar *) buffer + bytes_read) = 0;
64                puts (buffer);
65        }
66
67        printf ("Now closing the file.\n");
68        gnome_vfs_async_close (handle, close_callback, "close");
69        gtk_main_quit ();
70}
71
72static void
73open_callback  (GnomeVFSAsyncHandle *handle,
74                GnomeVFSResult result,
75                gpointer callback_data)
76{
77        if (result != GNOME_VFS_OK) {
78                printf ("Open failed: %s.\n",
79                        gnome_vfs_result_to_string (result));
80                gtk_main_quit ();
81        } else {
82                gchar *buffer;
83                const gulong buffer_size = 1024;
84
85                printf ("File opened correctly, data `%s'.\n",
86                        (gchar *) callback_data);
87
88                buffer = g_malloc (buffer_size);
89                gnome_vfs_async_read (handle,
90                                      buffer,
91                                      buffer_size - 1,
92                                      read_callback,
93                                      "read_callback");
94        }
95}
96
97
98int
99main (int argc, char **argv)
100{
101        GnomeVFSAsyncHandle *handle;
102
103        if (argc < 2) {
104                fprintf (stderr, "Usage: %s <uri>\n", argv[0]);
105                return 1;
106        }
107
108#ifdef WITH_PTHREAD
109        puts ("Initializing threads...");
110        g_thread_init (NULL);
111#endif
112
113#ifdef WITH_CORBA
114        CORBA_exception_init (&ev);
115        puts ("Initializing gnome-libs with CORBA...");
116        gnome_CORBA_init ("test-vfs", "0.0", &argc, argv, 0, &ev);
117#else
118        puts ("Initializing gnome-libs...");
119        gnome_init ("test-vfs", "0.0", argc, argv);
120#endif
121
122        puts ("Initializing gnome-vfs...");
123        gnome_vfs_init ();
124
125        puts ("Creating async context...");
126
127        printf ("Starting open for `%s'...\n", argv[1]);
128        gnome_vfs_async_open (&handle, argv[1], GNOME_VFS_OPEN_READ,
129                              open_callback, "open_callback");
130
131        puts ("GTK+ main loop running.");
132        gtk_main ();
133
134        puts ("GTK+ main loop finished.");
135
136#ifdef WITH_CORBA
137        CORBA_exception_free (&ev);
138#endif
139
140        puts ("All done");
141
142        while (1)
143                ;
144
145        return 0;
146}
Note: See TracBrowser for help on using the repository browser.