gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r3502 - in GNUnet/src: applications/fs/fsui applications/fs


From: grothoff
Subject: [GNUnet-SVN] r3502 - in GNUnet/src: applications/fs/fsui applications/fs/tools include
Date: Thu, 19 Oct 2006 21:56:48 -0700 (PDT)

Author: grothoff
Date: 2006-10-19 21:56:42 -0700 (Thu, 19 Oct 2006)
New Revision: 3502

Modified:
   GNUnet/src/applications/fs/fsui/TODO
   GNUnet/src/applications/fs/fsui/deserialize.c
   GNUnet/src/applications/fs/fsui/download.c
   GNUnet/src/applications/fs/fsui/fsui.c
   GNUnet/src/applications/fs/fsui/fsui.h
   GNUnet/src/applications/fs/fsui/search.c
   GNUnet/src/applications/fs/fsui/serialize.c
   GNUnet/src/applications/fs/fsui/unindex.c
   GNUnet/src/applications/fs/fsui/upload.c
   GNUnet/src/applications/fs/tools/gnunet-unindex.c
   GNUnet/src/include/gnunet_fsui_lib.h
Log:
more fsui cleanup and bugfixes

Modified: GNUnet/src/applications/fs/fsui/TODO
===================================================================
--- GNUnet/src/applications/fs/fsui/TODO        2006-10-20 03:51:08 UTC (rev 
3501)
+++ GNUnet/src/applications/fs/fsui/TODO        2006-10-20 04:56:42 UTC (rev 
3502)
@@ -15,6 +15,4 @@
 unindex.c:
 - check all events are sent
 
-deserialize.c:
-- deserialize upload and unindex
 

Modified: GNUnet/src/applications/fs/fsui/deserialize.c
===================================================================
--- GNUnet/src/applications/fs/fsui/deserialize.c       2006-10-20 03:51:08 UTC 
(rev 3501)
+++ GNUnet/src/applications/fs/fsui/deserialize.c       2006-10-20 04:56:42 UTC 
(rev 3502)
@@ -24,9 +24,6 @@
  * @brief FSUI functions for reading state from disk
  * @author Christian Grothoff
  * @see serializer.c
- *
- * TODO:
- * - deserialize upload and unindex!
  */
 
 #include "platform.h"
@@ -417,8 +414,6 @@
        }
       }
     }  
-    list->signalTerminate
-      = NO;
     list->ctx
       = ctx;
     
@@ -489,6 +484,9 @@
           0,
           sizeof(FSUI_UploadList));
     READINT(l.state);
+    fixState(&l.state);
+    if (l.state == FSUI_PENDING)
+      l.state = FSUI_ACTIVE;
     READLONG(l.completed);
     READLONG(l.total);
     READLONG(stime);

Modified: GNUnet/src/applications/fs/fsui/download.c
===================================================================
--- GNUnet/src/applications/fs/fsui/download.c  2006-10-20 03:51:08 UTC (rev 
3501)
+++ GNUnet/src/applications/fs/fsui/download.c  2006-10-20 04:56:42 UTC (rev 
3502)
@@ -231,9 +231,9 @@
     event.data.DownloadCompleted.dc.ppos = dl->parent;
     event.data.DownloadCompleted.dc.pcctx = dl->parent->cctx;
     dl->ctx->ecb(dl->ctx->ecbClosure,
-                &event);
+                &event);    
   } else if (dl->state == FSUI_ACTIVE) {
-    /* ECRS error, we did not signal to abort */
+    /* ECRS error */
     dl->state = FSUI_ERROR;
     event.type = FSUI_download_error;
     event.data.DownloadError.message = _("ECRS download failed (see logs)");
@@ -242,9 +242,21 @@
     event.data.DownloadError.dc.ppos = dl->parent;
     event.data.DownloadError.dc.pcctx = dl->parent->cctx;
     dl->ctx->ecb(dl->ctx->ecbClosure,
-                &event);    
+                &event);
+  } else if (dl->state == FSUI_ABORTED) { /* aborted */
+    event.type = FSUI_download_aborted;
+    event.data.DownloadAborted.dc.pos = dl;
+    event.data.DownloadAborted.dc.cctx = dl->cctx;
+    event.data.DownloadAborted.dc.ppos = dl->parent;
+    event.data.DownloadAborted.dc.pcctx = dl->parent->cctx;
+    dl->ctx->ecb(dl->ctx->ecbClosure,
+                &event);      
+  } else {
+    /* else: suspended */
+    GE_ASSERT(NULL, dl->state == FSUI_PENDING);
   }
 
