gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r186 - in GNUnet: . src/applications/fs/fsui src/include


From: grothoff
Subject: [GNUnet-SVN] r186 - in GNUnet: . src/applications/fs/fsui src/include
Date: Sat, 5 Feb 2005 07:36:31 -0800 (PST)

Author: grothoff
Date: 2005-02-05 07:36:31 -0800 (Sat, 05 Feb 2005)
New Revision: 186

Modified:
   GNUnet/src/applications/fs/fsui/fsui.c
   GNUnet/src/applications/fs/fsui/fsui.h
   GNUnet/src/include/gnunet_fsui_lib.h
   GNUnet/todo
Log:
implementing FSUI shutdown

Modified: GNUnet/src/applications/fs/fsui/fsui.c
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.c      2005-02-05 14:31:21 UTC (rev 
185)
+++ GNUnet/src/applications/fs/fsui/fsui.c      2005-02-05 15:36:31 UTC (rev 
186)
@@ -37,10 +37,28 @@
  */
 struct FSUI_Context * FSUI_start(FSUI_EventCallback cb,
                                 void * closure) {
-  FSUI_Context * ret;
+  FSUI_Context * ret;  
+  char * fn;
+  char * gh;
 
   ret = MALLOC(sizeof(FSUI_Context));
   memset(ret, 0, sizeof(FSUI_Context));
+  gh = getConfigurationString("",
+                             "GNUNET_HOME");
+  fn = MALLOC(strlen(gh) + strlen("fsui-lock") + 2);
+  strcpy(fn, gh);
+  FREE(gh);
+  strcat(fn, DIR_SEPARATOR_STR);
+  strcat(fn, "fsui-lock");
+  ret->ipc = IPC_SEMAPHORE_NEW(fn,
+                              1);
+  LOG(LOG_INFO,
+      "Getting IPC lock for FSUI (%s).\n",
+      fn);
+  FREE(fn);
+  IPC_SEMAPHORE_DOWN(ret->ipc);
+  LOG(LOG_INFO,
+      "Aquired IPC lock.\n");
   MUTEX_CREATE_RECURSIVE(&ret->lock);
   ret->ecb = cb;
   ret->ecbClosure = closure;
@@ -48,13 +66,90 @@
   return ret;
 }
 
