Enlightenment CVS committal

Author  : lordchaos
Project : e17
Module  : apps/evfs

Dir     : e17/apps/evfs/src/bin


Modified Files:
        Makefile.am evfs_main.c evfs_operation.c evfs_server_handle.c 
Added Files:
        evfs_operation_tasks.c 


Log Message:
* EVFS now has a workflow and eventing engine! This makes for a much cleaner, 
ecore_main_loop_iterate()-less system for the scheduling and processing of 
events in several chunks. At the moment, copy is the only major function to use 
this system, but recursive remove, and mkdir, are coming soon.  The 
operation_response system is currently slightly broken as a result of this, but 
will be fixed soon.

===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/evfs/src/bin/Makefile.am,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -3 -r1.17 -r1.18
--- Makefile.am 1 Mar 2006 22:12:44 -0000       1.17
+++ Makefile.am 12 Mar 2006 05:27:33 -0000      1.18
@@ -17,6 +17,7 @@
        $(top_srcdir)/src/common/evfs_common.c \
        evfs_server_handle.c \
        evfs_operation.c \
+       evfs_operation_tasks.c \
        $(top_srcdir)/src/common/evfs_vfolder.c
 
 evfscat_SOURCES = \
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/evfs/src/bin/evfs_main.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -3 -r1.37 -r1.38
--- evfs_main.c 11 Mar 2006 07:11:16 -0000      1.37
+++ evfs_main.c 12 Mar 2006 05:27:33 -0000      1.38
@@ -48,6 +48,12 @@
 
 static evfs_server *server;
 
+evfs_server* 
+evfs_server_get()
+{
+       return server;
+}
+
 evfs_client *
 evfs_client_get(Ecore_Ipc_Client * client)
 {
@@ -150,9 +156,11 @@
    return 1;
 }
 
-void
+int
 evfs_handle_command(evfs_client * client, evfs_command * command)
 {
+   int cleanup_command=1;
+       
    switch (command->type)
      {
      case EVFS_CMD_STARTMON_FILE:
@@ -190,6 +198,7 @@
      case EVFS_CMD_FILE_COPY:
         printf("File copy handler\n");
         evfs_handle_file_copy(client, command, command);
+       cleanup_command = 0;
         break;
 
      case EVFS_CMD_DIRECTORY_CREATE:
@@ -206,6 +215,8 @@
         printf("Warning - unhandled command %d\n", command->type);
         break;
      }
+
+   return cleanup_command;
 }
 
 evfs_plugin *
@@ -296,21 +307,24 @@
 int
 ecore_timer_enterer(__UNUSED__ void *data)
 {
+   evfs_operation_queue_run();
+       
    return 1;
 }
 
 int
 incoming_command_cb(__UNUSED__ void *data)
 {
+   int clean =0;
+       
    evfs_command_client *com_cli =
       ecore_list_remove_first(server->incoming_command_list);
 
    if (com_cli)
      {
-        evfs_handle_command(com_cli->client, com_cli->command);
-        evfs_cleanup_command(com_cli->command, EVFS_CLEANUP_FREE_COMMAND);
+        clean = evfs_handle_command(com_cli->client, com_cli->command);
+        if (clean) evfs_cleanup_command(com_cli->command, 
EVFS_CLEANUP_FREE_COMMAND);
         free(com_cli);
-
      }
 
    return 1;
@@ -335,7 +349,7 @@
    ecore_idle_enterer_add(incoming_command_cb, NULL);
 
    /*Add a timer, to make sure our event loop keeps going.  Kinda hacky */
-   ecore_timer_add(0.5, ecore_timer_enterer, NULL);
+   ecore_timer_add(0.1, ecore_timer_enterer, NULL);
 
    /*Load the plugins */
    evfs_load_plugins();
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/evfs/src/bin/evfs_operation.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- evfs_operation.c    2 Mar 2006 06:11:06 -0000       1.6
+++ evfs_operation.c    12 Mar 2006 05:27:33 -0000      1.7
@@ -3,6 +3,7 @@
 static long evfs_operation_count = 0;
 static int evfs_operation_init = 0;
 static Ecore_Hash *evfs_operation_hash;
+static Ecore_List *evfs_operation_queue;
 
 void
 evfs_operation_initialise()
@@ -15,27 +16,71 @@
 
    evfs_operation_hash =
       ecore_hash_new(ecore_direct_hash, ecore_direct_compare);
+
+   evfs_operation_queue = ecore_list_new();
 }
 
