From 8c0343d45f72b3ec93eb93a4101a7632aa90ab6a Mon Sep 17 00:00:00 2001
From: edgrif <edgrif>
Date: Fri, 25 Jan 2008 15:49:40 +0000
Subject: [PATCH] add option to allow blixem processes to be left running after
 view dies.

---
 src/zmapView/zmapView.c           | 33 +++++++++++++++----------
 src/zmapView/zmapViewCallBlixem.c | 40 ++++++++++++++++++++++++++-----
 src/zmapView/zmapView_P.h         | 13 +++++-----
 3 files changed, 62 insertions(+), 24 deletions(-)

diff --git a/src/zmapView/zmapView.c b/src/zmapView/zmapView.c
index 236b82c27..5dda50062 100755
--- a/src/zmapView/zmapView.c
+++ b/src/zmapView/zmapView.c
@@ -25,9 +25,9 @@
  * Description: 
  * Exported functions: See ZMap/zmapView.h
  * HISTORY:
- * Last edited: Nov 19 13:48 2007 (rds)
+ * Last edited: Jan 25 15:37 2008 (edgrif)
  * Created: Thu May 13 15:28:26 2004 (edgrif)
- * CVS info:   $Id: zmapView.c,v 1.126 2007-11-22 12:48:34 rds Exp $
+ * CVS info:   $Id: zmapView.c,v 1.127 2008-01-25 15:49:40 edgrif Exp $
  *-------------------------------------------------------------------
  */
 
@@ -1395,6 +1395,9 @@ static ZMapView createZMapView(GtkWidget *xremote_widget, char *view_name, GList
 
   zmap_view->revcomped_features = FALSE ;
 
+  zmap_view->kill_blixems = TRUE ;
+
+
   return zmap_view ;
 }
 
@@ -1445,17 +1448,22 @@ static void killAllSpawned(ZMapView zmap_view)
   GPid pid;
   GList *processes = zmap_view->spawned_processes;
 
-  while(processes)
+  if (zmap_view->kill_blixems)
     {
-      pid = GPOINTER_TO_INT(processes->data);
-      g_spawn_close_pid(pid);
-      kill(pid, 9);
-      processes = processes->next;
+      while (processes)
+	{
+	  pid = GPOINTER_TO_INT(processes->data);
+	  g_spawn_close_pid(pid);
+	  kill(pid, 9);
+	  processes = processes->next;
+	}
     }
 
-  if(zmap_view->spawned_processes)
-    g_list_free(zmap_view->spawned_processes);
-  zmap_view->spawned_processes = NULL ;
+  if (zmap_view->spawned_processes)
+    {
+      g_list_free(zmap_view->spawned_processes);
+      zmap_view->spawned_processes = NULL ;
+    }
 
   return ;
 }
@@ -1633,7 +1641,8 @@ static gboolean checkStateConnections(ZMapView zmap_view)
 			    /* Got the sequences so launch blixem. */
 			    if ((status = zmapViewCallBlixem(zmap_view,
 							     get_sequence->orig_feature, get_sequence->sequences,
-							     &blixem_pid)))
+							     &blixem_pid,
+							     &(zmap_view->kill_blixems))))
 			     zmap_view->spawned_processes = g_list_append(zmap_view->spawned_processes,
 									  GINT_TO_POINTER(blixem_pid)) ;
 
@@ -2335,7 +2344,7 @@ static void commandCB(ZMapWindow window, void *caller_data, void *window_data)
 	  {
 	    GPid blixem_pid ;
 
-	    if ((status = zmapViewCallBlixem(view, align_cmd->feature, NULL, &blixem_pid)))
+	    if ((status = zmapViewCallBlixem(view, align_cmd->feature, NULL, &blixem_pid, &(view->kill_blixems))))
 	      view->spawned_processes = g_list_append(view->spawned_processes, GINT_TO_POINTER(blixem_pid)) ;
 	  }
 
diff --git a/src/zmapView/zmapViewCallBlixem.c b/src/zmapView/zmapViewCallBlixem.c
index 9742a0669..0996c827f 100755
--- a/src/zmapView/zmapViewCallBlixem.c
+++ b/src/zmapView/zmapViewCallBlixem.c
@@ -29,9 +29,9 @@
  * Exported functions: see zmapView_P.h
  *              
  * HISTORY:
- * Last edited: Nov 12 13:48 2007 (rds)
+ * Last edited: Jan 25 15:34 2008 (edgrif)
  * Created: Thu Jun 28 18:10:08 2007 (edgrif)