+static void freeDownloadList(FSUI_DownloadList * list) {
+  FSUI_DownloadList * dpos;
+  int i;
+  void * unused;
+
+  while (list != NULL) {
+    dpos = list;
+    list = dpos->next;
+    freeDownloadList(dpos->subDownloads);
+    freeDownloadList(dpos->subDownloadsNext);
+    dpos->signalTerminate = YES;
+    PTHREAD_JOIN(&dpos->handle, &unused);
+    ECRS_freeUri(dpos->uri);
+    FREE(dpos->filename);
+    for (i=dpos->completedDownloadsCount-1;i>=0;i--)
+      ECRS_freeUri(dpos->completedDownloads[i]);    
+    GROW(dpos->completedDownloads,
+        dpos->completedDownloadsCount,
+        0);
+    FREE(dpos);
+  }
+}
+
 /**
  * Stop all processes under FSUI control (serialize state, continue
  * later if possible).
  */
 void FSUI_stop(struct FSUI_Context * ctx) {
+  FSUI_ThreadList * tpos;
+  FSUI_SearchList * spos;
+  void * unused;
+  int i;
+
+  LOG(LOG_INFO,
+      "FSUI shutdown.  This may take a while.\n");
+  while (ctx->activeThreads != NULL) {
+    tpos = ctx->activeThreads;
+    ctx->activeThreads = tpos->next;
+    PTHREAD_JOIN(&tpos->handle, &unused);
+    FREE(tpos);
+  }
+  
+  while (ctx->activeSearches != NULL) {
+    spos = ctx->activeSearches;
+    ctx->activeSearches = spos->next;
+
+    spos->signalTerminate = YES;
+    PTHREAD_JOIN(&spos->handle, &unused);
+    /* FIXME: serialize spos state! */
+
+    ECRS_freeUri(spos->uri);
+    for (i=spos->sizeResultsReceived-1;i>=0;i--) {
+      ECRS_FileInfo * fi;
+      fi = &spos->resultsReceived[i];
+      ECRS_freeMetaData(fi->meta);
+      ECRS_freeUri(fi->uri);
+    }
+    GROW(spos->resultsReceived,
+        spos->sizeResultsReceived,
+        0);
+    for (i=spos->sizeUnmatchedResultsReceived-1;i>=0;i--) {
+      ResultPending * rp = &spos->unmatchedResultsReceived[i];
+      GROW(rp->matchingKeys,
+          rp->matchingKeyCount,
+          0);
+      ECRS_freeMetaData(rp->fi.meta);
+      ECRS_freeUri(rp->fi.uri);
+    }
+    GROW(spos->unmatchedResultsReceived,
+        spos->sizeUnmatchedResultsReceived,
+        0);
+    FREE(spos);
+  }
+
+  /* FIXME: serialize dpos state! */
+  freeDownloadList(ctx->activeDownloads);
+  ctx->activeDownloads = NULL;
+
+  IPC_SEMAPHORE_UP(ctx->ipc);
+  IPC_SEMAPHORE_FREE(ctx->ipc);
   MUTEX_DESTROY(&ctx->lock);
   FREE(ctx);
+  LOG(LOG_INFO,
+      "FSUI shutdown complete.\n");
 }
 
 /**
@@ -134,8 +229,6 @@
       dpos = dpos->next;
     }
   }
-
-
   MUTEX_UNLOCK(&ctx->lock);
 }
 

Modified: GNUnet/src/applications/fs/fsui/fsui.h
===================================================================
--- GNUnet/src/applications/fs/fsui/fsui.h      2005-02-05 14:31:21 UTC (rev 
185)
+++ GNUnet/src/applications/fs/fsui/fsui.h      2005-02-05 15:36:31 UTC (rev 
186)
@@ -222,6 +222,8 @@
  */
 typedef struct FSUI_Context {
 
+  IPC_Semaphore * ipc;
+
   /**
    * Lock to synchronize access to the FSUI Context.
    */

Modified: GNUnet/src/include/gnunet_fsui_lib.h
===================================================================
--- GNUnet/src/include/gnunet_fsui_lib.h        2005-02-05 14:31:21 UTC (rev 
185)
+++ GNUnet/src/include/gnunet_fsui_lib.h        2005-02-05 15:36:31 UTC (rev 
186)
@@ -324,7 +324,12 @@
 /**
  * Start FSUI manager.  Use the given progress callback to notify the
  * UI about events.  Start processing pending activities that were
- * running when FSUI_stop was called previously.
+ * running when FSUI_stop was called previously.  There can only be
+ * one FSUI_Context open PER USER.  The second time anyone tries to
+ * open an FSUI_Context, FSUI_start will BLOCK until the first
+ * FSUI_Context is released (with FSUI_stop).  This may seem totally
+ * awful, but it is the only way to ensure that everything stays
+ * consistent.
  *
  * @return NULL on error
  */

Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2005-02-05 14:31:21 UTC (rev 185)
+++ GNUnet/todo 2005-02-05 15:36:31 UTC (rev 186)
@@ -9,7 +9,6 @@
 
 0.7.0pre0 [3'05] (aka "pre-preview"):
 - Missing Features:
-  * fsui core (persistence, shutdown, multiple FSUIs) [ difficult ]
   * mysql sqstore implementation iterator problem (Igor?)
 - Need testing:
   * ECRS-directories (build, iterate)
@@ -19,6 +18,8 @@
   * gnunet-search
 
 0.7.0pre1 [4'05] (aka "preview"):
+- topology: do aggressive bootstrap on first start (Christian) [ easy ]
+- ecrs-unindex: code cleanup [ easy ]
 - sqlite sqstore implementation does not compile yet (Nils)
 - gnunet-search: 
   * dump directory with search results [ easy ]
@@ -32,10 +33,9 @@
 
 0.7.0 [5'05] (aka "compatibility? what's that?"):
 - Missing Features:
-  * topology: do aggressive bootstrap on first start (Christian) [ easy ]
-  * ecrs-unindex: code cleanup [ easy ]
   * configure.ac: flags for mysql, gmp, libgcrypt should ONLY be passed when
     linking the respective modules / libraries (gnunet_util, sqstore_mysql) [ 
tricky ]
+  * fsui core (persistence) [ difficult ]
 - Features removed but to be revived:
   * fsui download: limit parallelism (currently unlimited, old gnunet-download 
allowed
     user to specify maximum amount of parallelism) [ tricky ]





reply via email to

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