-evfs_operation *
-evfs_operation_new()
+void
+evfs_operation_base_init(evfs_operation* op)
 {
    evfs_operation_count++;
 
-   evfs_operation *op = NEW(evfs_operation);
-
    op->id = evfs_operation_count;
    op->status = EVFS_OPERATION_STATUS_NORMAL;
 
    ecore_hash_set(evfs_operation_hash, (long *)op->id, op);
 
-   return op;
+   /*Init the subtask list*/
+   op->sub_task = ecore_list_new();
+
+}
+
+evfs_operation_files* 
+evfs_operation_files_new(evfs_client* client, evfs_command* command)
+{
+       evfs_operation_files* op = calloc(1, sizeof(evfs_operation_files));
+       evfs_operation_base_init(EVFS_OPERATION(op));
+       EVFS_OPERATION(op)->type = EVFS_OPERATION_TYPE_FILES;
+       EVFS_OPERATION(op)->client = client;
+       EVFS_OPERATION(op)->command = command;
+
+       return op;
 }
 
 void
 evfs_operation_destroy(evfs_operation * op)
 {
+   evfs_operation_task* task;
+       
    ecore_hash_remove(evfs_operation_hash, (long *)op->id);
+
+   if (op->sub_task) {
+          ecore_list_goto_first(op->sub_task);
+          while ( (task = ecore_list_remove_first(op->sub_task))) {
+                  switch (task->type) {
+                          case EVFS_OPERATION_TASK_TYPE_FILE_COPY:
+                                  
evfs_cleanup_filereference(EVFS_OPERATION_TASK_FILE_COPY(task)->file_from);
+                                  
evfs_cleanup_filereference(EVFS_OPERATION_TASK_FILE_COPY(task)->file_to);
+                                  
+                                  break;
+                       
+                          case EVFS_OPERATION_TASK_TYPE_MKDIR:
+                                  
evfs_cleanup_filereference(EVFS_OPERATION_TASK_MKDIR(task)->file);
+                                  break;
+                          default:
+                                  printf("Destroying unknown task type\n");
+                                  break;
+                  }
+                  free(task);
+          }
+   
+          ecore_list_destroy(op->sub_task);
+   }
+
+   if (op->command) {
+          evfs_cleanup_command(op->command, EVFS_CLEANUP_FREE_COMMAND);
+   }
+
    free(op);
 }
 
@@ -58,3 +103,191 @@
    /*printf ("stub"); */
    evfs_operation_event_create(client, command, op,misc);
 }
