File sandbox parent now maintains its own 'offset'.
authorshort <>
Wed, 10 Sep 2003 09:43:26 +0000 (09:43 +0000)
committershort <>
Wed, 10 Sep 2003 09:43:26 +0000 (09:43 +0000)
 - Needed for transparent vfs restarting.

src/libcaptive/client/file-parent.h
src/libcaptive/sandbox/parent-File.c

index ed7e6b8..63284e5 100644 (file)
@@ -47,6 +47,7 @@ struct _CaptiveFileParentObject {
 
        /*< private >*/
        Captive_File corba_File_object;
+       GnomeVFSFileOffset offset;
        };
 struct _CaptiveFileParentObjectClass {
        CaptiveFileObjectClass parent_class;
index 971a8b7..ccc6e6a 100644 (file)
@@ -115,6 +115,9 @@ CaptiveVfsParentObject *captive_vfs_parent_object;
 }
 
 
+static GnomeVFSResult captive_sandbox_parent_file_seek_slave
+               (CaptiveFileParentObject *captive_file_parent_object,GnomeVFSSeekPosition whence,GnomeVFSFileOffset offset);
+
 GnomeVFSResult captive_sandbox_parent_file_read(CaptiveFileParentObject *captive_file_parent_object,
                gpointer buffer_captive,GnomeVFSFileSize num_bytes,GnomeVFSFileSize *bytes_read_return)
 {
@@ -138,8 +141,12 @@ CaptiveVfsParentObject *captive_vfs_parent_object;
                xmlNewProp(xml_action,"num_bytes",captive_printf_alloca("%lu",(unsigned long)num_bytes));
                }
 
-       Captive_File_read(captive_file_parent_object->corba_File_object,&buffer_corba,num_bytes,&captive_corba_ev);
-       r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
+       r=captive_sandbox_parent_file_seek_slave(captive_file_parent_object,
+                       GNOME_VFS_SEEK_START,captive_file_parent_object->offset);
+       if (r==GNOME_VFS_OK) {
+               Captive_File_read(captive_file_parent_object->corba_File_object,&buffer_corba,num_bytes,&captive_corba_ev);
+               r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
+               }
        if (xml_action)
                xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
        if (r!=GNOME_VFS_OK)
@@ -148,6 +155,7 @@ CaptiveVfsParentObject *captive_vfs_parent_object;
        g_return_val_if_fail(buffer_corba->_length<=num_bytes,GNOME_VFS_ERROR_GENERIC);
        memcpy(buffer_captive,buffer_corba->_buffer,buffer_corba->_length);
        *bytes_read_return=buffer_corba->_length;
+       captive_file_parent_object->offset+=buffer_corba->_length;
 
        Captive_Bytes__freekids(buffer_corba,NULL/* 'd'; meaning? */);
        CORBA_free(buffer_corba);
@@ -183,19 +191,25 @@ CaptiveVfsParentObject *captive_vfs_parent_object;
                xmlNewProp(xml_action,"num_bytes",captive_printf_alloca("%lu",(unsigned long)num_bytes));
                }
 
-       buffer_corba_local._maximum=num_bytes;
-       buffer_corba_local._length=num_bytes;
-       buffer_corba_local._buffer=(/* de-const */gpointer)buffer_captive;
-       buffer_corba_local._release=FALSE;
-
-       Captive_File_write(captive_file_parent_object->corba_File_object,&buffer_corba_local,&bytes_written_corba,&captive_corba_ev);
-       r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
+       r=captive_sandbox_parent_file_seek_slave(captive_file_parent_object,
+                       GNOME_VFS_SEEK_START,captive_file_parent_object->offset);
+       if (r==GNOME_VFS_OK) {
+               buffer_corba_local._maximum=num_bytes;
+               buffer_corba_local._length=num_bytes;
+               buffer_corba_local._buffer=(/* de-const */gpointer)buffer_captive;
+               buffer_corba_local._release=FALSE;
+
+               Captive_File_write(captive_file_parent_object->corba_File_object,
+                               &buffer_corba_local,&bytes_written_corba,&captive_corba_ev);
+               r=captive_sandbox_parent_return_from_CORBA_Environment(&captive_corba_ev);
+               }
        if (xml_action)
                xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
        if (r!=GNOME_VFS_OK)
                return r;
 
        *bytes_written_return=bytes_written_corba;
+       captive_file_parent_object->offset+=bytes_written_corba;
 
        if (xml_action)
                xmlNewProp(xml_action,"bytes_written_return",captive_printf_alloca("%lu",(unsigned long)*bytes_written_return));
@@ -204,7 +218,7 @@ CaptiveVfsParentObject *captive_vfs_parent_object;
 }
 
 
-GnomeVFSResult captive_sandbox_parent_file_seek
+static GnomeVFSResult captive_sandbox_parent_file_seek_slave
                (CaptiveFileParentObject *captive_file_parent_object,GnomeVFSSeekPosition whence,GnomeVFSFileOffset offset)
 {
 GnomeVFSResult r;
@@ -236,7 +250,59 @@ CaptiveVfsParentObject *captive_vfs_parent_object;
 }
 
 
