1 /*
2 * Copyright (C) 2003 by the gtk2-perl team (see the file AUTHORS for the full
3 * list)
4 *
5 * This library is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Library General Public License as published by
7 * the Free Software Foundation; either version 2.1 of the License, or (at your
8 * option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 * License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * $Id$
20 */
21
22 #include "gperl.h"
23
24 /*
25 GIOChannel is GLib's way to creating a portable and unified for IO
26 over files, sockets, pipes, and whatever else acts like an FD
27 on unix.
28
29 but perl's filehandles already do this.
30
31 so we'll just replace the GLib concept of GIOChannel with perl
32 file handles or at least filenos.
33
34 thus, pretty much nothing from this header is bound to perl,
35 except for a one-way boxed wrapper to convert GIOChannels into
36 file descriptors for gperl_closure_marshal.
37 */
38
39 static SV*
gperl_io_channel_wrap(GType gtype,const char * package,GIOChannel * channel,gboolean own)40 gperl_io_channel_wrap (GType gtype,
41 const char * package,
42 GIOChannel * channel,
43 gboolean own)
44 {
45 PERL_UNUSED_VAR (gtype);
46 PERL_UNUSED_VAR (package);
47 PERL_UNUSED_VAR (own);
48 return newSViv (g_io_channel_unix_get_fd (channel));
49 }
50 static gpointer
gperl_io_channel_unwrap(GType gtype,const char * package,SV * sv)51 gperl_io_channel_unwrap (GType gtype,
52 const char * package,
53 SV * sv)
54 {
55 PERL_UNUSED_VAR (gtype);
56 PERL_UNUSED_VAR (package);
57 PERL_UNUSED_VAR (sv);
58 croak ("can't unwrap GIOChannels -- how'd you get one in perl?!?\n"
59 " you appear to have found a bug in gtk2-perl-xs. congratulations.\n"
60 " please report this bug to gtk-perl-list@gnome.org\n"
61 " croaking ");
62 return NULL;
63 }
64
65 static GPerlBoxedWrapperClass io_channel_wrapper_class = {
66 (GPerlBoxedWrapFunc) gperl_io_channel_wrap,
67 gperl_io_channel_unwrap,
68 NULL
69 };
70
71 MODULE = Glib::IO::Channel PACKAGE = Glib::IO::Channel PREFIX = g_io_channel_
72
73 BOOT:
74 gperl_register_boxed (G_TYPE_IO_CHANNEL, "Glib::IO::Channel",
75 &io_channel_wrapper_class);
76
77 ##void g_io_channel_init (GIOChannel *channel);
78 ##void g_io_channel_ref (GIOChannel *channel);
79 ##void g_io_channel_unref (GIOChannel *channel);
80 ##
81 ###ifndef G_DISABLE_DEPRECATED
82 ##GIOError g_io_channel_read (GIOChannel *channel, gchar *buf, gsize count, gsize *bytes_read);
83 ##GIOError g_io_channel_write (GIOChannel *channel, const gchar *buf, gsize count, gsize *bytes_written);
84 ##GIOError g_io_channel_seek (GIOChannel *channel, gint64 offset, GSeekType type);
85 ##void g_io_channel_close (GIOChannel *channel);
86 ###endif /* G_DISABLE_DEPRECATED */
87 ##
88 ##GIOStatus g_io_channel_shutdown (GIOChannel *channel,
89 ## gboolean flush,
90 ## GError **err);
91
92 ####
93 #### g_io_add_watch is bound in GMainLoop.xs as Glib::IO->add_watch
94 ####
95 ##guint g_io_add_watch_full (GIOChannel *channel,
96 ## gint priority,
97 ## GIOCondition condition,
98 ## GIOFunc func,
99 ## gpointer user_data,
100 ## GDestroyNotify notify);
101 ##GSource * g_io_create_watch (GIOChannel *channel,
102 ## GIOCondition condition);
103 ##guint g_io_add_watch (GIOChannel *channel,
104 ## GIOCondition condition,
105 ## GIOFunc func,
106 ## gpointer user_data);
107
108
109 ##/* character encoding conversion involved functions.
110 ## */
111 ##
112 ##void g_io_channel_set_buffer_size (GIOChannel *channel,
113 ## gsize size);
114 ##gsize g_io_channel_get_buffer_size (GIOChannel *channel);
115 ##GIOCondition g_io_channel_get_buffer_condition (GIOChannel *channel);
116 ##GIOStatus g_io_channel_set_flags (GIOChannel *channel,
117 ## GIOFlags flags,
118 ## GError **error);
119 ##GIOFlags g_io_channel_get_flags (GIOChannel *channel);
120 ##void g_io_channel_set_line_term (GIOChannel *channel,
121 ## const gchar *line_term,
122 ## gint length);
123 ##G_CONST_RETURN gchar* g_io_channel_get_line_term (GIOChannel *channel,
124 ## gint *length);
125 ##void g_io_channel_set_buffered (GIOChannel *channel,
126 ## gboolean buffered);
127 ##gboolean g_io_channel_get_buffered (GIOChannel *channel);
128 ##GIOStatus g_io_channel_set_encoding (GIOChannel *channel,
129 ## const gchar *encoding,
130 ## GError **error);
131 ##G_CONST_RETURN gchar* g_io_channel_get_encoding (GIOChannel *channel);
132 ##void g_io_channel_set_close_on_unref (GIOChannel *channel,
133 ## gboolean do_close);
134 ##gboolean g_io_channel_get_close_on_unref (GIOChannel *channel);
135 ##
136 ##
137 ##GIOStatus g_io_channel_flush (GIOChannel *channel,
138 ## GError **error);
139 ##GIOStatus g_io_channel_read_line (GIOChannel *channel,
140 ## gchar **str_return,
141 ## gsize *length,
142 ## gsize *terminator_pos,
143 ## GError **error);
144 ##GIOStatus g_io_channel_read_line_string (GIOChannel *channel,
145 ## GString *buffer,
146 ## gsize *terminator_pos,
147 ## GError **error);
148 ##GIOStatus g_io_channel_read_to_end (GIOChannel *channel,
149 ## gchar **str_return,
150 ## gsize *length,
151 ## GError **error);
152 ##GIOStatus g_io_channel_read_chars (GIOChannel *channel,
153 ## gchar *buf,
154 ## gsize count,
155 ## gsize *bytes_read,
156 ## GError **error);
157 ##GIOStatus g_io_channel_read_unichar (GIOChannel *channel,
158 ## gunichar *thechar,
159 ## GError **error);
160 ##GIOStatus g_io_channel_write_chars (GIOChannel *channel,
161 ## const gchar *buf,
162 ## gssize count,
163 ## gsize *bytes_written,
164 ## GError **error);
165 ##GIOStatus g_io_channel_write_unichar (GIOChannel *channel,
166 ## gunichar thechar,
167 ## GError **error);
168 ##GIOStatus g_io_channel_seek_position (GIOChannel *channel,
169 ## gint64 offset,
170 ## GSeekType type,
171 ## GError **error);
172 ##GIOChannel* g_io_channel_new_file (const gchar *filename,
173 ## const gchar *mode,
174 ## GError **error);
175 ##
176 ##/* Error handling */
177 ##
178 ##GQuark g_io_channel_error_quark (void);
179 ##GIOChannelError g_io_channel_error_from_errno (gint en);
180 ##
181 ##GIOChannel* g_io_channel_unix_new (int fd);
182 ##gint g_io_channel_unix_get_fd (GIOChannel *channel);
183 ##
184 ##/* Hook for GClosure / GSource integration. Don't touch */
185 ##GLIB_VAR GSourceFuncs g_io_watch_funcs;
186 ##
187 ###ifdef G_OS_WIN32
188 ##
189 ##/* You can use this "pseudo file descriptor" in a GPollFD to add
190 ## * polling for Windows messages. GTK applications should not do that.
191 ## */
192 ##
193 ###define G_WIN32_MSG_HANDLE 19981206
194 ##
195 ##/* Use this to get a GPollFD from a GIOChannel, so that you can call
196 ## * g_io_channel_win32_poll(). After calling this you should only use
197 ## * g_io_channel_read() to read from the GIOChannel, i.e. never read()
198 ## * from the underlying file descriptor. For SOCKETs, it is possible to call
199 ## * recv().
200 ## */
201 ##void g_io_channel_win32_make_pollfd (GIOChannel *channel,
202 ## GIOCondition condition,
203 ## GPollFD *fd);
204 ##
205 ##/* This can be used to wait a until at least one of the channels is readable.
206 ## * On Unix you would do a select() on the file descriptors of the channels.
207 ## */
208 ##gint g_io_channel_win32_poll (GPollFD *fds,
209 ## gint n_fds,
210 ## gint timeout_);
211 ##
212 ##/* Create an IO channel for Windows messages for window handle hwnd. */
213 ##GIOChannel *g_io_channel_win32_new_messages (guint hwnd);
214 ##
215 ##GIOChannel* g_io_channel_win32_new_fd (gint fd);
216 ##
217 ##gint g_io_channel_win32_get_fd (GIOChannel *channel);
218 ##
219 ##/* Create an IO channel for a winsock socket. The parameter should be
220 ## * a SOCKET. Contrary to IO channels for file descriptors (on *Win32),
221 ## * you can use normal recv() or recvfrom() on sockets even if GLib
222 ## * is polling them.
223 ## */
224 ##GIOChannel *g_io_channel_win32_new_socket (gint socket);
225 ##
226 ###endif
227 ##
228