- * CVS info:   $Id: zmapViewCallBlixem.c,v 1.5 2007-11-12 13:49:18 rds Exp $
+ * CVS info:   $Id: zmapViewCallBlixem.c,v 1.6 2008-01-25 15:49:40 edgrif Exp $
  *-------------------------------------------------------------------
  */
 
@@ -70,6 +70,8 @@ enum
 typedef struct BlixemDataStruct 
 {
   /* user preferences for blixem */
+  gboolean kill_on_exit ;				    /* TRUE => remove this blixem on
+							       program exit (default). */
   gchar         *netid;                               /* eg pubseq */
   int            port;                                /* eg 22100  */
   gchar         *script;                              /* script to call blixem standalone */
@@ -128,6 +130,9 @@ typedef struct
 {
   /* User configurable */
   gboolean init ;					    /* TRUE when struct has been initialised. */
+
+  gboolean kill_on_exit ;				    /* TRUE => remove this blixem on
+							       program exit (default). */
   gchar         *netid ;                               /* eg pubseq */
   int           port ;                                /* eg 22100  */
   gchar         *script ;                              /* script to call blixem standalone */
@@ -283,7 +288,8 @@ gboolean zmapViewBlixemLocalSequences(ZMapView view, ZMapFeature feature, GList
  * The function returns TRUE if blixem was successfully launched and also returns the pid of the blixem
  * process so that the blixems can be cleared up when the view exits.
  *  */
-gboolean zmapViewCallBlixem(ZMapView view, ZMapFeature feature, GList *local_sequences, GPid *child_pid)
+gboolean zmapViewCallBlixem(ZMapView view, ZMapFeature feature, GList *local_sequences,
+			    GPid *child_pid, gboolean *kill_on_exit)
 {
   gboolean status = TRUE ;
   char *argv[BLX_ARGV_ARGC + 1] = {NULL} ;
@@ -332,8 +338,11 @@ gboolean zmapViewCallBlixem(ZMapView view, ZMapFeature feature, GList *local_seq
       else
         zMapLogMessage("Blixem process spawned successfully. PID = '%d'", spawned_pid);
 
-      if(status && child_pid)
-        *child_pid = spawned_pid;
+      if (status && child_pid)
+        *child_pid = spawned_pid ;
+
+      if (kill_on_exit)
+	*kill_on_exit = blixem_data.kill_on_exit ;
     }
 
   freeBlixemData(&blixem_data) ;
@@ -450,6 +459,7 @@ static void setPrefs(BlixemConfigData curr_prefs, blixemData blixem_data)
   blixem_data->scope = curr_prefs->scope ;
   blixem_data->homolmax = curr_prefs->homolmax ;
   blixem_data->keep_tmpfiles = curr_prefs->keep_tmpfiles ;
+  blixem_data->kill_on_exit = curr_prefs->kill_on_exit ;
 
   if (blixem_data->dna_sets)
     {
@@ -487,10 +497,17 @@ static gboolean getUserPrefs(BlixemConfigData prefs)
 					      {"scope"     , ZMAPCONFIG_INT   , {NULL}},
 					      {"homol_max" , ZMAPCONFIG_INT   , {NULL}},
 					      {"keep_tempfiles", ZMAPCONFIG_BOOL, {NULL}},
+					      {"kill_on_exit", ZMAPCONFIG_BOOL, {NULL}},
 					      {"dna_featuresets", ZMAPCONFIG_STRING, {NULL}},
 					      {"protein_featuresets", ZMAPCONFIG_STRING, {NULL}},
 					      {"transcript_featuresets", ZMAPCONFIG_STRING, {NULL}},
 					      {NULL, -1, {NULL}}} ;
+
+
+  /* Set defaults... */
+  zMapConfigGetStructBool(elements, "kill_on_exit") = TRUE ;
+
+
   if ((config = zMapConfigCreate()))
     {
       char *dnaset_string, *proteinset_string, *transcriptset_string ;
@@ -524,6 +541,8 @@ static gboolean getUserPrefs(BlixemConfigData prefs)
 	    prefs->transcript_sets = zMapFeatureString2QuarkList(transcriptset_string) ;
 
 	  prefs->keep_tmpfiles = zMapConfigGetElementBool(next, "keep_tempfiles") ;
+
+	  prefs->kill_on_exit = zMapConfigGetElementBool(next, "kill_on_exit") ;
 	  
 	  zMapConfigDeleteStanzaSet(list) ;		    /* Not needed anymore. */
 	}
@@ -619,7 +638,7 @@ static gboolean makeTmpfiles(blixemData blixem_data)
   char       *path;
   char       *login;
 
-  if ((login = g_get_user_name()))
+  if ((login = (char *)g_get_user_name()))
     {
       path = g_strdup_printf("/tmp/%s_ZMAP_BLIXEM/", login);
     }
@@ -1592,6 +1611,10 @@ static ZMapGuiNotebookChapter makeChapter(ZMapGuiNotebook note_book_parent)
 					   ZMAPGUI_NOTEBOOK_TAGVALUE_CHECKBOX,
 					   "bool", blixem_config_curr_G.keep_tmpfiles) ;
 
+  tagvalue = zMapGUINotebookCreateTagValue(paragraph, "Kill Blixem on Exit",
+					   ZMAPGUI_NOTEBOOK_TAGVALUE_CHECKBOX,
+					   "bool", blixem_config_curr_G.kill_on_exit) ;
+
   return chapter ;
 }
 
@@ -1665,6 +1688,11 @@ static void readChapter(ZMapGuiNotebookChapter chapter)
 	  blixem_config_curr_G.keep_tmpfiles = bool_value ;
 	}
 
+      if (zMapGUINotebookGetTagValue(page, "Kill Blixem on Exit", "bool", &bool_value))
+	{
+	  blixem_config_curr_G.kill_on_exit = bool_value ;
+	}
+
     }
 
 