+
   if ( (ret == OK) &&
        (dl->is_recursive) &&
        (dl->is_directory) ) {
@@ -346,22 +358,21 @@
   dl->uri = ECRS_dupUri(uri);
   dl->total = ECRS_fileSize(uri);
   dl->child = NULL;
-  dl->next = parent->child;
-  parent->child = dl;  
-
+  dl->cctx = NULL;
   /* signal start! */
-  event.type = FSUI_download_error;
+  event.type = FSUI_download_started;
   event.data.DownloadStarted.filename = dl->filename;
-  event.data.DownloadStarted.total = ECRS_fileSize(uri);
-  event.data.DownloadStarted.uri = uri;
-  event.data.DownloadStarted.anonymityLevel = anonymityLevel;
+  event.data.DownloadStarted.total = ECRS_fileSize(dl->uri);
+  event.data.DownloadStarted.uri = dl->uri;
+  event.data.DownloadStarted.anonymityLevel = dl->anonymityLevel;
   event.data.DownloadStarted.dc.pos = dl;
-  event.data.DownloadStarted.dc.cctx = dl->cctx;
+  event.data.DownloadStarted.dc.cctx = NULL;
   event.data.DownloadStarted.dc.ppos = dl->parent;
   event.data.DownloadStarted.dc.pcctx = dl->parent->cctx; 
-  dl->cctx = ctx->ecb(ctx->ecbClosure,
-                     &event);
-
+  dl->cctx = dl->ctx->ecb(dl->ctx->ecbClosure,
+                         &event);
+  dl->next = parent->child;
+  parent->child = dl;  
   return dl;
 }
 
@@ -500,7 +511,6 @@
  */
 int FSUI_abortDownload(struct FSUI_Context * ctx,
                       struct FSUI_DownloadList * dl) {
-  FSUI_Event event;
   struct FSUI_DownloadList * c;
 
   GE_ASSERT(ctx->ectx, dl != NULL);
@@ -514,13 +524,6 @@
     return NO;
   dl->state = FSUI_ABORTED;
   PTHREAD_STOP_SLEEP(dl->handle);
-  event.type = FSUI_download_aborted;
-  event.data.DownloadAborted.dc.pos = dl;
-  event.data.DownloadAborted.dc.cctx = dl->cctx;
-  event.data.DownloadAborted.dc.ppos = dl->parent;
-  event.data.DownloadAborted.dc.pcctx = dl->parent->cctx;
-  ctx->ecb(ctx->ecbClosure,
-          &event);
   return OK;
 }
 

