2 * CORBA/ORBit client side of image GIOChannel object of sandbox_child()
3 * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "server-CaptiveIOChannel.h" /* self */
24 #include <glib/gmessages.h>
25 #include "captive/macros.h"
27 #include <libgnomevfs/gnome-vfs-file-size.h>
28 #include "captive/storage.h"
31 static void impl_Captive_CaptiveIOChannel_fini(impl_POA_Captive_CaptiveIOChannel *servant,CORBA_Environment *ev);
32 static void impl_Captive_CaptiveIOChannel_read(impl_POA_Captive_CaptiveIOChannel *servant,
33 Captive_Bytes **buffer_corba_return,const Captive_GSize count,CORBA_Environment *ev);
34 static void impl_Captive_CaptiveIOChannel_write(impl_POA_Captive_CaptiveIOChannel *servant,
35 const Captive_Bytes *buffer,Captive_GSize *bytes_written_return,CORBA_Environment *ev);
36 static void impl_Captive_CaptiveIOChannel_seek
37 (impl_POA_Captive_CaptiveIOChannel *servant,const Captive_GInt64 offset,const Captive_GSeekType type,CORBA_Environment *ev);
38 static Captive_GUInt64 impl_Captive_CaptiveIOChannel_size(impl_POA_Captive_CaptiveIOChannel *servant,CORBA_Environment *ev);
41 static PortableServer_ServantBase__epv impl_Captive_CaptiveIOChannel_base_epv={
42 NULL, /* _private data */
43 (gpointer)&impl_Captive_CaptiveIOChannel_fini, /* finalize routine */
44 NULL, /* default_POA routine */
46 static POA_Captive_CaptiveIOChannel__epv impl_Captive_CaptiveIOChannel_epv={
48 (gpointer)&impl_Captive_CaptiveIOChannel_read,
49 (gpointer)&impl_Captive_CaptiveIOChannel_write,
50 (gpointer)&impl_Captive_CaptiveIOChannel_seek,
51 (gpointer)&impl_Captive_CaptiveIOChannel_size,
53 static POA_Captive_CaptiveIOChannel__vepv impl_Captive_CaptiveIOChannel_vepv={
54 &impl_Captive_CaptiveIOChannel_base_epv,
55 &impl_Captive_CaptiveIOChannel_epv,
59 Captive_CaptiveIOChannel impl_Captive_CaptiveIOChannel__create
60 (PortableServer_POA poa,GIOChannel *image_iochannel,CORBA_Environment *ev)
62 Captive_CaptiveIOChannel retval;
63 impl_POA_Captive_CaptiveIOChannel *newservant;
64 PortableServer_ObjectId *objid;
66 captive_new0(newservant); /* FIXME: leak */
67 newservant->servant.vepv=&impl_Captive_CaptiveIOChannel_vepv;
70 newservant->image_iochannel=image_iochannel;
72 /* captive_giochannel_size() only _after_ g_io_channel_set_encoding() ! */
73 newservant->image_size=captive_giochannel_size(newservant->image_iochannel);
74 g_return_val_if_fail(newservant->image_size>0,NULL);
76 POA_Captive_CaptiveIOChannel__init((PortableServer_Servant)newservant,ev);
77 objid=PortableServer_POA_activate_object(poa,newservant,ev);
79 retval=PortableServer_POA_servant_to_reference(poa,newservant,ev);
85 static void impl_Captive_CaptiveIOChannel_fini(impl_POA_Captive_CaptiveIOChannel *servant,CORBA_Environment *ev)
87 /* FIXME: Any flushes? */
91 void impl_Captive_CaptiveIOChannel__destroy(impl_POA_Captive_CaptiveIOChannel *servant,CORBA_Environment *ev)
93 PortableServer_ObjectId *objid;
95 objid=PortableServer_POA_servant_to_id(servant->poa,servant,ev);
96 PortableServer_POA_deactivate_object(servant->poa,objid,ev);
98 impl_Captive_CaptiveIOChannel_fini(servant,ev);
103 static void impl_Captive_CaptiveIOChannel_read(impl_POA_Captive_CaptiveIOChannel *servant,
104 Captive_Bytes **buffer_corba_return,const Captive_GSize count,CORBA_Environment *ev)
106 Captive_Bytes *buffer_corba;
108 GIOStatus erriostatus;
110 buffer_corba=Captive_Bytes__alloc();
111 buffer_corba->_maximum=count;
112 buffer_corba->_length=0;
113 buffer_corba->_buffer=Captive_Bytes_allocbuf(buffer_corba->_maximum);
114 buffer_corba->_release=TRUE;
116 erriostatus=g_io_channel_read_chars(servant->image_iochannel,
117 (gchar *)buffer_corba->_buffer, /* buf */
119 &bytes_read, /* bytes_read */
121 if (erriostatus==G_IO_STATUS_EOF) {
122 g_assert(bytes_read==0);
124 erriostatus=G_IO_STATUS_NORMAL;
126 if (erriostatus!=G_IO_STATUS_NORMAL) {
127 captive_sandbox_child_GnomeVFSResultException_throw(ev,GNOME_VFS_ERROR_IO);
128 Captive_Bytes__freekids(buffer_corba,NULL/* 'd'; meaning? */);
129 CORBA_free(buffer_corba);
133 buffer_corba->_length=bytes_read;
134 *buffer_corba_return=buffer_corba;
138 static void impl_Captive_CaptiveIOChannel_write(impl_POA_Captive_CaptiveIOChannel *servant,
139 const Captive_Bytes *buffer_corba,Captive_GSize *bytes_written_return,CORBA_Environment *ev)
143 if (G_IO_STATUS_NORMAL!=g_io_channel_write_chars(servant->image_iochannel,
144 (const gchar *)buffer_corba->_buffer, /* buf */
145 buffer_corba->_length, /* count */
146 &bytes_written, /* bytes_written */
148 || bytes_written!=buffer_corba->_length) {
149 captive_sandbox_child_GnomeVFSResultException_throw(ev,GNOME_VFS_ERROR_IO);
153 *bytes_written_return=bytes_written;
157 static void impl_Captive_CaptiveIOChannel_seek
158 (impl_POA_Captive_CaptiveIOChannel *servant,const Captive_GInt64 offset,const Captive_GSeekType type,CORBA_Environment *ev)
160 if (G_IO_STATUS_NORMAL!=g_io_channel_seek_position(servant->image_iochannel,
164 captive_sandbox_child_GnomeVFSResultException_throw(ev,GNOME_VFS_ERROR_IO);
170 static Captive_GUInt64 impl_Captive_CaptiveIOChannel_size(impl_POA_Captive_CaptiveIOChannel *servant,CORBA_Environment *ev)
172 return servant->image_size;