diff --git a/src/zmapView/zmapView_P.h b/src/zmapView/zmapView_P.h
index d5c115950..068bb95e8 100755
--- a/src/zmapView/zmapView_P.h
+++ b/src/zmapView/zmapView_P.h
@@ -24,9 +24,9 @@
  *
  * Description: 
  * HISTORY:
- * Last edited: Jul 30 12:23 2007 (rds)
+ * Last edited: Jan 25 15:36 2008 (edgrif)
  * Created: Thu May 13 15:06:21 2004 (edgrif)
- * CVS info:   $Id: zmapView_P.h,v 1.31 2007-07-30 11:23:40 rds Exp $
+ * CVS info:   $Id: zmapView_P.h,v 1.32 2008-01-25 15:49:40 edgrif Exp $
  *-------------------------------------------------------------------
  */
 #ifndef ZMAP_VIEW_P_H
@@ -144,6 +144,9 @@ typedef struct _ZMapViewStruct
 
   GList *navigator_set_names;
   
+  /* view spawns blixem processes when requested, kill_blixems flag controls whether they are
+   * killed when view dies (default is TRUE). */
+  gboolean kill_blixems ;
   GList *spawned_processes;
 
   GHashTable *cwh_hash;
@@ -155,19 +158,17 @@ void zmapViewBusy(ZMapView zmap_view, gboolean busy) ;
 gboolean zmapAnyConnBusy(GList *connection_list) ;
 char *zmapViewGetStatusAsStr(ZMapViewState state) ;
 gboolean zmapViewBlixemLocalSequences(ZMapView view, ZMapFeature feature, GList **local_sequences_out) ;
-gboolean zmapViewCallBlixem(ZMapView view, ZMapFeature feature, GList *local_sequences, GPid *child_pid) ;
-
+gboolean zmapViewCallBlixem(ZMapView view, ZMapFeature feature, GList *local_sequences,
+			    GPid *child_pid, gboolean *kill_on_exit) ;
 ZMapFeatureContext zmapViewMergeInContext(ZMapView view, ZMapFeatureContext context);
 gboolean zmapViewDrawDiffContext(ZMapView view, ZMapFeatureContext *diff_context);
 void zmapViewEraseFromContext(ZMapView replace_me, ZMapFeatureContext context_inout);
-
 void zmapViewSetupXRemote(ZMapView view, GtkWidget *widget);
 gboolean zmapViewRemoteSendCommand(ZMapView view,
                                    char *action, GArray *xml_events,
                                    ZMapXMLObjTagFunctions start_handlers,
                                    ZMapXMLObjTagFunctions end_handlers,
                                    gpointer *handler_data);
-
 /* Context Window Hash (CWH) for the correct timing of the call to zMapFeatureContextDestroy */
 GHashTable *zmapViewCWHHashCreate(void);
 void zmapViewCWHSetList(GHashTable *hash, ZMapFeatureContext context, GList *list);
-- 
GitLab