One to many (Dirves to Volumes) patch round 1
- From: "John (J5) Palmieri" <johnp redhat com>
- To: gnome-vfs-list gnome org
- Cc: utopia gnome org
- Subject: One to many (Dirves to Volumes) patch round 1
- Date: Mon, 12 Jul 2004 14:37:45 -0400
Here is the first round of API changes for Gnome-VFS and making one
drive able to describe more than one volume (i.e. multiple partitions,
multisession CDs, etc.). Basically this patch changes the
GnomeVFSVolume *volume member in the GnomeVFSPrivateDrive struct to be
GList *volumes and then changes the API to accommodate the list (i.e.
set methods become add methods). Right now this does not add any new
functionality but serves as the basis for the one-to-many change
(Bugzilla bug 143888). It lays the foundation while making sure gnome-
vfs still works as expected before I start integrating the actual code
to do multiple volumes per drive using hal. If anyone sees any glaring
mistakes please let me know.
One issue that I am not sure how to deal with is the get_data_for_drive
method which searches the volume for info on the drive if the volume
exists. That is fine if there is only one volume but which volume do
you use if there are more than one?
Attached is the patch against CVS. Comments welcome. I would
especially like to know if I did the Corba stuff correctly. It was my
first time actually using Corba directly and I wanted to make sure I
didn't miss anything.
--
John (J5) Palmieri
Associate Software Engineer
Desktop Group
Red Hat, Inc.
Blog: http://martianrock.com
? gnome-vfs.one-to-many-1.patch
? doc/tmpl/gnome-vfs-dns-sd.sgml
? doc/tmpl/gnome-vfs-volumes.sgml
? imported/Makefile
? imported/Makefile.in
? imported/neon/Makefile.in
? libgnomevfs/.gnome-vfs-drive.h.swp
? libgnomevfs/.gnome-vfs-volume-monitor-private.h.swp
? libgnomevfs/.gnome-vfs-volume.c.swp
? libgnomevfs/gnome-vfs-drive.c.one-to-many-volumes
? libgnomevfs/gnome-vfs-volume-monitor-private.h.one-to-many-volumes
? libgnomevfs/gnome-vfs-volume-ops.c.one-to-many-volumes
? libgnomevfs/gnome-vfs-volume.c.one-to-many-volumes
? libgnomevfs/s-enum-types-c
? libgnomevfs/s-enum-types-h
? modules/computer-method.c.one-to-many-volumes
? test/test-dns-sd
Index: libgnomevfs/GNOME_VFS_Daemon.idl
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/GNOME_VFS_Daemon.idl,v
retrieving revision 1.7
diff -u -p -r1.7 GNOME_VFS_Daemon.idl
--- libgnomevfs/GNOME_VFS_Daemon.idl 20 Apr 2004 13:27:46 -0000 1.7
+++ libgnomevfs/GNOME_VFS_Daemon.idl 12 Jul 2004 18:34:13 -0000
@@ -54,7 +54,7 @@ module GNOME {
struct Drive {
long id;
long device_type;
- long volume;
+ sequence<long> volumes;
string device_path;
string activation_uri;
string display_name;
Index: libgnomevfs/gnome-vfs-drive.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-drive.c,v
retrieving revision 1.4
diff -u -p -r1.4 gnome-vfs-drive.c
--- libgnomevfs/gnome-vfs-drive.c 26 Nov 2003 12:18:38 -0000 1.4
+++ libgnomevfs/gnome-vfs-drive.c 12 Jul 2004 18:34:13 -0000
@@ -162,10 +162,17 @@ gnome_vfs_drive_finalize (GObject *objec
priv = drive->priv;
- if (priv->volume) {
- _gnome_vfs_volume_unset_drive (priv->volume,
- drive);
- gnome_vfs_volume_unref (priv->volume);
+ if (priv->volumes) {
+ GList *current_vol = priv->volumes;
+
+ while (current_vol) {
+ GnomeVFSVolume *vol = GNOME_VFS_VOLUME (current_vol->data);
+ _gnome_vfs_volume_unset_drive (vol,
+ drive);
+ gnome_vfs_volume_unref (vol);
+
+ current_vol = g_list_next (current_vol);
+ }
}
g_free (priv->device_path);
g_free (priv->activation_uri);
@@ -190,17 +197,55 @@ gnome_vfs_drive_get_device_type (GnomeVF
return drive->priv->device_type;
}
+#ifndef GNOME_VFS_DISABLE_DEPRICATED
GnomeVFSVolume *
gnome_vfs_drive_get_mounted_volume (GnomeVFSDrive *drive)
{
GnomeVFSVolume *vol;
-
+ GList *first_vol;
+
G_LOCK (drives);
- vol = gnome_vfs_volume_ref (drive->priv->volume);
+ first_vol = g_list_first (drive->priv->volumes);
+
+ if (first_vol != NULL) {
+ vol = GNOME_VFS_VOLUME (first_vol->data);
+ vol = gnome_vfs_volume_ref (vol);
+ } else {
+ vol = NULL;
+ }
+
G_UNLOCK (drives);
return vol;
}
+#endif /*GNOME_VFS_DISABLE_DEPRICATED*/
+
+void
+gnome_vfs_drive_free_volume_list (GList *volumes)
+{
+ g_assert (volumes != NULL);
+ g_list_foreach (volumes,
+ (GFunc)gnome_vfs_volume_unref,
+ NULL);
+
+ g_list_free (volumes);
+}
+
+GList *
+gnome_vfs_drive_get_mounted_volumes (GnomeVFSDrive *drive)
+{
+ GList *return_list;
+
+ G_LOCK (drives);
+ return_list = g_list_copy (drive->priv->volumes);
+ g_list_foreach (return_list,
+ (GFunc)gnome_vfs_volume_ref,
+ NULL);
+
+ G_UNLOCK (drives);
+
+ return return_list;
+}
gboolean
gnome_vfs_drive_is_mounted (GnomeVFSDrive *drive)
@@ -208,32 +253,38 @@ gnome_vfs_drive_is_mounted (GnomeVFSDriv
gboolean res;
G_LOCK (drives);
- res = drive->priv->volume != NULL;
+ res = drive->priv->volumes != NULL;
G_UNLOCK (drives);
return res;
}
-
void
-_gnome_vfs_drive_unset_volume (GnomeVFSDrive *drive,
+_gnome_vfs_drive_remove_volume (GnomeVFSDrive *drive,
GnomeVFSVolume *volume)
{
G_LOCK (drives);
- g_assert (drive->priv->volume == volume);
- drive->priv->volume = NULL;
+ g_assert ((g_list_find (drive->priv->volumes,
+ volume)) != NULL);
+
+ drive->priv->volumes = g_list_remove (drive->priv->volumes,
+ volume);
G_UNLOCK (drives);
gnome_vfs_volume_unref (volume);
}
void
-_gnome_vfs_drive_set_mounted_volume (GnomeVFSDrive *drive,
+_gnome_vfs_drive_add_mounted_volume (GnomeVFSDrive *drive,
GnomeVFSVolume *volume)
{
G_LOCK (drives);
- g_assert (drive->priv->volume == NULL);
-
- drive->priv->volume = gnome_vfs_volume_ref (volume);
+
+ g_assert ((g_list_find (drive->priv->volumes,
+ volume)) == NULL);
+
+ drive->priv->volumes = g_list_append (drive->priv->volumes,
+ gnome_vfs_volume_ref (volume));
+
G_UNLOCK (drives);
}
@@ -322,17 +373,34 @@ void
gnome_vfs_drive_to_corba (GnomeVFSDrive *drive,
GNOME_VFS_Drive *corba_drive)
{
- GnomeVFSVolume *volume;
+ CORBA_sequence_CORBA_long corba_volumes;
corba_drive->id = drive->priv->id;
corba_drive->device_type = drive->priv->device_type;
- volume = gnome_vfs_drive_get_mounted_volume (drive);
- if (volume != NULL) {
- corba_drive->volume = volume->priv->id;
- gnome_vfs_volume_unref (volume);
+
+ if (drive->priv->volumes != NULL) {
+ int i;
+ guint length = g_list_length (drive->priv->volumes);
+ GList *current = drive->priv->volumes;
+
+ corba_volumes._maximum = length;
+ corba_volumes._length = length;
+ corba_volumes._buffer = CORBA_sequence_CORBA_long_allocbuf (length);
+
+ for (i = 0; i < length; i++) {
+ GnomeVFSVolume *volume;
+
+ volume = GNOME_VFS_VOLUME(current->data);
+ corba_volumes._buffer[i] = volume->priv->id;
+ current = g_list_next (current);
+ }
+
+ corba_drive->volumes = corba_volumes;
} else {
- corba_drive->volume = 0;
+ corba_drive->volumes._maximum = 0;
+ corba_drive->volumes._length = 0;
}
+
corba_drive->device_path = corba_string_or_null_dup (drive->priv->device_path);
corba_drive->activation_uri = corba_string_or_null_dup (drive->priv->activation_uri);
corba_drive->display_name = corba_string_or_null_dup (drive->priv->display_name);
@@ -353,11 +421,16 @@ _gnome_vfs_drive_from_corba (const GNOME
drive->priv->id = corba_drive->id;
drive->priv->device_type = corba_drive->device_type;
- if (corba_drive->volume != 0) {
- drive->priv->volume = gnome_vfs_volume_monitor_get_volume_by_id (volume_monitor,
- corba_drive->volume);
- if (drive->priv->volume != NULL) {
- _gnome_vfs_volume_set_drive (drive->priv->volume, drive);
+ if (corba_drive->volumes._length != 0) {
+ int i;
+
+ for (i = 0; i < corba_drive->volumes._length; i++) {
+ GnomeVFSVolume *volume = gnome_vfs_volume_monitor_get_volume_by_id (volume_monitor,
+ corba_drive->volumes._buffer[i]);
+ if (volume != NULL) {
+ _gnome_vfs_drive_add_mounted_volume (drive, volume);
+ _gnome_vfs_volume_set_drive (volume, drive);
+ }
}
}
Index: libgnomevfs/gnome-vfs-drive.h
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-drive.h,v
retrieving revision 1.6
diff -u -p -r1.6 gnome-vfs-drive.h
--- libgnomevfs/gnome-vfs-drive.h 1 Mar 2004 09:43:31 -0000 1.6
+++ libgnomevfs/gnome-vfs-drive.h 12 Jul 2004 18:34:13 -0000
@@ -60,10 +60,17 @@ GType gnome_vfs_drive_get_type (void) G_
GnomeVFSDrive *gnome_vfs_drive_ref (GnomeVFSDrive *drive);
void gnome_vfs_drive_unref (GnomeVFSDrive *drive);
+void gnome_vfs_drive_free_volume_list (GList *volumes);
+
gulong gnome_vfs_drive_get_id (GnomeVFSDrive *drive);
GnomeVFSDeviceType gnome_vfs_drive_get_device_type (GnomeVFSDrive *drive);
+
+#ifndef GNOME_VFS_DISABLE_DEPRICATED
GnomeVFSVolume * gnome_vfs_drive_get_mounted_volume (GnomeVFSDrive *drive);
+#endif /*GNOME_VFS_DISABLE_DEPRICATED*/
+
+GList * gnome_vfs_drive_get_mounted_volumes (GnomeVFSDrive *drive);
char * gnome_vfs_drive_get_device_path (GnomeVFSDrive *drive);
char * gnome_vfs_drive_get_activation_uri (GnomeVFSDrive *drive);
char * gnome_vfs_drive_get_display_name (GnomeVFSDrive *drive);
@@ -86,5 +93,5 @@ void gnome_vfs_drive_eject (GnomeVFSDr
gpointer user_data);
G_END_DECLS
+#endif
-#endif /* GNOME_VFS_DRIVE_H */
Index: libgnomevfs/gnome-vfs-volume-monitor-daemon.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-volume-monitor-daemon.c,v
retrieving revision 1.8
diff -u -p -r1.8 gnome-vfs-volume-monitor-daemon.c
--- libgnomevfs/gnome-vfs-volume-monitor-daemon.c 3 Jul 2004 16:13:13 -0000 1.8
+++ libgnomevfs/gnome-vfs-volume-monitor-daemon.c 12 Jul 2004 18:34:13 -0000
@@ -544,7 +544,7 @@ create_drive_from_mount_point (GnomeVFSV
drive->priv->display_name = get_drive_name (volume_monitor, drive, mount);
drive->priv->is_user_visible = TRUE;
- drive->priv->volume = NULL;
+ drive->priv->volumes = NULL;
uri = gnome_vfs_get_uri_from_local_path (mount->mount_path);
mounted_volume = _gnome_vfs_volume_monitor_find_mtab_volume_by_activation_uri (volume_monitor, uri);
@@ -552,7 +552,7 @@ create_drive_from_mount_point (GnomeVFSV
if (mounted_volume != NULL &&
mounted_volume->priv->drive == NULL) {
- drive->priv->volume = gnome_vfs_volume_ref (mounted_volume);
+ _gnome_vfs_drive_add_mounted_volume (drive, mounted_volume);
_gnome_vfs_volume_set_drive (mounted_volume, drive);
}
@@ -805,14 +805,14 @@ create_vol_from_mount (GnomeVFSVolumeMon
g_free (uri);
if (containing_drive != NULL &&
- containing_drive->priv->volume == NULL) {
+ g_list_find (containing_drive->priv->volumes, vol) == NULL) {
/* Make sure the mounted volume for a visible drive is visible */
if (containing_drive->priv->is_user_visible) {
vol->priv->is_user_visible = 1;
}
vol->priv->drive = containing_drive;
- _gnome_vfs_drive_set_mounted_volume (containing_drive, vol);
+ _gnome_vfs_drive_add_mounted_volume (containing_drive, vol);
}
return vol;
Index: libgnomevfs/gnome-vfs-volume-monitor-private.h
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-volume-monitor-private.h,v
retrieving revision 1.4
diff -u -p -r1.4 gnome-vfs-volume-monitor-private.h
--- libgnomevfs/gnome-vfs-volume-monitor-private.h 22 Jan 2004 15:35:01 -0000 1.4
+++ libgnomevfs/gnome-vfs-volume-monitor-private.h 12 Jul 2004 18:34:13 -0000
@@ -68,7 +68,7 @@ struct _GnomeVFSVolumePrivate {
struct _GnomeVFSDrivePrivate {
gulong id;
GnomeVFSDeviceType device_type;
- GnomeVFSVolume *volume; /* Owning ref */
+ GList *volumes; /* GnomeVFSVolume list */
/* Only for unix mounts: */
char *device_path;
@@ -83,9 +83,9 @@ struct _GnomeVFSDrivePrivate {
void _gnome_vfs_volume_set_drive (GnomeVFSVolume *volume,
GnomeVFSDrive *drive);
-void _gnome_vfs_drive_set_mounted_volume (GnomeVFSDrive *drive,
+void _gnome_vfs_drive_add_mounted_volume (GnomeVFSDrive *drive,
GnomeVFSVolume *volume);
-void _gnome_vfs_drive_unset_volume (GnomeVFSDrive *drive,
+void _gnome_vfs_drive_remove_volume (GnomeVFSDrive *drive,
GnomeVFSVolume *volume);
void _gnome_vfs_volume_unset_drive (GnomeVFSVolume *volume,
GnomeVFSDrive *drive);
Index: libgnomevfs/gnome-vfs-volume-monitor.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-volume-monitor.c,v
retrieving revision 1.3
diff -u -p -r1.3 gnome-vfs-volume-monitor.c
--- libgnomevfs/gnome-vfs-volume-monitor.c 26 Nov 2003 12:18:38 -0000 1.3
+++ libgnomevfs/gnome-vfs-volume-monitor.c 12 Jul 2004 18:34:14 -0000
@@ -473,7 +473,7 @@ _gnome_vfs_volume_monitor_unmounted (Gno
drive = volume->priv->drive;
if (drive != NULL) {
_gnome_vfs_volume_unset_drive (volume, drive);
- _gnome_vfs_drive_unset_volume (drive, volume);
+ _gnome_vfs_drive_remove_volume (drive, volume);
}
gnome_vfs_volume_unref (volume);
@@ -499,17 +499,20 @@ void
_gnome_vfs_volume_monitor_disconnected (GnomeVFSVolumeMonitor *volume_monitor,
GnomeVFSDrive *drive)
{
- GnomeVFSVolume *volume;
+ GList *vol_list;
g_mutex_lock (volume_monitor->priv->mutex);
volume_monitor->priv->fstab_drives = g_list_remove (volume_monitor->priv->fstab_drives, drive);
drive->priv->is_connected = 0;
g_mutex_unlock (volume_monitor->priv->mutex);
- volume = drive->priv->volume;
- if (volume != NULL) {
- _gnome_vfs_volume_unset_drive (volume, drive);
- _gnome_vfs_drive_unset_volume (drive, volume);
+ vol_list = drive->priv->volumes;
+ if (vol_list != NULL) {
+ for (; vol_list != NULL; vol_list = g_list_next (vol_list)) {
+ GnomeVFSVolume *volume = GNOME_VFS_VOLUME (vol_list->data);
+ _gnome_vfs_volume_unset_drive (volume, drive);
+ _gnome_vfs_drive_remove_volume (drive, volume);
+ }
}
g_signal_emit (volume_monitor, volume_monitor_signals[DRIVE_DISCONNECTED], 0, drive);
Index: libgnomevfs/gnome-vfs-volume-ops.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-volume-ops.c,v
retrieving revision 1.11
diff -u -p -r1.11 gnome-vfs-volume-ops.c
--- libgnomevfs/gnome-vfs-volume-ops.c 3 Jun 2004 13:49:26 -0000 1.11
+++ libgnomevfs/gnome-vfs-volume-ops.c 12 Jul 2004 18:34:14 -0000
@@ -566,28 +566,25 @@ gnome_vfs_drive_unmount (GnomeVFSDrive
GnomeVFSVolumeOpCallback callback,
gpointer user_data)
{
- char *mount_path, *device_path, *uri;
- GnomeVFSVolume *volume;
+ GList *vol_list;
+ vol_list = gnome_vfs_drive_get_mounted_volumes (drive);
- volume = gnome_vfs_drive_get_mounted_volume (drive);
+ if (vol_list != NULL) {
+ GList *current_vol = vol_list;
- if (volume != NULL) {
- emit_pre_unmount (volume);
- }
+ while (current_vol) {
+ GnomeVFSVolume *vol = GNOME_VFS_VOLUME (current_vol->data);
+
+ gnome_vfs_volume_unmount (vol,
+ callback,
+ user_data);
- uri = gnome_vfs_drive_get_activation_uri (drive);
- mount_path = gnome_vfs_get_local_path_from_uri (uri);
- g_free (uri);
- device_path = gnome_vfs_drive_get_device_path (drive);
- mount_unmount_operation (mount_path,
- device_path,
- (volume == NULL) ? GNOME_VFS_DEVICE_TYPE_UNKNOWN:gnome_vfs_volume_get_device_type (volume),
- FALSE, FALSE,
- callback, user_data);
- g_free (mount_path);
- g_free (device_path);
- gnome_vfs_volume_unref (volume);
+ current_vol = g_list_next (current_vol);
+ }
+
+ gnome_vfs_drive_free_volume_list (vol_list);
+ }
}
void
@@ -595,28 +592,35 @@ gnome_vfs_drive_eject (GnomeVFSDrive *d
GnomeVFSVolumeOpCallback callback,
gpointer user_data)
{
- char *mount_path, *device_path, *uri;
- GnomeVFSVolume *volume;
+ GList *vol_list;
+ vol_list = gnome_vfs_drive_get_mounted_volumes (drive);
- volume = gnome_vfs_drive_get_mounted_volume (drive);
+ if (vol_list != NULL) {
+ GList *current_vol = vol_list;
- if (volume != NULL) {
- emit_pre_unmount (volume);
- }
+ while (current_vol) {
+ GnomeVFSVolume *vol = GNOME_VFS_VOLUME (current_vol->data);
+
+ current_vol = g_list_next (current_vol);
+
+ /* Check to see if this is the last volume */
+ /* If not simply unmount it */
+ /* If so the eject the media along with the unmount */
+ if (current_vol != NULL) {
+ gnome_vfs_volume_unmount (vol,
+ callback,
+ user_data);
+ } else {
+ gnome_vfs_volume_eject (vol,
+ callback,
+ user_data);
+ }
+
+ }
- uri = gnome_vfs_drive_get_activation_uri (drive);
- mount_path = gnome_vfs_get_local_path_from_uri (uri);
- g_free (uri);
- device_path = gnome_vfs_drive_get_device_path (drive);
- mount_unmount_operation (mount_path,
- device_path,
- (volume == NULL) ? GNOME_VFS_DEVICE_TYPE_UNKNOWN:gnome_vfs_volume_get_device_type (volume),
- FALSE, TRUE,
- callback, user_data);
- g_free (mount_path);
- g_free (device_path);
- gnome_vfs_volume_unref (volume);
+ gnome_vfs_drive_free_volume_list (vol_list);
+ }
}
Index: libgnomevfs/gnome-vfs-volume.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-volume.c,v
retrieving revision 1.4
diff -u -p -r1.4 gnome-vfs-volume.c
--- libgnomevfs/gnome-vfs-volume.c 26 Nov 2003 12:18:38 -0000 1.4
+++ libgnomevfs/gnome-vfs-volume.c 12 Jul 2004 18:34:14 -0000
@@ -379,7 +379,7 @@ _gnome_vfs_volume_from_corba (const GNOM
volume->priv->drive = gnome_vfs_volume_monitor_get_drive_by_id (volume_monitor,
corba_volume->drive);
if (volume->priv->drive != NULL) {
- _gnome_vfs_drive_set_mounted_volume (volume->priv->drive, volume);
+ _gnome_vfs_drive_add_mounted_volume (volume->priv->drive, volume);
/* The drive reference is weak */
gnome_vfs_drive_unref (volume->priv->drive);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]