+
+
+
+/*Sub task functions*/
+void evfs_operation_copy_task_add(evfs_operation* op, evfs_filereference* 
file_from, evfs_filereference* file_to, struct stat from_stat,
+               struct stat to_stat)
+{
+       evfs_operation_files* fop = EVFS_OPERATION_FILES(op);
+       evfs_operation_task_file_copy* copy = calloc(1, 
sizeof(evfs_operation_task_file_copy));
+
+       copy->file_from = file_from;
+       copy->file_to = file_to;
+       copy->next_byte = 0;
+       memcpy(&copy->source_stat, &from_stat, sizeof(struct stat));
+       memcpy(&copy->dest_stat, &to_stat, sizeof(struct stat));
+
+       EVFS_OPERATION_TASK(copy)->status = EVFS_OPERATION_TASK_STATUS_PENDING;
+       EVFS_OPERATION_TASK(copy)->type = EVFS_OPERATION_TASK_TYPE_FILE_COPY;
+
+       fop->total_bytes += from_stat.st_size;
+       fop->total_files += 1;
+
+       ecore_list_append(op->sub_task, copy);
+}
+
+
+/*Sub task functions*/
+void evfs_operation_mkdir_task_add(evfs_operation* op, evfs_filereference* dir)
+{
+       evfs_operation_files* fop = EVFS_OPERATION_FILES(op);
+       evfs_operation_task_mkdir* mkdir = calloc(1, 
sizeof(evfs_operation_task_mkdir));
+
+       mkdir->file = dir;
+
+       EVFS_OPERATION_TASK(mkdir)->status = EVFS_OPERATION_TASK_STATUS_PENDING;
+       EVFS_OPERATION_TASK(mkdir)->type = EVFS_OPERATION_TASK_TYPE_MKDIR;
+
+       fop->total_bytes += 0; /*Should we bother adding the size of a dir 
here?*/
+       fop->total_files += 1;
+
+       ecore_list_append(op->sub_task, mkdir);
+}
+
+
+
+/*MISC/DEBUG*/
+
+void evfs_operation_tasks_print(evfs_operation* op)
+{
+       evfs_operation_task* task;
+
+       printf("Operation subtasks:\n");
+       
+       ecore_list_goto_first(op->sub_task);
+       while ( (task = ecore_list_next(op->sub_task))) {
+               switch (task->type) {
+                       case EVFS_OPERATION_TASK_TYPE_FILE_COPY:
+                               printf("COPY: %s://%s to %s://%s\n", 
EVFS_OPERATION_TASK_FILE_COPY(task)->file_from->plugin_uri,
+                                                                    
EVFS_OPERATION_TASK_FILE_COPY(task)->file_from->path,
+                                                                    
EVFS_OPERATION_TASK_FILE_COPY(task)->file_to->plugin_uri,
+                                                                    
EVFS_OPERATION_TASK_FILE_COPY(task)->file_to->path);
+                                                                       
+                               break;
+                       case EVFS_OPERATION_TASK_TYPE_FILE_REMOVE:
+                               break;
+
+                       case EVFS_OPERATION_TASK_TYPE_MKDIR:
+                               printf("MKDIR: %s://%s \n", 
EVFS_OPERATION_TASK_MKDIR(task)->file->plugin_uri,
+                                                                    
EVFS_OPERATION_TASK_MKDIR(task)->file->path);
+                               break;
+
+                       default:
+                               break;
+               }
+       }
+
+       if (op->type == EVFS_OPERATION_TYPE_FILES) 
+               printf("Total bytes: %lld, Total files: %ld\n", 
EVFS_OPERATION_FILES(op)->total_bytes, EVFS_OPERATION_FILES(op)->total_files);
+
+       printf("** DONE\n");
+}
+
+void evfs_operation_queue_run() 
+{
+       evfs_operation* op;
+       
+       ecore_list_goto_first(evfs_operation_queue);
+       op = ecore_list_current(evfs_operation_queue);
+       
+       if (op) {
+               switch (op->type) {
+                       case EVFS_OPERATION_TYPE_FILES:
+                               /*printf("Files operation to process!\n");*/
+                               
+                               evfs_operation_run_tasks(op);
+                               break;
+                       default:
+                               printf("Unknown operation type in run queue - 
%d!\n", op->type);
+                               break;
+               }
+
+               if (op->status == EVFS_OPERATION_STATUS_COMPLETED) {
+                       ecore_list_remove_first(evfs_operation_queue);
+                       evfs_operation_destroy(op);
+                       
+                       printf("Finished running operation, and cleaned up!\n");
+               }
+
+       } else {
+               /*printf("No operations to process!\n");*/
+       }
+}
+
+void evfs_operation_run_tasks(evfs_operation* op)
+{
+       evfs_operation_task* task = NULL;
+
+       task = ecore_list_current(op->sub_task);
+       if (task) {
+               if (task->status == EVFS_OPERATION_TASK_STATUS_PENDING)
+                       task->status = EVFS_OPERATION_TASK_STATUS_EXEC;
+
+               
+               switch (task->type) {
+                       case EVFS_OPERATION_TASK_TYPE_FILE_COPY: {
+                               int prog = 0;
+                               double progress;
+                               double calc;
+                                                                        
+                               /*printf("...Processing file copy task 
type!\n");*/
+                               prog = evfs_operation_tasks_file_copy_run(op, 
EVFS_OPERATION_TASK_FILE_COPY(task));
+                               EVFS_OPERATION_FILES(op)->progress_bytes += 
prog;
+
+                               calc = 
(double)EVFS_OPERATION_FILES(op)->total_bytes / 
(double)EVFS_OPERATION_FILES(op)->progress_bytes;
+                               progress = 1.0 / calc;
+                               progress *= 100.0;
+
+                               evfs_file_progress_event_create(op->client,  
EVFS_OPERATION_TASK_FILE_COPY(task)->file_from,
+                                               
EVFS_OPERATION_TASK_FILE_COPY(task)->file_to,
+                                               op->command, progress, 
+                                               EVFS_PROGRESS_TYPE_CONTINUE);
+
+
+                               if (task->status == 
EVFS_OPERATION_TASK_STATUS_COMMITTED) {
+                                       
EVFS_OPERATION_FILES(task)->progress_files += 1;
+                                       op->processed_tasks++;
+                               }
+
+                               //FIXME - ther's probably a better place to put 
this*/
+                               if (op->processed_tasks == 
ecore_list_nodes(op->sub_task) && task->status == 
EVFS_OPERATION_TASK_STATUS_COMMITTED) {
+                                       
evfs_file_progress_event_create(op->client,  
EVFS_OPERATION_TASK_FILE_COPY(task)->file_from,
+                                               
EVFS_OPERATION_TASK_FILE_COPY(task)->file_to,
+                                               op->command, 100, 
+                                               EVFS_PROGRESS_TYPE_DONE);       
                                
+                               }
+                       }
+                       break;
+                       
+                       case EVFS_OPERATION_TASK_TYPE_MKDIR:
+                               /*printf("...Processing mkdir task type!\n");*/
+                               evfs_operation_tasks_mkdir_run(op, 
EVFS_OPERATION_TASK_MKDIR(task));
+
+                               if (task->status == 
EVFS_OPERATION_TASK_STATUS_COMMITTED) {
+                                       
EVFS_OPERATION_FILES(task)->progress_files += 1;
+                                       op->processed_tasks++;
+                               }
+                               break;                          
+                       default:
+                               printf("Can't process task - unknown type!\n");
+                               break;
+
+               }
+
+               if (task->status == EVFS_OPERATION_TASK_STATUS_COMMITTED) {
+                       ecore_list_next(op->sub_task);
+               }
+       } else {
+               /*If task is null, operation is completed!*/
+               op->status = EVFS_OPERATION_STATUS_COMPLETED;
+
+       }
+}
+
+void evfs_operation_queue_pending_add(evfs_operation* op)
+{
+       ecore_list_goto_first(op->sub_task);
+       ecore_list_append(evfs_operation_queue, op);
+}
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/evfs/src/bin/evfs_server_handle.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -3 -r1.48 -r1.49
--- evfs_server_handle.c        11 Mar 2006 07:11:16 -0000      1.48
+++ evfs_server_handle.c        12 Mar 2006 05:27:33 -0000      1.49
@@ -379,26 +379,21 @@
    evfs_plugin *plugin;
    evfs_plugin *dst_plugin;
 
-   char bytes[COPY_BLOCKSIZE];
-   int64 count;
    char destination_file[PATH_MAX];
-   long read_write_bytes = 0;
 
    struct stat file_stat;
    struct stat dest_stat;
 
    int progress = 0;
-   int last_notify_progress = 0;
-   int b_read = 0, b_write = 0;
    int res;
-   evfs_operation *op;
+   evfs_operation_files *op;
 
    /*Make a new evfs_operation, for client communication */
    if (root_command == command) {
-          op = evfs_operation_new();
-          root_command->op = op;
+          op = evfs_operation_files_new(client, root_command);
+          root_command->op = EVFS_OPERATION(op);
    } else {
-          op = root_command->op;
+          op = EVFS_OPERATION_FILES(root_command->op);
    }
 
    plugin =
@@ -418,8 +413,8 @@
              plugin->functions->evfs_file_read &&
              dst_plugin->functions->evfs_file_write))
           {
-             printf("AHH! Copy Not supported!\n");
-             evfs_operation_destroy(op);
+             printf("ARGH! Copy Not supported!\n");
+             evfs_operation_destroy(EVFS_OPERATION(op));
              return;
           }
 
