2 * CORBA/ORBit server side of File object, ran by 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-File.h" /* self */
24 #include <glib/gmessages.h>
25 #include "captive/macros.h"
30 static void impl_Captive_File_fini(impl_POA_Captive_File *servant,CORBA_Environment *ev);
31 static void impl_Captive_File_read(impl_POA_Captive_File *servant,Captive_Bytes **buffer,
32 const Captive_GnomeVFSFileSize num_bytes,CORBA_Environment *ev);
33 static void impl_Captive_File_write(impl_POA_Captive_File *servant,
34 const Captive_Bytes *buffer,Captive_GnomeVFSFileSize *bytes_written_return,CORBA_Environment *ev);
35 static void impl_Captive_File_seek(impl_POA_Captive_File *servant,
36 const Captive_GnomeVFSSeekPosition whence,const Captive_GnomeVFSFileOffset offset,CORBA_Environment *ev);
37 static void impl_Captive_File_tell
38 (impl_POA_Captive_File *servant,Captive_GnomeVFSFileOffset *offset_return,CORBA_Environment *ev);
39 static void impl_Captive_File_remove(impl_POA_Captive_File *servant,CORBA_Environment *ev);
40 static void impl_Captive_File_file_info_get
41 (impl_POA_Captive_File *servant,Captive_GnomeVFSFileInfo **file_info,CORBA_Environment *ev);
42 static void impl_Captive_File_file_info_set(impl_POA_Captive_File *servant,
43 const Captive_GnomeVFSFileInfo *file_info,const Captive_GnomeVFSSetFileInfoMask mask,CORBA_Environment *ev);
44 static void impl_Captive_File_truncate
45 (impl_POA_Captive_File *servant,const Captive_GnomeVFSFileSize file_size,CORBA_Environment *ev);
46 static void impl_Captive_File_move
47 (impl_POA_Captive_File *servant,const CORBA_char *pathname_new,const CORBA_boolean force_replace,CORBA_Environment *ev);
50 static PortableServer_ServantBase__epv impl_Captive_File_base_epv={
51 NULL, /* _private data */
52 (gpointer)&impl_Captive_File_fini, /* finalize routine */
53 NULL, /* default_POA routine */
55 static POA_Captive_File__epv impl_Captive_File_epv={
57 (gpointer)&impl_Captive_File_read,
58 (gpointer)&impl_Captive_File_write,
59 (gpointer)&impl_Captive_File_seek,
60 (gpointer)&impl_Captive_File_tell,
61 (gpointer)&impl_Captive_File_remove,
62 (gpointer)&impl_Captive_File_file_info_get,
63 (gpointer)&impl_Captive_File_file_info_set,
64 (gpointer)&impl_Captive_File_truncate,
65 (gpointer)&impl_Captive_File_move,
67 static POA_Captive_File__vepv impl_Captive_File_vepv={
68 &impl_Captive_File_base_epv,
69 &impl_Captive_File_epv,
73 Captive_File impl_Captive_File__create(PortableServer_POA poa,CORBA_Environment *ev)
76 impl_POA_Captive_File *newservant;
77 PortableServer_ObjectId *objid;
79 captive_new0(newservant); /* FIXME: leak */
80 newservant->servant.vepv=&impl_Captive_File_vepv;
82 newservant->captive_file_object=NULL;
83 POA_Captive_File__init((PortableServer_Servant)newservant,ev);
84 objid=PortableServer_POA_activate_object(poa,newservant,ev);
86 retval=PortableServer_POA_servant_to_reference(poa,newservant,ev);
92 static void impl_Captive_File_fini(impl_POA_Captive_File *servant,CORBA_Environment *ev)
94 if (servant->captive_file_object) {
95 g_object_unref(servant->captive_file_object);
96 servant->captive_file_object=NULL;
101 static void impl_Captive_File__destroy(impl_POA_Captive_File *servant,CORBA_Environment *ev)
103 PortableServer_ObjectId *objid;
105 objid=PortableServer_POA_servant_to_id(servant->poa,servant,ev);
106 PortableServer_POA_deactivate_object(servant->poa,objid,ev);
108 impl_Captive_File_fini(servant,ev);
113 Captive_File impl_Captive_Vfs_file_new_open
114 (impl_POA_Captive_Vfs *servant,const CORBA_char *pathname,const Captive_GnomeVFSOpenMode mode,CORBA_Environment *ev)
117 impl_POA_Captive_File *retval_servant;
118 GnomeVFSResult errvfsresult;
120 retval=impl_Captive_File__create(servant->poa,ev);
121 if (ev->_major!=CORBA_NO_EXCEPTION)
124 retval_servant=PortableServer_POA_reference_to_servant(servant->poa,retval,ev);
125 if (ev->_major!=CORBA_NO_EXCEPTION)
126 return NULL; /* 'retval' leak */
128 if (GNOME_VFS_OK!=(errvfsresult=captive_file_new_open(&retval_servant->captive_file_object,
129 servant->captive_vfs_object,pathname,mode))) {
130 impl_Captive_File__destroy(retval_servant,ev);
131 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
139 Captive_File impl_Captive_Vfs_file_new_create(impl_POA_Captive_Vfs *servant,const CORBA_char *pathname,
140 const Captive_GnomeVFSOpenMode mode,const CORBA_boolean exclusive,const CORBA_unsigned_long perm,CORBA_Environment *ev)
143 impl_POA_Captive_File *retval_servant;
144 GnomeVFSResult errvfsresult;
146 retval=impl_Captive_File__create(servant->poa,ev);
147 if (ev->_major!=CORBA_NO_EXCEPTION)
150 retval_servant=PortableServer_POA_reference_to_servant(servant->poa,retval,ev);
151 if (ev->_major!=CORBA_NO_EXCEPTION)
152 return NULL; /* 'retval' leak */
154 if (GNOME_VFS_OK!=(errvfsresult=captive_file_new_create(&retval_servant->captive_file_object,
155 servant->captive_vfs_object,pathname,mode,exclusive,perm))) {
156 impl_Captive_File__destroy(retval_servant,ev);
157 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
165 static void impl_Captive_File_read(impl_POA_Captive_File *servant,Captive_Bytes **buffer_corba_return,
166 const Captive_GnomeVFSFileSize num_bytes,CORBA_Environment *ev)
168 Captive_Bytes *buffer_corba;
169 GnomeVFSFileSize bytes_read;
170 GnomeVFSResult errvfsresult;
172 buffer_corba=Captive_Bytes__alloc();
173 buffer_corba->_maximum=num_bytes;
174 buffer_corba->_length=0;
175 buffer_corba->_buffer=Captive_Bytes_allocbuf(buffer_corba->_maximum);
176 buffer_corba->_release=TRUE;
178 if (GNOME_VFS_OK!=(errvfsresult=captive_file_read(servant->captive_file_object,
179 buffer_corba->_buffer,num_bytes,&bytes_read))) {
180 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
181 Captive_Bytes__freekids(buffer_corba,NULL/* 'd'; meaning? */);
182 CORBA_free(buffer_corba);
186 buffer_corba->_length=bytes_read;
187 *buffer_corba_return=buffer_corba;
191 static void impl_Captive_File_write(impl_POA_Captive_File *servant,
192 const Captive_Bytes *buffer_corba,Captive_GnomeVFSFileSize *bytes_written_return,CORBA_Environment *ev)
194 GnomeVFSFileSize bytes_written;
195 GnomeVFSResult errvfsresult;
197 if (GNOME_VFS_OK!=(errvfsresult=captive_file_write(servant->captive_file_object,
198 buffer_corba->_buffer,buffer_corba->_length,&bytes_written))) {
199 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
203 *bytes_written_return=bytes_written;
207 static void impl_Captive_File_seek(impl_POA_Captive_File *servant,
208 const Captive_GnomeVFSSeekPosition whence,const Captive_GnomeVFSFileOffset offset,CORBA_Environment *ev)
210 GnomeVFSResult errvfsresult;
212 if (GNOME_VFS_OK!=(errvfsresult=captive_file_seek(servant->captive_file_object,whence,offset))) {
213 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
219 static void impl_Captive_File_tell
220 (impl_POA_Captive_File *servant,Captive_GnomeVFSFileOffset *offset_return,CORBA_Environment *ev)
222 GnomeVFSFileOffset offset_captive;
223 GnomeVFSResult errvfsresult;
225 if (GNOME_VFS_OK!=(errvfsresult=captive_file_tell(servant->captive_file_object,&offset_captive))) {
226 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
230 *offset_return=offset_captive;
234 static void impl_Captive_File_remove(impl_POA_Captive_File *servant,CORBA_Environment *ev)
236 GnomeVFSResult errvfsresult;
238 if (GNOME_VFS_OK!=(errvfsresult=captive_file_remove(servant->captive_file_object))) {
239 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
245 static void impl_Captive_File_file_info_get
246 (impl_POA_Captive_File *servant,Captive_GnomeVFSFileInfo **file_info_corba_return,CORBA_Environment *ev)
248 GnomeVFSFileInfo file_info_captive;
249 GnomeVFSResult errvfsresult;
250 Captive_GnomeVFSFileInfo *file_info_corba;
252 if (GNOME_VFS_OK!=(errvfsresult=captive_file_file_info_get(servant->captive_file_object,&file_info_captive))) {
253 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
257 file_info_corba=Captive_GnomeVFSFileInfo__alloc();
259 if (GNOME_VFS_OK!=(errvfsresult=captive_sandbox_file_info_captive_to_corba(
260 file_info_corba,&file_info_captive))) {
261 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
262 Captive_GnomeVFSFileInfo__freekids(file_info_corba,NULL/* 'd'; meaning? */);
263 CORBA_free(file_info_corba);
267 *file_info_corba_return=file_info_corba;
271 static void impl_Captive_File_file_info_set(impl_POA_Captive_File *servant,
272 const Captive_GnomeVFSFileInfo *file_info_corba,const Captive_GnomeVFSSetFileInfoMask mask,CORBA_Environment *ev)
274 GnomeVFSFileInfo file_info_captive;
275 GnomeVFSResult errvfsresult;
277 if (GNOME_VFS_OK!=(errvfsresult=captive_sandbox_file_info_corba_to_captive(
278 &file_info_captive,file_info_corba))) {
279 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
283 if (GNOME_VFS_OK!=(errvfsresult=captive_file_file_info_set(servant->captive_file_object,&file_info_captive,mask))) {
284 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
290 static void impl_Captive_File_truncate
291 (impl_POA_Captive_File *servant,const Captive_GnomeVFSFileSize file_size,CORBA_Environment *ev)
293 GnomeVFSResult errvfsresult;
295 if (GNOME_VFS_OK!=(errvfsresult=captive_file_truncate(servant->captive_file_object,file_size))) {
296 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);
302 static void impl_Captive_File_move
303 (impl_POA_Captive_File *servant,const CORBA_char *pathname_new,const CORBA_boolean force_replace,CORBA_Environment *ev)
305 GnomeVFSResult errvfsresult;
307 if (GNOME_VFS_OK!=(errvfsresult=captive_file_move(servant->captive_file_object,pathname_new,force_replace))) {
308 captive_sandbox_child_GnomeVFSResultException_throw(ev,errvfsresult);