Modified: GNUnet/src/applications/fs/fsui/fsui.c
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.c      2006-10-20 03:51:08 UTC (rev 
3501)
+++ GNUnet/src/applications/fs/fsui/fsui.c      2006-10-20 04:56:42 UTC (rev 
3502)
@@ -93,7 +93,7 @@
   FSUI_Event event;
  
   while (ret != NULL) {
-    if (ret->state == FSUI_PENDING) {
+    if (ret->state == FSUI_ACTIVE) {
       event.type = FSUI_upload_resumed;
       event.data.UploadResumed.uc.pos = ret;
       event.data.UploadResumed.uc.cctx = NULL;
@@ -121,8 +121,7 @@
 static void doResumeUploads(struct FSUI_UploadList * ret,
                            FSUI_Context * ctx) {
   while (ret != NULL) {
-    if (ret->state == FSUI_PENDING) {
-      ret->state = FSUI_ACTIVE;
+    if (ret->state == FSUI_ACTIVE) {
       ret->shared->handle = PTHREAD_CREATE(&FSUI_uploadThread,
                                           ret,
                                           128 * 1024);
@@ -434,12 +433,11 @@
         (spos->state == FSUI_ABORTED) ||
         (spos->state == FSUI_ERROR) ||
         (spos->state == FSUI_COMPLETED) ) {
-      spos->signalTerminate = YES;
-      PTHREAD_STOP_SLEEP(spos->handle);
-      PTHREAD_JOIN(spos->handle, &unused);
       if (spos->state == FSUI_ACTIVE)
        spos->state = FSUI_PENDING;
-      else
+      PTHREAD_STOP_SLEEP(spos->handle);
+      PTHREAD_JOIN(spos->handle, &unused);
+      if (spos->state != FSUI_PENDING)
        spos->state++; /* _JOINED */
     }
     spos = spos->next;
@@ -451,12 +449,11 @@
         (xpos->state == FSUI_ABORTED) ||
         (xpos->state == FSUI_ERROR) ||
         (xpos->state == FSUI_COMPLETED) ) {
-      xpos->force_termination = YES;
-      PTHREAD_STOP_SLEEP(xpos->handle);
-      PTHREAD_JOIN(xpos->handle, &unused);    
       if (xpos->state == FSUI_ACTIVE)
        xpos->state = FSUI_PENDING;
-      else
+      PTHREAD_STOP_SLEEP(xpos->handle);
+      PTHREAD_JOIN(xpos->handle, &unused);    
+      if (xpos->state != FSUI_PENDING)
        xpos->state++; /* _JOINED */
     }    
     xpos = xpos->next;    
@@ -470,12 +467,11 @@
         (upos->state == FSUI_COMPLETED) ) {
       /* NOTE: will force transitive termination
         of rest of tree! */
-      upos->shared->force_termination = YES;
-      PTHREAD_STOP_SLEEP(upos->shared->handle);
-      PTHREAD_JOIN(upos->shared->handle, &unused);
       if (upos->state == FSUI_ACTIVE)
        upos->state = FSUI_PENDING;
-      else
+      PTHREAD_STOP_SLEEP(upos->shared->handle);
+      PTHREAD_JOIN(upos->shared->handle, &unused);
+      if (upos->state != FSUI_PENDING)
        upos->state++; /* _JOINED */
     }
     upos = upos->next;

Modified: GNUnet/src/applications/fs/fsui/fsui.h
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.h      2006-10-20 03:51:08 UTC (rev 
3501)
+++ GNUnet/src/applications/fs/fsui/fsui.h      2006-10-20 04:56:42 UTC (rev 
3502)
@@ -143,11 +143,7 @@
 
   ResultPending * unmatchedResultsReceived;
 
-  /**
-   * Set this to YES to signal the search thread that
-   * termination is desired.  Then join on handle.
-   */
-  int signalTerminate;
+  void * cctx;
 
   /**
    * Desired anonymity level for this search
@@ -172,8 +168,6 @@
    */
   unsigned int sizeUnmatchedResultsReceived;
 
-  void * cctx;
-
   FSUI_State state;
 
 } FSUI_SearchList;
@@ -316,8 +310,6 @@
 
   void * cctx;
 
-  int force_termination;
-
   FSUI_State state;
 
 } FSUI_UnindexList;
@@ -355,8 +347,6 @@
 
   int individualKeywords;
 
-  int force_termination;
-
 } FSUI_UploadShared;
 
 /**

Modified: GNUnet/src/applications/fs/fsui/search.c
===================================================================
--- GNUnet/src/applications/fs/fsui/search.c    2006-10-20 03:51:08 UTC (rev 
3501)
+++ GNUnet/src/applications/fs/fsui/search.c    2006-10-20 04:56:42 UTC (rev 
3502)
@@ -231,8 +231,9 @@
   return OK;
 }
 
-static int testTerminate(FSUI_SearchList * pos) {
-  if (pos->signalTerminate == NO)
+static int testTerminate(void * cls) {
+  FSUI_SearchList * pos = cls;
+  if (pos->state == FSUI_ACTIVE)
     return OK;
   return SYSERR;
 }
@@ -242,15 +243,48 @@
  */
 void * FSUI_searchThread(void * cls) {
   FSUI_SearchList * pos = cls;
-  ECRS_search(pos->ctx->ectx,
+  FSUI_Event event;
+  int ret;
+
+  event.type = FSUI_search_started;
+  event.data.SearchStarted.sc.pos = pos;
+  event.data.SearchStarted.sc.cctx = NULL;
+  pos->cctx = pos->ctx->ecb(pos->ctx->ecbClosure,
+                           &event);
+  ret = ECRS_search(pos->ctx->ectx,
              pos->ctx->cfg,
              pos->uri,
              pos->anonymityLevel,
              get_time() + cronYEARS, /* timeout!?*/
              &spcb,
              pos,
-             (ECRS_TestTerminate) &testTerminate,
+             &testTerminate,
              pos);
+  if (ret != OK) {
+    pos->state = FSUI_ERROR;    
+    event.type = FSUI_search_error;
+    event.data.SearchError.sc.pos = pos;
+    event.data.SearchError.sc.cctx = pos->cctx;
+    event.data.SearchError.message = _("Error running search (consult logs).");
+    pos->ctx->ecb(pos->ctx->ecbClosure,
+                 &event);
+  } else if (pos->state == FSUI_ABORTED) {
+    event.type = FSUI_search_aborted;
+    event.data.SearchAborted.sc.pos = pos;
+    event.data.SearchAborted.sc.cctx = pos->cctx;
+    pos->ctx->ecb(pos->ctx->ecbClosure,
+                 &event);
+  } else if (pos->state == FSUI_ACTIVE) {
+    event.type = FSUI_search_completed;
+    event.data.SearchCompleted.sc.pos = pos;
+    event.data.SearchCompleted.sc.cctx = pos->cctx;
+    pos->ctx->ecb(pos->ctx->ecbClosure,
+                 &event);
+  } else {
+    GE_ASSERT(NULL, pos->state == FSUI_PENDING);
+    /* must be suspending */
+  }
+
   return NULL;
 }
 
@@ -267,7 +301,7 @@
   ectx = ctx->ectx;
   MUTEX_LOCK(ctx->lock);
   pos = MALLOC(sizeof(FSUI_SearchList));
-  pos->signalTerminate = NO;
+  pos->state = FSUI_ACTIVE;
   pos->uri = ECRS_dupUri(uri);
   pos->numberOfURIKeys = ECRS_countKeywordsOfUri(uri);
   pos->sizeResultsReceived = 0;
@@ -295,6 +329,16 @@
 }
 
 /**
+ * Abort a search.
+ */
+int FSUI_abortSearch(struct FSUI_Context * ctx,
+                    struct FSUI_SearchList * sl) {
+  sl->state = FSUI_ABORTED;
+  PTHREAD_STOP_SLEEP(sl->handle);
+  return OK;
+}
+
+/**
  * Stop a search.
  */
 int FSUI_stopSearch(struct FSUI_Context * ctx,
@@ -322,10 +366,6 @@
     prev->next = pos->next;
   MUTEX_UNLOCK(ctx->lock);
   pos->next = NULL;
-  pos->signalTerminate = YES;
-  /* send signal to terminate sleep! */
-  GE_ASSERT(ctx->ectx, pos->handle != NULL);
-  PTHREAD_STOP_SLEEP(pos->handle);
   PTHREAD_JOIN(pos->handle,
               &unused);
   ECRS_freeUri(pos->uri);

Modified: GNUnet/src/applications/fs/fsui/serialize.c
===================================================================
--- GNUnet/src/applications/fs/fsui/serialize.c 2006-10-20 03:51:08 UTC (rev 
3501)
+++ GNUnet/src/applications/fs/fsui/serialize.c 2006-10-20 04:56:42 UTC (rev 
3502)
@@ -165,8 +165,6 @@
       continue;
     }
     GE_ASSERT(ctx->ectx,
-             spos->signalTerminate == YES);
-    GE_ASSERT(ctx->ectx,
              ECRS_isKeywordUri(spos->uri));
     WRITEINT(fd, 1);
     WRITEINT(fd, spos->state);

Modified: GNUnet/src/applications/fs/fsui/unindex.c
===================================================================
--- GNUnet/src/applications/fs/fsui/unindex.c   2006-10-20 03:51:08 UTC (rev 
3501)
+++ GNUnet/src/applications/fs/fsui/unindex.c   2006-10-20 04:56:42 UTC (rev 
3502)
@@ -23,11 +23,6 @@
  * @brief unindex functions
  * @author Krista Bennett
  * @author Christian Grothoff
- *
- * TODO:
- * - make sure events are sent for resume/abort
- *   when respective FSUI calls happen!
- *   (initialize cctx!)
  */
 
 #include "platform.h"
@@ -57,7 +52,7 @@
 
 static int tt(void * cls) {
   FSUI_UnindexList * utc = cls;
-  if (utc->force_termination == YES)
+  if (utc->state != FSUI_ACTIVE)
     return SYSERR;
   return OK;
 }
@@ -69,7 +64,21 @@
   FSUI_UnindexList * utc = cls;
   FSUI_Event event;
   int ret;
+  unsigned long long size;
 
+  if (OK != disk_file_size(utc->ctx->ectx,
+                          utc->filename,
+                          &size,
+                          YES)) {
+    GE_BREAK(utc->ctx->ectx, 0);
+    event.data.UnindexCompleted.total = 0;
+  }
+  event.type = FSUI_unindex_started;
+  event.data.UnindexStarted.uc.pos = utc;
+  event.data.UnindexStarted.uc.cctx = NULL;
+  event.data.UnindexStarted.total = size;
+  utc->cctx = utc->ctx->ecb(utc->ctx->ecbClosure,
+                           &event); 
   ret = ECRS_unindexFile(utc->ctx->ectx,
                         utc->ctx->cfg,
                         utc->filename,
@@ -79,20 +88,30 @@
                         utc);
   if (ret == OK) {
     event.type = FSUI_unindex_completed;
-    if (OK != disk_file_size(utc->ctx->ectx,
-                            utc->filename,
-                            &event.data.UnindexCompleted.total,
-                            YES)) {
-      GE_BREAK(utc->ctx->ectx, 0);
-      event.data.UnindexCompleted.total = 0;
-    }
+    event.data.UnindexCompleted.uc.pos = utc;
+    event.data.UnindexCompleted.uc.cctx = utc->cctx;
+    event.data.UnindexCompleted.total = size;
     event.data.UnindexCompleted.filename = utc->filename;
-  } else {
+    utc->ctx->ecb(utc->ctx->ecbClosure,
+                 &event);
+  } else if (utc->state == FSUI_ACTIVE) {
     event.type = FSUI_unindex_error;
+    event.data.UnindexError.uc.pos = utc;
+    event.data.UnindexError.uc.cctx = utc->cctx;
     event.data.UnindexError.message = _("Unindex failed.");
+    utc->ctx->ecb(utc->ctx->ecbClosure,
+                 &event);
+  } else if (utc->state == FSUI_ABORTED) {
+    event.type = FSUI_unindex_aborted;
+    event.data.UnindexAborted.uc.pos = utc;
+    event.data.UnindexAborted.uc.cctx = utc->cctx;
+    utc->ctx->ecb(utc->ctx->ecbClosure,
+                 &event);
+  } else {
+    /* must be suspending */
+    GE_BREAK(NULL, 
+            utc->state == FSUI_PENDING);
   }
-  utc->ctx->ecb(utc->ctx->ecbClosure,
-               &event);
 #if 0
   GE_LOG(utc->ctx->ectx, 
         GE_DEBUG | GE_REQUEST | GE_USER,
@@ -112,8 +131,8 @@
  *  running
  */
 struct FSUI_UnindexList *
-FSUI_unindex(struct FSUI_Context * ctx,
-            const char * filename) {
+FSUI_startUnindex(struct FSUI_Context * ctx,
+                 const char * filename) {
   FSUI_UnindexList * utc;
 
   if (YES == disk_directory_test(ctx->ectx,
@@ -130,7 +149,7 @@
   utc->ctx = ctx;
   utc->filename = STRDUP(filename);
   utc->start_time = get_time();
-  utc->force_termination = NO;
+  utc->state = FSUI_ACTIVE;
   utc->handle = PTHREAD_CREATE(&FSUI_unindexThread,
                               utc,
                               32 * 1024);
@@ -155,11 +174,28 @@
  *
  * @return SYSERR if no such unindex is pending
  */
+int FSUI_abortUnindex(struct FSUI_Context * ctx,
+                     struct FSUI_UnindexList * ul) {
+  if ( (ul->state != FSUI_ACTIVE) &&
+       (ul->state != FSUI_PENDING) )
+    return NO;
+  ul->state = FSUI_ABORTED;
+  PTHREAD_STOP_SLEEP(ul->handle);
+  return OK;
+}
+
+
+/**
+ * Stop a deletion operation.
+ *
+ * @return SYSERR if no such unindex is pending
+ */
 int FSUI_stopUnindex(struct FSUI_Context * ctx,
                     struct FSUI_UnindexList * dl) {
   FSUI_UnindexList * prev;
   struct GE_Context * ectx;
   void * unused;
+  FSUI_Event event;
 
   ectx = ctx->ectx;
   if (dl == NULL) {
@@ -190,10 +226,13 @@
     prev->next = dl->next;
   }
   MUTEX_UNLOCK(ctx->lock);
-  dl->force_termination = YES;
-  PTHREAD_STOP_SLEEP(dl->handle);
   PTHREAD_JOIN(dl->handle,
               &unused);
+  event.type = FSUI_upload_stopped;
+  event.data.UnindexStopped.uc.pos = dl;
+  event.data.UnindexStopped.uc.cctx = dl->cctx;
+  dl->ctx->ecb(dl->ctx->ecbClosure,
+              &event);
   FREE(dl->filename);
   FREE(dl);
   return OK;

Modified: GNUnet/src/applications/fs/fsui/upload.c
===================================================================
--- GNUnet/src/applications/fs/fsui/upload.c    2006-10-20 03:51:08 UTC (rev 
3501)
+++ GNUnet/src/applications/fs/fsui/upload.c    2006-10-20 04:56:42 UTC (rev 
3502)
@@ -65,8 +65,7 @@
 
 static int testTerminate(void * cls) {
   FSUI_UploadList * utc = cls;
-  if ( (utc->shared->force_termination != NO) ||
-       (utc->state != FSUI_ACTIVE) )
+  if (utc->state != FSUI_ACTIVE) 
     return SYSERR;
   return OK;
 }
@@ -172,6 +171,28 @@
                        &event);                
 }
 
+static void signalUploadStarted(struct FSUI_UploadList * utc,
+                               int first_only) {
+  FSUI_Event event;
+  
+  while (utc != NULL) {
+    event.type = FSUI_upload_started;
+    event.data.UploadStarted.uc.pos = utc;
+    event.data.UploadStarted.uc.cctx = utc->cctx;
+    event.data.UploadStarted.uc.ppos = utc->parent;
+    event.data.UploadStarted.uc.pcctx = utc->parent->cctx;
+    event.data.UploadStarted.total = utc->total;
+    event.data.UploadStarted.anonymityLevel = utc->shared->anonymityLevel;
+    event.data.UploadStarted.filename = utc->filename;
+    utc->cctx = utc->shared->ctx->ecb(utc->shared->ctx->ecbClosure,
+                                     &event);
+    signalUploadStarted(utc->child, 0);
+    if (first_only)
+      break;
+    utc = utc->next;
+  }  
+}
+
 /**
  * Thread that does the upload.
  */
@@ -184,17 +205,20 @@
   struct GE_Context * ectx;
   char * filename;
 
+  if (utc->parent == &utc->shared->ctx->activeUploads) {
+    /* top-level call: signal client! */
+    signalUploadStarted(utc, 1);
+  }
   ectx = utc->shared->ctx->ectx;
   GE_ASSERT(ectx, utc->filename != NULL);
   cpos = utc->child;
-  while ( (cpos != NULL) &&
-         (utc->shared->force_termination == NO) ) {
+  while (cpos != NULL) {
     if (cpos->state == FSUI_PENDING)
       FSUI_uploadThread(cpos);
     cpos = cpos->next;
   }
-  if (utc->shared->force_termination == YES)
-    return NULL; /* aborted */
+  if (utc->state != FSUI_ACTIVE)
+    return NULL; /* aborted or suspended */
   if (utc->child != NULL) {
     filename = createDirectoryHelper(ectx,
                                     utc->child,
@@ -208,7 +232,6 @@
     filename = STRDUP(utc->filename);
   }  
   utc->start_time = get_time();
-  utc->state = FSUI_ACTIVE;
     
   ret = ECRS_uploadFile(utc->shared->ctx->ectx,
                        utc->shared->ctx->cfg,
@@ -223,8 +246,21 @@
                        utc,
                        &utc->uri);
   if (ret != OK) {
-    signalError(utc,
-               _("Upload failed (consult logs)."));
+    if (utc->state == FSUI_ACTIVE) {
+      signalError(utc,
+                 _("Upload failed (consult logs)."));
+    } else if (utc->state == FSUI_ABORTED) {
+      event.type = FSUI_upload_aborted;
+      event.data.UploadAborted.uc.pos = utc;
+      event.data.UploadAborted.uc.cctx = utc->cctx;
+      event.data.UploadAborted.uc.ppos = utc->parent;
+      event.data.UploadAborted.uc.pcctx = utc->parent->cctx;
+      utc->shared->ctx->ecb(utc->shared->ctx->ecbClosure,
+                           &event); 
+    } else {
+      /* must be suspended */
+      GE_BREAK(NULL, utc->state == FSUI_PENDING);
+    }
     if (utc->child != NULL) 
       UNLINK(filename);
     FREE(filename);
@@ -275,7 +311,7 @@
   event.data.UploadCompleted.filename = utc->filename;
   event.data.UploadCompleted.uri = utc->uri;
   utc->shared->ctx->ecb(utc->shared->ctx->ecbClosure,
-               &event);                
+                       &event);                
   if (utc->child != NULL) 
     UNLINK(filename);
   FREE(filename);
@@ -358,7 +394,7 @@
   utc->parent = parent;
   utc->uri = NULL;
   utc->cctx = NULL; /* to be set later */
-  utc->state = FSUI_PENDING;
+  utc->state = FSUI_ACTIVE;
   if (YES == disk_file_test(shared->ctx->ectx,
                            filename)) {
     /* add this file */
@@ -400,28 +436,6 @@
   return utc;
 }
 
-static void signalUploadStarted(struct FSUI_UploadList * utc,
-                               int first_only) {
-  FSUI_Event event;
-  
-  while (utc != NULL) {
-    event.type = FSUI_upload_started;
-    event.data.UploadStarted.uc.pos = utc;
-    event.data.UploadStarted.uc.cctx = utc->cctx;
-    event.data.UploadStarted.uc.ppos = utc->parent;
-    event.data.UploadStarted.uc.pcctx = utc->parent->cctx;
-    event.data.UploadStarted.total = utc->total;
-    event.data.UploadStarted.anonymityLevel = utc->shared->anonymityLevel;
-    event.data.UploadStarted.filename = utc->filename;
-    utc->cctx = utc->shared->ctx->ecb(utc->shared->ctx->ecbClosure,
-                                     &event);
-    signalUploadStarted(utc->child, 0);
-    if (first_only)
-      break;
-    utc = utc->next;
-  }  
-}
-
 static void signalUploadStopped(struct FSUI_UploadList * ul,
                                int first_only) {
   FSUI_Event event;
@@ -503,7 +517,6 @@
   shared->anonymityLevel = anonymityLevel;
   shared->priority = priority;
   shared->individualKeywords = individualKeywords;
-  shared->force_termination = NO;
   ul = addUploads(shared,
                  filename,
                  keyUri,
@@ -520,7 +533,6 @@
     freeShared(shared);
     return NULL;
   }
-  signalUploadStarted(ul, 1);
   return ul;
 }
 
@@ -536,27 +548,18 @@
 int FSUI_abortUpload(struct FSUI_Context * ctx,
                     struct FSUI_UploadList * ul) {
   FSUI_UploadList * c;
-  FSUI_Event event;
   
   GE_ASSERT(ctx->ectx, ul != NULL);
   if ( (ul->state != FSUI_ACTIVE) &&
        (ul->state != FSUI_PENDING) )
     return NO;
   ul->state = FSUI_ABORTED;
-  ul->shared->force_termination = YES;
   c = ul->child;
   while (c != NULL) {
     FSUI_abortUpload(ctx, c);
     c = c->next;
   }    
   PTHREAD_STOP_SLEEP(ul->shared->handle);
-  event.type = FSUI_upload_aborted;
-  event.data.UploadAborted.uc.pos = ul;
-  event.data.UploadAborted.uc.cctx = ul->cctx;
-  event.data.UploadAborted.uc.ppos = ul->parent;
-  event.data.UploadAborted.uc.pcctx = ul->parent->cctx;
-  ctx->ecb(ctx->ecbClosure,
-          &event);
   return OK;
 }
 

Modified: GNUnet/src/applications/fs/tools/gnunet-unindex.c
===================================================================
--- GNUnet/src/applications/fs/tools/gnunet-unindex.c   2006-10-20 03:51:08 UTC 
(rev 3501)
+++ GNUnet/src/applications/fs/tools/gnunet-unindex.c   2006-10-20 04:56:42 UTC 
(rev 3502)
@@ -25,11 +25,10 @@
  * @author Krista Bennett
  * @author James Blackwell
  * @author Igor Wronsky
- *
- * TODO: fix message handling, signal handling
  */
 
 #include "platform.h"
+#include "gnunet_directories.h"
 #include "gnunet_fsui_lib.h"
 #include "gnunet_util_config_impl.h"
 #include "gnunet_util_error_loggers.h"
@@ -38,13 +37,11 @@
 
 static struct GC_Configuration * cfg;
 
-static struct SEMAPHORE * exitSignal;
-
 static cron_t start_time;
 
 static int errorCode;
 
-static char * cfgFilename;
+static char * cfgFilename = DEFAULT_CLIENT_CONFIG_FILE;
 
 /**
  * Print progess message.
@@ -77,13 +74,14 @@
       ? (double) (-1.0)
       : (double) (event->data.UnindexCompleted.total / 1024.0 * cronSECONDS / 
delta));
     }
-    SEMAPHORE_UP(exitSignal);
+    errorCode = 0;
+    GNUNET_SHUTDOWN_INITIATE();
     break;
   case FSUI_unindex_error:
     printf(_("\nError unindexing file: %s\n"),
           event->data.UnindexError.message);
-    errorCode = 1;
-    SEMAPHORE_UP(exitSignal); /* always exit main? */
+    errorCode = 3;
+    GNUNET_SHUTDOWN_INITIATE();
     break;
   default:
     GE_BREAK(ectx, 0);
@@ -149,14 +147,19 @@
     GE_free_context(ectx);
     return -1;
   }
+  if (OK != GC_parse_configuration(cfg,
+                                  cfgFilename)) {  
+    GC_free(cfg);
+    GE_free_context(ectx);
+    return -1;
+  }
   GC_get_configuration_value_number(cfg,
-                                   "GNUNET-INSERT",
+                                   "GNUNET",
                                    "VERBOSE",
                                    0,
                                    9999,
                                    0,
                                    &verbose);
-  exitSignal = SEMAPHORE_CREATE(0);
   /* fundamental init */
   ctx = FSUI_start(ectx,
                   cfg,
@@ -165,24 +168,25 @@
                   NO,
                   &printstatus,
                   &verbose);
+  errorCode = 1;
   start_time = get_time();
   filename = string_expandFileName(ectx,
                                   argv[i]);
-  ul = FSUI_unindex(ctx,
-                   filename);
+  ul = FSUI_startUnindex(ctx,
+                        filename);
   if (ul == NULL) {
     printf(_("`%s' failed.  Is `%s' a file?\n"),
           "FSUI_unindex",
           filename);
-    errorCode = 1;
+    errorCode = 2;
   } else {
-    /* wait for completion */
-    SEMAPHORE_DOWN(exitSignal, YES);
+    GNUNET_SHUTDOWN_WAITFOR();
+    if (errorCode != 0)
+      FSUI_abortUnindex(ctx, ul);
     FSUI_stopUnindex(ctx, ul);
   }
   FREE(filename);
   FSUI_stop(ctx);
-  SEMAPHORE_DESTROY(exitSignal);
   GC_free(cfg);
   GE_free_context(ectx);
   return errorCode;

Modified: GNUnet/src/include/gnunet_fsui_lib.h
===================================================================
--- GNUnet/src/include/gnunet_fsui_lib.h        2006-10-20 03:51:08 UTC (rev 
3501)
+++ GNUnet/src/include/gnunet_fsui_lib.h        2006-10-20 04:56:42 UTC (rev 
3502)
@@ -870,13 +870,12 @@
  * @return NULL on error
  */
 struct FSUI_UnindexList *
-FSUI_unindex(struct FSUI_Context * ctx,
-            const char * filename);
+FSUI_startUnindex(struct FSUI_Context * ctx,
+                 const char * filename);
 
 
 /**
- * Abort an unindex operation.  If the context is for a recursive
- * upload, all sub-uploads will also be aborted.
+ * Abort an unindex operation.
  *
  * @return SYSERR on error
  */
@@ -885,8 +884,7 @@
 
 
 /**
- * Stop an unindex operation.  If the context is for a recursive
- * upload, all sub-uploads will also be stopped.
+ * Stop an unindex operation. 
  *
  * @return SYSERR on error
  */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]