@@ -428,128 +423,26 @@
         res =
            (*dst_plugin->functions->evfs_file_lstat) (command, &dest_stat, 1);
 
-        /*If this file exists, lock our operation until we get confirmation
-         * from the user that they want to overwrite, or not */
-        if ( (res != EVFS_ERROR) && !(op->status == 
EVFS_OPERATION_STATUS_OVERRIDE) )
-          {
-             printf("File overwrite\n");
-             evfs_operation_status_set(op, EVFS_OPERATION_STATUS_USER_WAIT);
-
-             evfs_operation_user_dispatch(client, root_command, op, 
command->file_command.files[1]->path);
-             while (op->status == EVFS_OPERATION_STATUS_USER_WAIT)
-               {
-                  ecore_main_loop_iterate();
-                  usleep(1);
-               }
-
-             if (op->response == EVFS_OPERATION_RESPONSE_NEGATE)
-               {
-                  printf("User opted not to overwrite file!\n");
-                  goto CLEANUP;
-               }
-             else
-               {
-                if (op->response == EVFS_OPERATION_RESPONSE_AFFIRM_ALL) {
-                        op->status = EVFS_OPERATION_STATUS_OVERRIDE;
-                }
-                      
-                  printf("User opted to overwrite file! -%d\n", op->response);
-               }
-          }
-
         if (!S_ISDIR(file_stat.st_mode))
           {
-             int fd = (*plugin->functions->evfs_file_open) (client,
-                                                            command->
-                                                            file_command.
-                                                            files[0]);
-
-             if (fd <= 0)
-               {
-                  printf("*************************  Could not open file!\n");
-                  goto CLEANUP;
-               }
-
-             (*dst_plugin->functions->evfs_file_create) (command->file_command.
-                                                         files[1]);
-
-             count = 0;
-
-            printf("Copying file, total file size %lld bytes\n", 
file_stat.st_size);
-             while (count < file_stat.st_size)
-               {
-                  
//(*plugin->functions->evfs_file_seek)(command->file_command.files[0], count, 
SEEK_SET);
+                 evfs_operation_copy_task_add(EVFS_OPERATION(op), 
+                      evfs_filereference_clone(command->file_command.files[0]),
+                      evfs_filereference_clone(command->file_command.files[1]),
+                      file_stat, dest_stat);
 
-                  read_write_bytes =
-                     (file_stat.st_size >
-                      count +
-                      COPY_BLOCKSIZE) ? COPY_BLOCKSIZE : (file_stat.st_size -
-                                                          count);
-
-                  //printf("Reading/writing %d bytes\n", read_write_bytes);
-
-                  //TODO: Implement error checking here
-                  b_read =
-                     (*plugin->functions->evfs_file_read) (client,
-                                                           command->
-                                                           file_command.
-                                                           files[0], bytes,
-                                                           read_write_bytes);
-                  if (b_read > 0)
-                    {
-                       b_write =
-                          (*dst_plugin->functions->evfs_file_write) (command->
-                                                                     
file_command.
-                                                                     files[1],
-                                                                     bytes,
-                                                                     b_read);
-                       //printf("%d  -> %d\n", b_read, b_write);
-                    }
-                  count += b_read;
-
-                  progress =
-                     (double)((double)count / (double)file_stat.st_size * 100);
-                  if (progress % 1 == 0 && last_notify_progress < progress)
-                    {
-                       evfs_file_progress_event_create(client, command,
-                                                       root_command, progress,
-                                                       
EVFS_PROGRESS_TYPE_CONTINUE);
-                       last_notify_progress = progress;
-                    }
-
-                  //printf("Bytes to go: %d\n", file_stat.st_size - count);
-
-                  /*Iterate */
-                  ecore_main_loop_iterate();
-               }
-             (*dst_plugin->functions->evfs_file_close) (command->file_command.
-                                                        files[1]);
-             (*plugin->functions->evfs_file_close) (command->file_command.
-                                                    files[0]);
-          }
-        else
-          {
+          } else {
              Ecore_List *directory_list = NULL;
 
+                 evfs_operation_mkdir_task_add(EVFS_OPERATION(op), 
+                      
evfs_filereference_clone(command->file_command.files[1]));
+
              /*First, we need a directory list... */
              (*plugin->functions->evfs_dir_list) (client, command,
                                                   &directory_list);
              if (directory_list)
                {
-                  int ret = 0;
                   evfs_filereference *file = NULL;
 
-                  /*OK, so the directory exists at the source, and contains 
files.
-                   * Let's make the destination directory first..*/
-                  printf("Making new directory '%s'",
-                         command->file_command.files[1]->path);
-                  ret =
-                     (*dst_plugin->functions->evfs_file_mkdir) (command->
-                                                                file_command.
-                                                                files[1]);
-                  printf("....ret was %d\n", ret);
-
-                  //printf("Recursive directory list for '%s' received..\n", 
command->file_command.files[0]->path);
                   while ((file = ecore_list_remove_first(directory_list)))
                     {
                        evfs_filereference *source = NEW(evfs_filereference);
@@ -592,9 +485,16 @@
           }
 
         /*Only send '100%' event when we're back at the top, or we aren't 
recursive */
-        if (command == root_command)
-           evfs_file_progress_event_create(client, command, root_command, 100,
-                                           EVFS_PROGRESS_TYPE_DONE);
+        if (command == root_command) {
+           /*evfs_file_progress_event_create(client, command, root_command, 
100,
+                                           EVFS_PROGRESS_TYPE_DONE);*/
+
+          evfs_operation_tasks_print(EVFS_OPERATION(op));
+
+          evfs_operation_queue_pending_add(EVFS_OPERATION(op));
+
+       }
+
 
      }
    else
@@ -603,11 +503,6 @@
                command->file_command.files[0]->plugin_uri,
                command->file_command.files[1]->plugin_uri);
      }
-
- CLEANUP:
-   if (command == root_command)
-          evfs_operation_destroy(op);
-
 }
 
 void




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to