add eject functions/events
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 16 May 2011 11:03:06 +0000 (11:03 +0000)
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 16 May 2011 11:03:06 +0000 (11:03 +0000)
SVN revision: 59443

legacy/eeze/ChangeLog
legacy/eeze/configure.ac
legacy/eeze/src/lib/Eeze_Disk.h
legacy/eeze/src/lib/eeze_disk.c
legacy/eeze/src/lib/eeze_disk_mount.c
legacy/eeze/src/lib/eeze_disk_private.h

index 82b84679bd5a1fef4d938e2674690fabf54692f1..b858480969a9084dee5741a0e9295e5872be8669 100644 (file)
@@ -1,3 +1,8 @@
+2011-05-16  Mike Blumenkrantz (discomfitor/zmike)
++EEZE_EVENT_DISK_EJECT
++eeze_disk_eject
+Functions for ejecting a disk
+
 2011-05-15  Mike Blumenkrantz (discomfitor/zmike)
 +eeze_disk_cancel
 Cancel the current pending mount/umount operation on a disk
index 6f014045b2dfca518370dd7ebc9c8a9e8ec181db..72c5c589dafbd634195c465a9443abce0ce9daed 100644 (file)
@@ -109,6 +109,7 @@ if test "x$eeze_mount" = "xyes";then
   with_umount="/bin/umount"
   AC_ARG_WITH([mount], AS_HELP_STRING([--with-mount], [specify mount bin @<:@default=detect@:>@]))
   AC_ARG_WITH([umount], AS_HELP_STRING([--with-umount], [specify umount bin @<:@default=detect@:>@]))
+  AC_ARG_WITH([eject], AS_HELP_STRING([--with-eject], [specify eject bin @<:@default=detect@:>@]))
   PKG_CHECK_MODULES([LIBMOUNT], [mount >= 2.18.0])
   mount_v=$(pkg-config --modversion mount)
   PKG_CHECK_MODULES([ECORE_FILE], [ecore-file >= 1.0.0])
@@ -122,6 +123,11 @@ if test "x$eeze_mount" = "xyes";then
     AC_PATH_PROG([with_umount], [umount], AC_MSG_ERROR([umount could not be found in PATH]))
   fi
   AC_DEFINE_UNQUOTED([EEZE_UNMOUNT_BIN], ["$with_umount"], [umount bin to use])
+
+  if test "x$with_eject" = "xdetect";then
+    AC_PATH_PROG([with_eject], [eject], AC_MSG_ERROR([eject could not be found in PATH]))
+  fi
+  AC_DEFINE_UNQUOTED([EEZE_EJECT_BIN], ["$with_eject"], [eject bin to use])
 fi
 AM_CONDITIONAL([OLD_LIBMOUNT], [test -n $mount_v -a $(echo $mount_v | cut -d'.' -f2) -lt 19])
 if test -z "$OLD_LIBMOUNT_TRUE" ; then
@@ -182,6 +188,7 @@ if test "x$eeze_mount" = "xyes";then
   echo
   echo "Mount..................: ${with_mount}"
   echo "Umount.................: ${with_umount}"
+  echo "Eject..................: ${with_eject}"
   echo
 fi
 echo "Test...................: ${have_eeze_udev_test}"
index 2571e9e6adf0addfa4f87171dacff7d741669d9d..5bc031b72cf99752d78e95213c7cb3e697a97cd8 100644 (file)
@@ -55,23 +55,19 @@ typedef enum
 
 EAPI extern int EEZE_EVENT_DISK_MOUNT;
 EAPI extern int EEZE_EVENT_DISK_UNMOUNT;
+EAPI extern int EEZE_EVENT_DISK_EJECT;
 EAPI extern int EEZE_EVENT_DISK_ERROR;
 
-typedef struct _Eeze_Event_Disk_Mount Eeze_Event_Disk_Mount;
-typedef struct _Eeze_Event_Disk_Unmount Eeze_Event_Disk_Unmount;
+typedef struct _Eeze_Event_Disk Eeze_Event_Disk_Mount;
+typedef struct _Eeze_Event_Disk Eeze_Event_Disk_Unmount;
+typedef struct _Eeze_Event_Disk Eeze_Event_Disk_Eject;
 typedef struct _Eeze_Disk Eeze_Disk;
 
-struct _Eeze_Event_Disk_Mount
+struct _Eeze_Event_Disk
 {
    Eeze_Disk *disk;
 };
 
-struct _Eeze_Event_Disk_Unmount
-{
-   Eeze_Disk *disk;
-};
-
-
 typedef struct _Eeze_Event_Disk_Error Eeze_Event_Disk_Error;
 
 struct _Eeze_Event_Disk_Error
index 3d84a6f41a7fcd7fc668c12236a374477f044cfa..2af2308b0078fc5cf0a3ed61fd38e7d95d9845fa 100644 (file)
@@ -197,6 +197,9 @@ eeze_disk_free(Eeze_Disk *disk)
      eina_strbuf_free(disk->mount_cmd);
    if (disk->unmount_cmd)
      eina_strbuf_free(disk->unmount_cmd);
+   if (disk->eject_cmd)
+     eina_strbuf_free(disk->eject_cmd);
+   if (disk->mounter) ecore_exe_kill(disk->mounter);
    _eeze_disks = eina_list_remove(_eeze_disks, disk);
    free(disk);
 }
