2 * CORBA/ORBit server side of Vfs 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-Vfs.h" /* self */
24 #include <glib/gmessages.h>
25 #include "captive/macros.h"
26 #include "server-Directory.h"
27 #include "server-File.h"
29 #include "server-GLogFunc.h"
30 #include "client-CaptiveIOChannel.h"
33 static void impl_Captive_Vfs_fini(impl_POA_Captive_Vfs *servant,CORBA_Environment *ev);
34 static void impl_Captive_Vfs_init
35 (impl_POA_Captive_Vfs *servant,const Captive_CaptiveOptions *options_corba,CORBA_Environment *ev);
36 static void impl_Captive_Vfs_shutdown(impl_POA_Captive_Vfs *servant,CORBA_Environment *ev);
38 static PortableServer_ServantBase__epv impl_Captive_Vfs_base_epv={
39 NULL, /* _private data */
40 (gpointer)&impl_Captive_Vfs_fini, /* finalize routine */
41 NULL, /* default_POA routine */
43 static POA_Captive_Vfs__epv impl_Captive_Vfs_epv={
45 (gpointer)&impl_Captive_Vfs_init,
46 (gpointer)&impl_Captive_Vfs_shutdown,
47 (gpointer)&impl_Captive_Vfs_directory_new_open,
48 (gpointer)&impl_Captive_Vfs_directory_new_make,
49 (gpointer)&impl_Captive_Vfs_file_new_open,
50 (gpointer)&impl_Captive_Vfs_file_new_create,
52 static POA_Captive_Vfs__vepv impl_Captive_Vfs_vepv={
53 &impl_Captive_Vfs_base_epv,
54 &impl_Captive_Vfs_epv,
58 Captive_Vfs impl_Captive_Vfs__create(PortableServer_POA poa,CORBA_Environment *ev)
61 impl_POA_Captive_Vfs *newservant;
62 PortableServer_ObjectId *objid;
64 captive_new0(newservant); /* FIXME: leak */
65 newservant->servant.vepv=&impl_Captive_Vfs_vepv;
67 newservant->captive_vfs_object=NULL;
68 POA_Captive_Vfs__init((PortableServer_Servant)newservant,ev);
69 objid=PortableServer_POA_activate_object(poa,newservant,ev);
71 retval=PortableServer_POA_servant_to_reference(poa,newservant,ev);
77 static void impl_Captive_Vfs_fini(impl_POA_Captive_Vfs *servant,CORBA_Environment *ev)
79 if (servant->captive_vfs_object) {
80 g_object_unref(servant->captive_vfs_object);
81 servant->captive_vfs_object=NULL;
86 static Captive_CaptiveIOChannel options_corba_image_iochannel_copy;
88 void impl_Captive_Vfs__destroy(impl_POA_Captive_Vfs *servant,CORBA_Environment *ev)
90 PortableServer_ObjectId *objid;
92 objid=PortableServer_POA_servant_to_id(servant->poa,servant,ev);
93 PortableServer_POA_deactivate_object(servant->poa,objid,ev);
95 impl_Captive_Vfs_fini(servant,ev);
96 CORBA_Object_release(options_corba_image_iochannel_copy,ev);
101 static void options_module_corba_to_options_module_captive
102 (struct captive_options_module *dest_options_module_captive,const Captive_CaptiveOptionsModule *src_options_module_corba)
104 g_return_if_fail(dest_options_module_captive!=NULL);
105 g_return_if_fail(src_options_module_corba!=NULL);
107 dest_options_module_captive->pathname_utf8=g_strdup(src_options_module_corba->pathname_utf8);
108 dest_options_module_captive->type=CAPTIVE_OPTIONS_MODULE_TYPE_PE32;
109 dest_options_module_captive->u.pe32.base=g_memdup(src_options_module_corba->data._buffer,
110 src_options_module_corba->data._length);
111 dest_options_module_captive->u.pe32.length=src_options_module_corba->data._length;
112 dest_options_module_captive->u.pe32.mapped=FALSE;
116 static void impl_Captive_Vfs_init
117 (impl_POA_Captive_Vfs *servant,const Captive_CaptiveOptions *options_corba,CORBA_Environment *ev)
119 struct captive_options options_captive;
120 GnomeVFSResult errvfsresult;
123 g_return_if_fail(servant->captive_vfs_object==NULL);
125 options_corba_image_iochannel_copy=CORBA_Object_duplicate(options_corba->image_iochannel,ev);
126 if (ev->_major!=CORBA_NO_EXCEPTION)
129 /* impl_Captive_Vfs_init_g_log_func() does its own copy of 'options_corba->g_log_func'. */
130 impl_Captive_Vfs_init_g_log_func(options_corba->g_log_func,options_corba->debug_messages,ev);
132 captive_options_init(&options_captive);
134 options_module_corba_to_options_module_captive(&options_captive.filesystem,&options_corba->filesystem);
136 options_captive.debug_messages=options_corba->debug_messages;
137 options_captive.rwmode =options_corba->rwmode;
138 options_captive.media =options_corba->media;
140 options_captive.image_iochannel=(GIOChannel *)captive_io_channel_new(
141 options_corba_image_iochannel_copy, /* corba_captive_io_channel */
142 (options_captive.rwmode!=CAPTIVE_OPTION_RWMODE_RO)); /* writeable */
144 for (moduleui=0;moduleui<options_corba->load_module._length;moduleui++) {
145 struct captive_options_module *options_module;
147 captive_new(options_module);
148 options_module_corba_to_options_module_captive(options_module,options_corba->load_module._buffer+moduleui);
149 options_captive.load_module=g_list_append(options_captive.load_module,options_module);
152 g_assert(captive_sandbox_server_argv==NULL);
154 if (GNOME_VFS_OK!=(errvfsresult=captive_vfs_new(&servant->captive_vfs_object,&options_captive))) {
155 CORBA_exception_set(ev,CORBA_USER_EXCEPTION,ex_Captive_GnomeVFSResultException,GINT_TO_POINTER((gint)errvfsresult));
156 captive_options_free(&options_captive);
160 captive_options_free(&options_captive);
162 g_assert(servant->captive_vfs_object!=NULL);
166 static gboolean impl_Captive_Vfs_shutdown_idle(gpointer data /* unused */)
168 sandbox_child_shutdown();
170 return FALSE; /* remove me */
173 static void impl_Captive_Vfs_shutdown(impl_POA_Captive_Vfs *servant,CORBA_Environment *ev)
177 /* Shutdown 'servant->captive_vfs_object' synchronously as it may
178 * flush its buffers needed to be transferred to our parent.
180 impl_Captive_Vfs_fini(servant,&captive_corba_ev);
181 g_assert(validate_CORBA_Environment(&captive_corba_ev));
183 sandbox_child_prepare_shutdown();
185 /* Do not call sandbox_child_shutdown() directly as we would fail
186 * to finish this CORBA method call properly.
187 * Do not call g_idle_add_full() as it would miss linc main loop.
189 source=g_idle_source_new ();
190 g_source_set_priority(source,G_PRIORITY_LOW);
191 g_source_set_callback(
193 (GSourceFunc)impl_Captive_Vfs_shutdown_idle, /* func */
196 g_source_attach(source,
197 g_main_loop_get_context(linc_main_get_loop())); /* context; NULL means 'default context' */
198 g_source_unref(source);