+object shutdown() functions as release() will not destroy() servants
[captive.git] / src / libcaptive / sandbox / server-File.c
index b897855..93a3271 100644 (file)
@@ -45,6 +45,7 @@ static void impl_Captive_File_truncate
                (impl_POA_Captive_File *servant,const Captive_GnomeVFSFileSize file_size,CORBA_Environment *ev);
 static void impl_Captive_File_move
                (impl_POA_Captive_File *servant,const CORBA_char *pathname_new,const CORBA_boolean force_replace,CORBA_Environment *ev);
+static void impl_Captive_File_shutdown(impl_POA_Captive_File *servant,CORBA_Environment *ev);
 
 
 static PortableServer_ServantBase__epv impl_Captive_File_base_epv={
@@ -63,6 +64,7 @@ static POA_Captive_File__epv impl_Captive_File_epv={
        (gpointer)&impl_Captive_File_file_info_set,
        (gpointer)&impl_Captive_File_truncate,
        (gpointer)&impl_Captive_File_move,
+       (gpointer)&impl_Captive_File_shutdown,
        };
 static POA_Captive_File__vepv impl_Captive_File_vepv={
        &impl_Captive_File_base_epv,
@@ -117,6 +119,8 @@ Captive_File retval;
 impl_POA_Captive_File *retval_servant;
 GnomeVFSResult errvfsresult;
 
+       g_return_val_if_fail(servant->captive_vfs_object!=NULL,NULL);   /* not yet initialized? */
+
        retval=impl_Captive_File__create(servant->poa,ev);
        if (ev->_major!=CORBA_NO_EXCEPTION)
                return NULL;
@@ -143,6 +147,8 @@ Captive_File retval;
 impl_POA_Captive_File *retval_servant;
 GnomeVFSResult errvfsresult;
 
+       g_return_val_if_fail(servant->captive_vfs_object!=NULL,NULL);   /* not yet initialized? */
+
        retval=impl_Captive_File__create(servant->poa,ev);
        if (ev->_major!=CORBA_NO_EXCEPTION)
                return NULL;
@@ -309,3 +315,40 @@ GnomeVFSResult errvfsresult;
                return;
                }
 }
+
+
+static gboolean impl_Captive_File_shutdown_idle(impl_POA_Captive_File *servant /* data */)
+{
+       impl_Captive_File__destroy(servant,&captive_corba_ev);
+       g_assert(validate_CORBA_Environment(&captive_corba_ev));
+
+       return FALSE;   /* remove me */
+}
+
+static void impl_Captive_File_shutdown(impl_POA_Captive_File *servant,CORBA_Environment *ev)
+{
+GSource *source;
+
+       /* Shutdown 'servant->captive_file_object' synchronously as it may
+        * flush its buffers needed to be transferred to our parent.
+        */
+       impl_Captive_File_fini(servant,&captive_corba_ev);
+       g_assert(validate_CORBA_Environment(&captive_corba_ev));
+
+       /* Do not call impl_Captive_File__destroy() directly as we would fail
+        * to finish this CORBA method call properly.
+        * Do not call g_idle_add_full() as it would miss linc main loop.
+        * FIXME: STATUS_SHARING_VIOLATION error during batch processing.
+        *  - probably exclusive access to be changed to shareable one
+        */
+  source=g_idle_source_new ();
+       g_source_set_priority(source,G_PRIORITY_LOW);
+  g_source_set_callback(
+                       source, /* source */
+                       (GSourceFunc)impl_Captive_File_shutdown_idle,   /* func */
+                       servant,        /* data */
+                       NULL);  /* notify */
+  g_source_attach(source,
+                       g_main_loop_get_context(linc_main_get_loop())); /* context; NULL means 'default context' */
+  g_source_unref(source);
+}