-GnomeVFSResult captive_sandbox_parent_file_tell(CaptiveFileParentObject *captive_file_parent_object,GnomeVFSFileOffset *offset_return)
+GnomeVFSResult captive_sandbox_parent_file_seek
+               (CaptiveFileParentObject *captive_file_parent_object,GnomeVFSSeekPosition whence,GnomeVFSFileOffset offset)
+{
+GnomeVFSResult r;
+xmlNode *xml_action=NULL;
+CaptiveVfsParentObject *captive_vfs_parent_object;
+
+       g_return_val_if_fail(CAPTIVE_FILE_PARENT_IS_OBJECT(captive_file_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(CAPTIVE_FILE_OBJECT(captive_file_parent_object)->vfs);
+
+       if (captive_vfs_parent_object->corba_bug_action) {
+               xml_action=xmlNewTextChild(captive_vfs_parent_object->corba_bug_action,NULL,"file_seek",NULL);
+               xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_parent_object));
+               xmlNewProp(xml_action,"whence",
+                               (whence==GNOME_VFS_SEEK_START ? "start" :
+                                       (whence==GNOME_VFS_SEEK_CURRENT ? "current" :
+                                               (whence==GNOME_VFS_SEEK_END ? "end" : captive_printf_alloca("%lu",(unsigned long)whence)))));
+               xmlNewProp(xml_action,"offset",captive_printf_alloca("%" G_GINT64_FORMAT,(gint64)offset));
+               }
+
+       switch (whence) {
+               case GNOME_VFS_SEEK_START:
+                       captive_file_parent_object->offset=offset;
+                       break;
+               case GNOME_VFS_SEEK_CURRENT:
+                       if (0
+                                       || (offset>0 && (captive_file_parent_object->offset+offset)<captive_file_parent_object->offset)
+                                       || (offset<0 && (captive_file_parent_object->offset+offset)>captive_file_parent_object->offset))
+                               r=GNOME_VFS_ERROR_BAD_PARAMETERS;
+                       else
+                               captive_file_parent_object->offset+=offset;
+                       break;
+               case GNOME_VFS_SEEK_END:
+                       g_assert_not_reached(); /* NOT IMPLEMENTED YET */
+                       r=GNOME_VFS_ERROR_GENERIC;
+                       break;
+               default:
+                       r=GNOME_VFS_ERROR_BAD_PARAMETERS;
+               }
+
+       if (xml_action)
+               xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
+       if (r!=GNOME_VFS_OK)
+               return r;
+
+       return GNOME_VFS_OK;
+}
+
+
+#if 0 /* unused */
+static GnomeVFSResult captive_sandbox_parent_file_tell_slave
+               (CaptiveFileParentObject *captive_file_parent_object,GnomeVFSFileOffset *offset_return)
 {
 Captive_GnomeVFSFileOffset offset_corba;
 GnomeVFSResult r;
@@ -267,6 +333,37 @@ CaptiveVfsParentObject *captive_vfs_parent_object;
 
        return GNOME_VFS_OK;
 }
+#endif
+
+
+GnomeVFSResult captive_sandbox_parent_file_tell(CaptiveFileParentObject *captive_file_parent_object,GnomeVFSFileOffset *offset_return)
+{
+GnomeVFSResult r;
+xmlNode *xml_action=NULL;
+CaptiveVfsParentObject *captive_vfs_parent_object;
+
+       g_return_val_if_fail(CAPTIVE_FILE_PARENT_IS_OBJECT(captive_file_parent_object),GNOME_VFS_ERROR_BAD_PARAMETERS);
+       g_return_val_if_fail(offset_return!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+       captive_vfs_parent_object=CAPTIVE_VFS_PARENT_OBJECT(CAPTIVE_FILE_OBJECT(captive_file_parent_object)->vfs);
+
+       if (captive_vfs_parent_object->corba_bug_action) {
+               xml_action=xmlNewTextChild(captive_vfs_parent_object->corba_bug_action,NULL,"file_tell",NULL);
+               xmlNewProp(xml_action,"object",captive_printf_alloca("%p",captive_file_parent_object));
+               }
+
+       *offset_return=captive_file_parent_object->offset;
+       r=GNOME_VFS_OK;
+       if (xml_action)
+               xmlNewProp(xml_action,"result",gnome_vfs_result_to_string(r));
+       if (r!=GNOME_VFS_OK)
+               return r;
+
+       if (xml_action)
+               xmlNewProp(xml_action,"offset_return",captive_printf_alloca("%" G_GINT64_FORMAT,(gint64)*offset_return));
+
+       return GNOME_VFS_OK;
+}
 
 
 GnomeVFSResult captive_sandbox_parent_file_remove(CaptiveFileParentObject *captive_file_parent_object)