index 5b22ad9872cbee14f0c3f7b03ebd4b8ef13fd231..5dccbbee0b8c75e7d8a566247c1ca5236240b1c2 100644 (file)
@@ -15,6 +15,7 @@
 
 EAPI int EEZE_EVENT_DISK_MOUNT = 0;
 EAPI int EEZE_EVENT_DISK_UNMOUNT = 0;
+EAPI int EEZE_EVENT_DISK_EJECT = 0;
 EAPI int EEZE_EVENT_DISK_ERROR = 0;
 static Ecore_Event_Handler *_mount_handler = NULL;
 static Eina_List *eeze_events = NULL;
@@ -91,7 +92,7 @@ _eeze_disk_mount_result_handler(void *data __UNUSED__, int type __UNUSED__, Ecor
         else
            _eeze_disk_mount_error_handler(disk, "incorrect invocation or permissions");
      }
-   else
+   else if (disk->mount_status == EEZE_DISK_UNMOUNTING)
      switch (ev->exit_code)
        {
         case 0:
@@ -104,11 +105,27 @@ _eeze_disk_mount_result_handler(void *data __UNUSED__, int type __UNUSED__, Ecor
 
         default:
           INF("Could not unmount disk, retrying");
-          disk->mounter = ecore_exe_pipe_run(eina_strbuf_string_get(disk->unmount_cmd), 0, disk);
+          disk->mounter = ecore_exe_run(eina_strbuf_string_get(disk->unmount_cmd), disk);
           eeze_events = eina_list_append(eeze_events, disk);
           return ECORE_CALLBACK_RENEW;
        }
-
+     else
+       switch (ev->exit_code)
+         {
+          case 0:
+            e = malloc(sizeof(Eeze_Event_Disk_Eject));
+            EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
+            e->disk = disk;
+            disk->mounter = NULL;
+            ecore_event_add(EEZE_EVENT_DISK_EJECT, e, NULL, NULL);
+            break;
+
+          default:
+            INF("Could not eject disk, retrying");
+            disk->mounter = ecore_exe_run(eina_strbuf_string_get(disk->unmount_cmd), disk);
+            eeze_events = eina_list_append(eeze_events, disk);
+            return ECORE_CALLBACK_RENEW;
+         }
    return ECORE_CALLBACK_RENEW;
 }
 
@@ -123,6 +140,7 @@ eeze_mount_init(void)
 {
    EEZE_EVENT_DISK_MOUNT = ecore_event_type_new();
    EEZE_EVENT_DISK_UNMOUNT = ecore_event_type_new();
+   EEZE_EVENT_DISK_EJECT = ecore_event_type_new();
    EEZE_EVENT_DISK_ERROR = ecore_event_type_new();
    _mount_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
                                            (Ecore_Event_Handler_Cb)_eeze_disk_mount_result_handler, NULL);
@@ -324,13 +342,37 @@ eeze_disk_unmount(Eeze_Disk *disk)
    return EINA_TRUE;
 }
 
+EAPI Eina_Bool
+eeze_disk_eject(Eeze_Disk *disk)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(disk, EINA_FALSE);
+
+   if (!disk->eject_cmd)
+     {
+        disk->eject_cmd = eina_strbuf_new();
+        if (disk->mount_wrapper)
+          eina_strbuf_append_printf(disk->eject_cmd, "%s ", disk->mount_wrapper);
+        eina_strbuf_append_printf(disk->eject_cmd, EEZE_EJECT_BIN" %s", eeze_disk_devpath_get(disk));
+     }
+
+   INF("Ejecting: %s", eina_strbuf_string_get(disk->eject_cmd));
+   disk->mounter = ecore_exe_run(eina_strbuf_string_get(disk->eject_cmd), disk);
+   if (!disk->mounter)
+     return EINA_FALSE;
+
+   eeze_events = eina_list_append(eeze_events, disk);
+   disk->mount_status = EEZE_DISK_EJECTING;
+   return EINA_TRUE;
+}
+
 EAPI void
 eeze_disk_cancel(Eeze_Disk *disk)
 {
    EINA_SAFETY_ON_NULL_RETURN(disk);
    if ((!disk->mount_status) || (!disk->mounter)) return;
    disk->mount_status = EEZE_DISK_NULL;
-   ecore_exe_quit(disk->mounter);
+   ecore_exe_kill(disk->mounter);
+   disk->mounter = NULL;
 }
 
 EAPI const char *
index 3146a088a64332cd02e4cbabaf2c4350d49db5cf..50347f057475e541c4458ead11e381dc90640dd1 100644 (file)
@@ -34,7 +34,8 @@ typedef enum
 {
    EEZE_DISK_NULL,
    EEZE_DISK_MOUNTING,
-   EEZE_DISK_UNMOUNTING
+   EEZE_DISK_UNMOUNTING,
+   EEZE_DISK_EJECTING
 } Eeze_Disk_Status;
 
 struct _Eeze_Disk
@@ -45,6 +46,7 @@ struct _Eeze_Disk
    Eeze_Disk_Status mount_status;
    Eina_Strbuf *mount_cmd;
    Eina_Strbuf *unmount_cmd;
+   Eina_Strbuf *eject_cmd;
    Eina_Bool mount_cmd_changed : 1;
    Eina_Bool unmount_cmd_changed : 1;
    Eina_Bool mounted : 1;