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;
65 GIOStatus erriostatus;
67 captive_new0(newservant); /* FIXME: leak */
68 newservant->servant.vepv=&impl_Captive_CaptiveIOChannel_vepv;
71 newservant->image_iochannel=image_iochannel;
72 erriostatus=g_io_channel_set_encoding(newservant->image_iochannel,
73 NULL, /* encoding; force binary data */
75 g_assert(erriostatus==G_IO_STATUS_NORMAL);
77 /* captive_giochannel_size() only _after_ g_io_channel_set_encoding() ! */
78 newservant->image_size=captive_giochannel_size(newservant->image_iochannel);
79 g_return_val_if_fail(newservant->image_size>0,NULL);
81 POA_Captive_CaptiveIOChannel__init((PortableServer_Servant)newservant,ev);
82 objid=PortableServer_POA_activate_object(poa,newservant,ev);
84 retval=PortableServer_POA_servant_to_reference(poa,newservant,ev);
90 static void impl_Captive_CaptiveIOChannel_fini(impl_POA_Captive_CaptiveIOChannel *servant,CORBA_Environment *ev)
92 /* FIXME: Any flushes? */
96 void impl_Captive_CaptiveIOChannel__destroy(impl_POA_Captive_CaptiveIOChannel *servant,CORBA_Environment *ev)
98 PortableServer_ObjectId *objid;
100 objid=PortableServer_POA_servant_to_id(servant->poa,servant,ev);
101 PortableServer_POA_deactivate_object(servant->poa,objid,ev);
103 impl_Captive_CaptiveIOChannel_fini(servant,ev);
108 static void impl_Captive_CaptiveIOChannel_read(impl_POA_Captive_CaptiveIOChannel *servant,
109 Captive_Bytes **buffer_corba_return,const Captive_GSize count,CORBA_Environment *ev)
111 Captive_Bytes *buffer_corba;
113 GIOStatus erriostatus;
115 buffer_corba=Captive_Bytes__alloc();
116 buffer_corba->_maximum=count;
117 buffer_corba->_length=0;
118 buffer_corba->_buffer=Captive_Bytes_allocbuf(buffer_corba->_maximum);
119 buffer_corba->_release=TRUE;
121 erriostatus=g_io_channel_read_chars(servant->image_iochannel,
122 buffer_corba->_buffer, /* buf */
124 &bytes_read, /* bytes_read */
126 if (erriostatus==G_IO_STATUS_EOF) {
127 g_assert(bytes_read==0);
129 erriostatus=G_IO_STATUS_NORMAL;
131 if (erriostatus!=G_IO_STATUS_NORMAL) {
132 captive_sandbox_child_GnomeVFSResultException_throw(ev,GNOME_VFS_ERROR_IO);
133 Captive_Bytes__freekids(buffer_corba,NULL/* 'd'; meaning? */);
134 CORBA_free(buffer_corba);
138 buffer_corba->_length=bytes_read;
139 *buffer_corba_return=buffer_corba;
143 static void impl_Captive_CaptiveIOChannel_write(impl_POA_Captive_CaptiveIOChannel *servant,
144 const Captive_Bytes *buffer_corba,Captive_GSize *bytes_written_return,CORBA_Environment *ev)
148 if (G_IO_STATUS_NORMAL!=g_io_channel_write_chars(servant->image_iochannel,
149 buffer_corba->_buffer, /* buf */
150 buffer_corba->_length, /* count */
151 &bytes_written, /* bytes_written */
153 || bytes_written!=buffer_corba->_length) {
154 captive_sandbox_child_GnomeVFSResultException_throw(ev,GNOME_VFS_ERROR_IO);
158 *bytes_written_return=bytes_written;
162 static void impl_Captive_CaptiveIOChannel_seek
163 (impl_POA_Captive_CaptiveIOChannel *servant,const Captive_GInt64 offset,const Captive_GSeekType type,CORBA_Environment *ev)
165 if (G_IO_STATUS_NORMAL!=g_io_channel_seek_position(servant->image_iochannel,
169 captive_sandbox_child_GnomeVFSResultException_throw(ev,GNOME_VFS_ERROR_IO);
175 static Captive_GUInt64 impl_Captive_CaptiveIOChannel_size(impl_POA_Captive_CaptiveIOChannel *servant,CORBA_Environment *ev)
177 return servant->image_size;