From 70ab12c54c3c95a5d169968e86d070c8e8f22b21 Mon Sep 17 00:00:00 2001
From: edgrif <edgrif>
Date: Fri, 23 Jan 2004 13:27:48 +0000
Subject: [PATCH] update for multiple threads per zmap

---
 src/makefile                    |   2 +-
 src/zmapApp/makefile            |  17 +-
 src/zmapApp/zmapApp_P.h         |  19 ++-
 src/zmapApp/zmapAppconnect.c    |  52 ++----
 src/zmapApp/zmapAppmanage.c     |  45 ++++-
 src/zmapApp/zmapAppwindow.c     |  48 ++++--
 src/zmapConfig/README           |  10 +-
 src/zmapConfig/zmapConfig.c     |  37 ++--
 src/zmapControl/zmapControl.c   | 289 ++++++++++++++++++++++++++------
 src/zmapManager/zmapManager.c   |  95 +++--------
 src/zmapManager/zmapManager_P.h |  25 +--
 src/zmapServer/makefile         |   2 +-
 src/zmapThreads/makefile        |   2 +-
 src/zmapThreads/zmapConn.c      |  13 +-
 src/zmapThreads/zmapConn_P.h    |   5 +-
 src/zmapThreads/zmapConnutils.c |  53 +++++-
 src/zmapWindow/zmapWindow.c     |  18 +-
 src/zmapWindow/zmapWindow_P.h   |   6 +-
 18 files changed, 480 insertions(+), 258 deletions(-)

diff --git a/src/makefile b/src/makefile
index 8e8b3e3a0..0d268b71b 100755
--- a/src/makefile
+++ b/src/makefile
@@ -5,7 +5,7 @@
 #
 
 APP_DIR = zmapApp
-MAKE_DIRS = $(APP_DIR) zmapAppmanager zmapControl zmapserver zmapthreads zmaputils zmapwindow
+MAKE_DIRS = $(APP_DIR) zmapAppmanager zmapConfig zmapControl zmapserver zmapthreads zmaputils zmapwindow zmapNoThreads
 
 
 all: makebindir libs zmap 
diff --git a/src/zmapApp/makefile b/src/zmapApp/makefile
index 9fa207e13..4f1434976 100755
--- a/src/zmapApp/makefile
+++ b/src/zmapApp/makefile
@@ -32,23 +32,24 @@ include $(MAKE_DIR)/build.make
 # Make the application programs themselves.
 
 # ZMAP library...
-ZMAP_LIB_FLAGS = -L$(BINDIR) -lZMapApp -lZMap
+ZMAP_LIB_FLAGS = -L$(BINDIR) -lZMapApp -lZMap -lZMapThr
 
-# Ace-Conn library...
+# Ace-Conn library...This is a bit of hack really...the ACEDB_MACHINE stuff should be
+# in a separate subdir as we don't yet know what server we will be contacting....
 ACECONN_DIR = $(HOME)/acedb/CODE/Ace-Conn
 ACECONN_INCL_DIR = $(ACECONN_DIR)
-ACECONN_LIB_DIR = $(ACECONN_DIR)/bin.ALPHA_5
+ACECONN_LIB_DIR = $(ACECONN_DIR)/bin.$(ACEDB_MACHINE)
 ACECONN_LIB_FLAGS = -L$(ACECONN_LIB_DIR) -lAceConn -lmd5
 
 
 
-zmap: $(APP_CC_MAIN_OBJ) $(ZMAPAPP_LIB) $(ZMAP_LIB)
-	$(CC)  -g -pthread  -o $(BINDIR)/$@ `$(PACKAGE_CONFIG) --libs glib-2.0 gtk+-2.0` $(BINDIR)/zmapAppmain_c.o $(ZMAP_LIB_FLAGS)  $(ACECONN_LIB_FLAGS)
+zmap: $(APP_CC_MAIN_OBJ) $(ZMAPAPP_LIB) $(ZMAP_LIB) $(ZMAPTHR_LIB)
+	$(CC)  -g -pthread  -o $(BINDIR)/$@ $(BINDIR)/zmapAppmain_c.o $(LDFLAGS) $(ZMAP_LIB_FLAGS)  $(ACECONN_LIB_FLAGS) $(GNOME_LIBS) $(GTK_LIBS)
 	@echo 'zmap (C version) make...'
 
-#	$(CC)  -g -pthread  -o $(BINDIR)/$@ `gtk-config --libs` $(BINDIR)/zmapAppmain_c.o $(ZMAP_LIB_FLAGS)  $(ACECONN_LIB_FLAGS)
+#	$(CC)  -g -pthread  -o $(BINDIR)/$@ `gtk-config --libs` $(BINDIR)/zmapAppmain_c.o $(ZMAP_LIB_FLAGS) $(ACECONN_LIB_FLAGS) $(GNOME_LIBS) $(GTK_LIBS)
 #	@echo 'zmap (C version) make...'
 
-zmapC: $(APP_CCC_MAIN_OBJ) $(ZMAPAPP_LIB) $(ZMAP_LIB)
-	$(CCC)  -g -pthread  -o $(BINDIR)/$@ `gtk-config --libs` $(BINDIR)/zmapAppmain_c.o $(ZMAP_LIB_FLAGS)  $(ACECONN_LIB_FLAGS)
+zmapC: $(APP_CCC_MAIN_OBJ) $(ZMAPAPP_LIB) $(ZMAP_LIB) $(ZMAPTHR_LIB)
+	$(CCC)  -g -pthread  -o $(BINDIR)/$@ $(BINDIR)/zmapAppmain_c.o $(LDFLAGS) $(ZMAP_LIB_FLAGS) $(ACECONN_LIB_FLAGS) $(GNOME_LIBS) $(GTK_LIBS)
 	@echo 'zmap (C++ version) make...'
diff --git a/src/zmapApp/zmapApp_P.h b/src/zmapApp/zmapApp_P.h
index 9dcd5441c..8335f8cdd 100755
--- a/src/zmapApp/zmapApp_P.h
+++ b/src/zmapApp/zmapApp_P.h
@@ -25,20 +25,29 @@
  * Description: 
  * Exported functions: See XXXXXXXXXXXXX.h
  * HISTORY:
- * Last edited: Nov 17 16:11 2003 (edgrif)
+ * Last edited: Jan 22 15:15 2004 (edgrif)
  * Created: Thu Jul 24 14:35:41 2003 (edgrif)
- * CVS info:   $Id: zmapApp_P.h,v 1.3 2003-11-18 10:44:16 edgrif Exp $
+ * CVS info:   $Id: zmapApp_P.h,v 1.4 2004-01-23 13:27:58 edgrif Exp $
  *-------------------------------------------------------------------
  */
 #ifndef ZMAP_APP_PRIV_H
 #define ZMAP_APP_PRIV_H
 
 #include <gtk/gtk.h>
+
+
+#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
+#include <libgnome/libgnome.h>
+#include <libgnomeui/libgnomeui.h>
+#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
+
+
+
 #include <ZMap/zmapManager.h>
 
 
 /* Minimum GTK version supported. */
-enum {ZMAP_GTK_MAJOR = 2, ZMAP_GTK_MINOR = 2, ZMAP_GTK_MICRO = 4} ;
+enum {ZMAP_GTK_MAJOR = 2, ZMAP_GTK_MINOR = 2, ZMAP_GTK_MICRO = 1} ;
 
 
 /* Overall application control struct. */
@@ -46,8 +55,6 @@ typedef struct
 {
   GtkWidget *app_widg ;
 
-  GtkWidget *machine_widg ;
-  GtkWidget *port_widg ;
   GtkWidget *sequence_widg ;
 
   GtkWidget *clist_widg ;
@@ -59,7 +66,7 @@ typedef struct
 
 
 /* cols in connection list. */
-enum {ZMAP_NUM_COLS = 3} ;
+enum {ZMAP_NUM_COLS = 4} ;
 
 
 
diff --git a/src/zmapApp/zmapAppconnect.c b/src/zmapApp/zmapAppconnect.c
index 5b14b0db6..9f17c88a1 100755
--- a/src/zmapApp/zmapAppconnect.c
+++ b/src/zmapApp/zmapAppconnect.c
@@ -26,9 +26,9 @@
  * Description: 
  * Exported functions: See XXXXXXXXXXXXX.h
  * HISTORY:
- * Last edited: Nov 17 14:58 2003 (edgrif)
+ * Last edited: Jan 22 15:20 2004 (edgrif)
  * Created: Thu Jul 24 14:36:37 2003 (edgrif)
- * CVS info:   $Id: zmapAppconnect.c,v 1.3 2003-11-18 10:44:16 edgrif Exp $
+ * CVS info:   $Id: zmapAppconnect.c,v 1.4 2004-01-23 13:27:59 edgrif Exp $
  *-------------------------------------------------------------------
  */
 
@@ -46,7 +46,7 @@ GtkWidget *zmapMainMakeConnect(ZMapAppContext app_context)
   GtkWidget *frame ;
   GtkWidget *topbox, *hbox, *entry, *label, *create_button ;
 
-  frame = gtk_frame_new( "New Connection" );
+  frame = gtk_frame_new( "New ZMap" );
   gtk_frame_set_label_align( GTK_FRAME( frame ), 0.0, 0.0 );
   gtk_container_border_width(GTK_CONTAINER(frame), 5);
 
@@ -58,30 +58,6 @@ GtkWidget *zmapMainMakeConnect(ZMapAppContext app_context)
   gtk_container_border_width(GTK_CONTAINER(hbox), 5);
   gtk_box_pack_start(GTK_BOX(topbox), hbox, FALSE, FALSE, 0) ;
 
-  label = gtk_label_new( "Machine:" ) ;
-  gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0) ;
-
-  app_context->machine_widg = entry = gtk_entry_new() ;
-  gtk_entry_set_text(GTK_ENTRY(entry), "") ;
-  gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1) ;
-  gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0) ;
-
-  hbox = gtk_hbox_new(FALSE, 0) ;
-  gtk_container_border_width(GTK_CONTAINER(hbox), 5);
-  gtk_box_pack_start(GTK_BOX(topbox), hbox, FALSE, FALSE, 0) ;
-
-  label = gtk_label_new( "Port:" ) ;
-  gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0) ;
-
-  app_context->port_widg = entry = gtk_entry_new() ;
-  gtk_entry_set_text(GTK_ENTRY(entry), "") ;
-  gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1) ;
-  gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0) ;
-
-  hbox = gtk_hbox_new(FALSE, 0) ;
-  gtk_container_border_width(GTK_CONTAINER(hbox), 5);
-  gtk_box_pack_start(GTK_BOX(topbox), hbox, FALSE, FALSE, 0) ;
-
   label = gtk_label_new( "Sequence:" ) ;
   gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0) ;
 
@@ -90,7 +66,7 @@ GtkWidget *zmapMainMakeConnect(ZMapAppContext app_context)
   gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1) ;
   gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0) ;
 
-  create_button = gtk_button_new_with_label("Create Thread") ;
+  create_button = gtk_button_new_with_label("Create ZMap") ;
   gtk_signal_connect(GTK_OBJECT(create_button), "clicked",
 		     GTK_SIGNAL_FUNC(createThreadCB), (gpointer)app_context) ;
   gtk_box_pack_start(GTK_BOX(topbox), create_button, FALSE, FALSE, 0) ;
@@ -108,33 +84,27 @@ GtkWidget *zmapMainMakeConnect(ZMapAppContext app_context)
 static void createThreadCB(GtkWidget *widget, gpointer cb_data)
 {
   ZMapAppContext app_context = (ZMapAppContext)cb_data ;
-  char *machine ;
-  char *port_str ;
-  int port ;
   char *sequence ;
   char *row_text[ZMAP_NUM_COLS] = {"", "", ""} ;
   int row ;
   ZMap zmap ;
 
-  machine = (char *)gtk_entry_get_text(GTK_ENTRY(app_context->machine_widg)) ;
-  port_str = (char *)gtk_entry_get_text(GTK_ENTRY(app_context->port_widg)) ;
-  port = atoi(port_str) ;
   sequence = (char *)gtk_entry_get_text(GTK_ENTRY(app_context->sequence_widg)) ;
 
-
-  zmap = zMapManagerAdd(app_context->zmap_manager, machine, port, sequence) ;
+  zmap = zMapManagerAdd(app_context->zmap_manager, sequence) ;
   /* ERROR HANDLING ETC.... */
 
-  row_text[0] = machine ;
-  row_text[1] = port_str ;
-  row_text[2] = sequence ;
+  row_text[0] = zMapGetZMapID(zmap) ;
+  row_text[1] = zMapGetSequence(zmap) ;
+  row_text[2] = zMapGetZMapStatus(zmap) ;
+  row_text[3] = "rubbish" ;
 
   row = gtk_clist_append(GTK_CLIST(app_context->clist_widg), row_text) ;
   gtk_clist_set_row_data(GTK_CLIST(app_context->clist_widg), row, (gpointer)zmap) ;
 
 
-  ZMAP_DEBUG(("GUI: create thread number %d to access: %s on port %d\n",
-		  (row + 1), machine ? machine : "localhost", port)) ;
+  ZMAP_DEBUG(("GUI: create thread number %d for zmap \"%s\" for sequence \"%s\"\n",
+		  (row + 1), row_text[0], row_text[1])) ;
 
   return ;
 }
diff --git a/src/zmapApp/zmapAppmanage.c b/src/zmapApp/zmapAppmanage.c
index 158096431..bc11a8f0f 100755
--- a/src/zmapApp/zmapAppmanage.c
+++ b/src/zmapApp/zmapAppmanage.c
@@ -26,9 +26,9 @@
  * Description: 
  * Exported functions: See XXXXXXXXXXXXX.h
  * HISTORY:
- * Last edited: Nov 17 16:11 2003 (edgrif)
+ * Last edited: Jan 22 14:13 2004 (edgrif)
  * Created: Thu Jul 24 14:36:47 2003 (edgrif)
- * CVS info:   $Id: zmapAppmanage.c,v 1.3 2003-11-18 10:44:16 edgrif Exp $
+ * CVS info:   $Id: zmapAppmanage.c,v 1.4 2004-01-23 13:28:00 edgrif Exp $
  *-------------------------------------------------------------------
  */
 
@@ -37,6 +37,7 @@
 #include <zmapApp_P.h>
 
 static void loadThreadCB(GtkWidget *widget, gpointer cb_data) ;
+static void stopThreadCB(GtkWidget *widget, gpointer cb_data) ;
 static void killThreadCB(GtkWidget *widget, gpointer data) ;
 static void checkThreadCB(GtkWidget *widget, gpointer cb_data) ;
 static void selectRow(GtkCList *clist, gint row, gint column, GdkEventButton *event,
@@ -45,16 +46,17 @@ static void unselectRow(GtkCList *clist, gint row, gint column, GdkEventButton *
 			gpointer cb_data) ;
 
 
-static char *column_titles[ZMAP_NUM_COLS] = {"Window", "Status", "Last Request"} ;
+static char *column_titles[ZMAP_NUM_COLS] = {"ZMap", "Sequence", "Status", "Last Request"} ;
 
 
 
 GtkWidget *zmapMainMakeManage(ZMapAppContext app_context)
 {
   GtkWidget *frame ;
-  GtkWidget *vbox, *scrwin, *clist, *hbox, *load_button, *kill_button, *check_button ;
+  GtkWidget *vbox, *scrwin, *clist, *hbox,
+    *load_button, *stop_button, *kill_button, *check_button ;
 
-  frame = gtk_frame_new("Manage Connections") ;
+  frame = gtk_frame_new("Manage ZMaps") ;
   gtk_frame_set_label_align( GTK_FRAME( frame ), 0.0, 0.0 ) ;
   gtk_container_border_width(GTK_CONTAINER(frame), 5) ;
   
@@ -68,7 +70,7 @@ GtkWidget *zmapMainMakeManage(ZMapAppContext app_context)
   gtk_widget_set_usize(scrwin, -2, 150) ;		    /* -2  =>  leave value unchanged. */
   gtk_box_pack_start(GTK_BOX(vbox), scrwin, FALSE, FALSE, 0) ;
 
-  app_context->clist_widg = clist = gtk_clist_new_with_titles(3, column_titles) ;
+  app_context->clist_widg = clist = gtk_clist_new_with_titles(4, column_titles) ;
   gtk_signal_connect(GTK_OBJECT(clist), "select_row",
 		     GTK_SIGNAL_FUNC(selectRow), (gpointer)app_context) ;
   gtk_signal_connect(GTK_OBJECT(clist), "unselect_row",
@@ -80,17 +82,22 @@ GtkWidget *zmapMainMakeManage(ZMapAppContext app_context)
   gtk_container_border_width(GTK_CONTAINER(hbox), 5);
   gtk_container_add(GTK_CONTAINER(vbox), hbox);
 
-  load_button = gtk_button_new_with_label("Load Thread Data") ;
+  load_button = gtk_button_new_with_label("Reload") ;
   gtk_signal_connect(GTK_OBJECT(load_button), "clicked",
 		     GTK_SIGNAL_FUNC(loadThreadCB), (gpointer)app_context) ;
   gtk_box_pack_start(GTK_BOX(hbox), load_button, FALSE, FALSE, 0) ;
 
-  kill_button = gtk_button_new_with_label("Kill Thread") ;
+  stop_button = gtk_button_new_with_label("Stop") ;
+  gtk_signal_connect(GTK_OBJECT(stop_button), "clicked",
+		     GTK_SIGNAL_FUNC(stopThreadCB), (gpointer)app_context) ;
+  gtk_box_pack_start(GTK_BOX(hbox), stop_button, FALSE, FALSE, 0) ;
+
+  kill_button = gtk_button_new_with_label("Kill") ;
   gtk_signal_connect(GTK_OBJECT(kill_button), "clicked",
 		     GTK_SIGNAL_FUNC(killThreadCB), (gpointer)app_context) ;
   gtk_box_pack_start(GTK_BOX(hbox), kill_button, FALSE, FALSE, 0) ;
 
-  check_button = gtk_button_new_with_label("Check Connections") ;
+  check_button = gtk_button_new_with_label("Status") ;
   gtk_signal_connect(GTK_OBJECT(check_button), "clicked",
 		     GTK_SIGNAL_FUNC(checkThreadCB), (gpointer)app_context) ;
   gtk_box_pack_start(GTK_BOX(hbox), check_button, FALSE, FALSE, 0) ;
@@ -115,6 +122,26 @@ static void loadThreadCB(GtkWidget *widget, gpointer cb_data)
   return ;
 }
 
+static void stopThreadCB(GtkWidget *widget, gpointer cb_data)
+{
+  ZMapAppContext app_context = (ZMapAppContext)cb_data ;
+  int row ;
+
+  if (app_context->selected_zmap)
+    {
+      printf("not implemented\n") ;
+
+#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
+      /* We need a call like this.....but it doesn't exist yet... */
+      zMapManagerStop(app_context->selected_zmap) ;
+#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
+
+    }
+
+
+  return ;
+}
+
 static void killThreadCB(GtkWidget *widget, gpointer cb_data)
 {
   ZMapAppContext app_context = (ZMapAppContext)cb_data ;
diff --git a/src/zmapApp/zmapAppwindow.c b/src/zmapApp/zmapAppwindow.c
index 3d49fbaff..283f3ea3a 100755
--- a/src/zmapApp/zmapAppwindow.c
+++ b/src/zmapApp/zmapAppwindow.c
@@ -26,9 +26,9 @@
  * Description: 
  * Exported functions: See XXXXXXXXXXXXX.h
  * HISTORY:
- * Last edited: Nov 17 17:18 2003 (edgrif)
+ * Last edited: Jan 22 15:16 2004 (edgrif)
  * Created: Thu Jul 24 14:36:27 2003 (edgrif)
- * CVS info:   $Id: zmapAppwindow.c,v 1.3 2003-11-18 10:44:50 edgrif Exp $
+ * CVS info:   $Id: zmapAppwindow.c,v 1.4 2004-01-23 13:28:01 edgrif Exp $
  *-------------------------------------------------------------------
  */
 
@@ -37,14 +37,18 @@
 #include <zmapApp_P.h>
 
 
-static void initGTK(int argc, char *argv[]) ;
+extern int TEST_GLOBAL = 0 ;
+
+
+
+static void initGnomeGTK(int argc, char *argv[]) ;
 static ZMapAppContext createAppContext(void) ;
 static void quitCB(GtkWidget *widget, gpointer data) ;
 static void removeZmapRow(void *app_data, void *zmap) ;
 
 
-/* Overall app. debugging output. */
-gboolean zmap_debug_G = TRUE ; 
+/* Overall app. debugging output...not used currently. */
+gboolean zmapApp_debug_G = TRUE ; 
 
 
 
@@ -54,7 +58,12 @@ int zmapMainMakeAppWindow(int argc, char *argv[])
   GtkWidget *toplevel, *vbox, *menubar, *connect_frame, *manage_frame ;
   GtkWidget *kill_button, *quit_button ;
 
-  initGTK(argc, argv) ;					    /* May exit if checks fail. */
+  initGnomeGTK(argc, argv) ;					    /* May exit if checks fail. */
+
+
+  TEST_GLOBAL = atoi(argv[1]) ;
+
+
 
   app_context = createAppContext() ;
 
@@ -105,10 +114,15 @@ void zmapExit(ZMapAppContext app_context)
  */
 
 
-static void initGTK(int argc, char *argv[])
+static void initGnomeGTK(int argc, char *argv[])
 {
   gchar *err_msg ;
 
+#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
+  GnomeProgram *prog ; 
+#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
+
+
   gtk_set_locale() ;
 
   if ((err_msg = gtk_check_version(ZMAP_GTK_MAJOR, ZMAP_GTK_MINOR, ZMAP_GTK_MICRO)))
@@ -120,6 +134,22 @@ static void initGTK(int argc, char *argv[])
 
   gtk_init(&argc, &argv) ;
 
+
+#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
+  /* Initialize GNOME, we should have the version recorded somewhere.... plus need to look at
+   * whether we want to specify properties after argv. */
+
+  prog = gnome_program_init("ZMap", "0.0", LIBGNOMEUI_MODULE, argc, argv, GNOME_PARAM_NONE) ;
+
+#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
+  /* This crashes, apparently because gtk is not init'd.... */
+
+  prog = gnome_program_init("ZMap", "0.0", LIBGNOME_MODULE, argc, argv, GNOME_PARAM_NONE) ;
+#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
+
+#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
+
+
   return ;
 }
 
@@ -130,9 +160,7 @@ static ZMapAppContext createAppContext(void)
 
   app_context = g_new(ZMapAppContextStruct, sizeof(ZMapAppContextStruct)) ;
 
-  app_context->app_widg
-    = app_context->machine_widg = app_context->port_widg = app_context->sequence_widg
-    = app_context->clist_widg = NULL ;
+  app_context->app_widg = app_context->sequence_widg = app_context->clist_widg = NULL ;
 
   app_context->zmap_manager = zMapManagerInit(removeZmapRow, (void *)app_context) ;
   app_context->selected_zmap = NULL ;
diff --git a/src/zmapConfig/README b/src/zmapConfig/README
index b8385d312..8909f9c25 100755
--- a/src/zmapConfig/README
+++ b/src/zmapConfig/README
@@ -3,5 +3,11 @@ ZMapConfig
 
 
 This directory contains the code that deals with reading/writing configuration
-information into ZMaps configuration file(s). Currently much of this is just
-skeleton stuff.
+information into ZMaps configuration file(s).
+
+Status:
+
+ Currently much of this is just skeleton stuff. We need to add code, probably
+using gnome_config() calls to read the configuration files.
+
+Lots of work to do here.
diff --git a/src/zmapConfig/zmapConfig.c b/src/zmapConfig/zmapConfig.c
index a6ca0c634..e27b3da7b 100755
--- a/src/zmapConfig/zmapConfig.c
+++ b/src/zmapConfig/zmapConfig.c
@@ -25,17 +25,16 @@
  * Description: 
  * Exported functions: See zmapConfig.h
  * HISTORY:
- * Last edited: Jan 21 18:13 2004 (edgrif)
+ * Last edited: Jan 23 10:43 2004 (edgrif)
  * Created: Thu Jul 24 16:06:44 2003 (edgrif)
- * CVS info:   $Id: zmapConfig.c,v 1.1 2004-01-21 18:15:31 edgrif Exp $
+ * CVS info:   $Id: zmapConfig.c,v 1.2 2004-01-23 13:28:13 edgrif Exp $
  *-------------------------------------------------------------------
  */
 
 #include <zmapConfig_P.h>
 
 
-
-
+/* Initialise the configuration manager. */
 ZMapConfig zMapConfigInit(char *config_file)
 {
   ZMapConfig config ;
@@ -50,23 +49,35 @@ ZMapConfig zMapConfigInit(char *config_file)
 }
 
 
-
-gboolean zMapConfigGetPorts(ZMapConfig config, char **ports)
+/* Hacked up currently, these values would in reality be extracted from a configuration file
+ * and loaded into memory which would then become a dynamic list of servers that could be
+ * added into interactively. */
+gboolean zMapConfigGetServers(ZMapConfig config, char ***servers)
 {
-  gboolean result = FALSE ;
+  gboolean result = TRUE ;
+  static char *my_servers[] = {"griffin2 20000 acedb",
+			       "griffin2 20001 acedb",
+			       "griffin2 20002 acedb",
+			       NULL} ;
 
-  /* This is just hacked for now.... */
-  static char *my_ports[] = {"griffin2 20000 acedb",
-			     "griffin2 20001 acedb",
-			     "griffin2 20002 acedb"} ;
-
-  *ports = &my_ports[0] ;
+  *servers = my_servers ;
 
   return result ;
 }
 
 
 
+/* Delete of a config, will require freeing some members of the structure. */
+void zMapConfigDelete(ZMapConfig config)
+{
+  g_free(config->config_file) ;
+
+  g_free(config) ;
+
+  return ;
+}
+
+
 /*
  *  ------------------- Internal functions -------------------
  */
diff --git a/src/zmapControl/zmapControl.c b/src/zmapControl/zmapControl.c
index bbd20b53b..bb893f865 100755
--- a/src/zmapControl/zmapControl.c
+++ b/src/zmapControl/zmapControl.c
@@ -20,14 +20,15 @@
  * This file is part of the ZMap genome database package
  * and was written by
  * 	Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk and
- *      Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk,
+ *      Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk
  *
- * Description: 
- * Exported functions: See XXXXXXXXXXXXX.h
+ * Description: This is the ZMap interface code, it controls both
+ *              the window code and the threaded server code.
+ * Exported functions: See ZMap.h
  * HISTORY:
- * Last edited: Nov 17 18:49 2003 (edgrif)
+ * Last edited: Jan 23 11:24 2004 (edgrif)
  * Created: Thu Jul 24 16:06:44 2003 (edgrif)
- * CVS info:   $Id: zmapControl.c,v 1.1 2003-11-18 10:32:22 edgrif Exp $
+ * CVS info:   $Id: zmapControl.c,v 1.2 2004-01-23 13:28:09 edgrif Exp $
  *-------------------------------------------------------------------
  */
 
@@ -35,28 +36,51 @@
 #include <ZMap_P.h>
 
 
+/* ZMap debugging output. */
+gboolean zmap_debug_G = TRUE ; 
 
-static void killGUI(ZMap zmap) ;
-static void killZMap(ZMap zmap) ;
-static gint idleCB(gpointer cb_data) ;
+
+static gint zmapIdleCB(gpointer cb_data) ;
+static void zmapWindowCB(void *cb_data, int reason) ;
 static void checkConnection(ZMap zmap) ;
 static void startConnectionChecking(ZMap zmap) ;
 static void stopConnectionChecking(ZMap zmap) ;
+static void killGUI(ZMap zmap) ;
+static void killZMap(ZMap zmap) ;
+static gboolean getServer(char *server_string, char **machine, char **port, char **protocol) ;
 
 
 
+/*
+ *  ------------------- External functions -------------------
+ *   (includes callbacks)
+ */
+
+
 /* Trivial at the moment..... */
-ZMap zMapCreate(void *app_data, ZMapCallbackFunc destroy_func)
+ZMap zMapCreate(void *app_data, ZMapCallbackFunc destroy_cb, ZMapConfig config)
 {
   ZMap zmap = NULL ;
 
+  /* GROSS HACK FOR NOW, NEED SOMETHING BETTER LATER... */
+  static int zmap_num = 0 ;
+
   zmap = g_new(ZMapStruct, sizeof(ZMapStruct)) ;
+  zmap_num++ ;
 
-  zmap->app_data = app_data ;
-  zmap->destroy_zmap_cb = destroy_func ;
+  zmap->zmap_id = g_strdup_printf("%d", zmap_num) ;
 
   zmap->state = ZMAP_INIT ;
 
+  zmap->sequence = NULL ;
+
+  zmap->config = config ;
+
+  zmap->connection_list = NULL ;
+
+  zmap->app_data = app_data ;
+  zmap->destroy_zmap_cb = destroy_cb ;
+
   return zmap ;
 }
 
@@ -64,37 +88,64 @@ ZMap zMapCreate(void *app_data, ZMapCallbackFunc destroy_func)
 
 /* Create a new zmap with its window and a connection to a database via a thread,
  * at this point the ZMap is blank and waiting to be told to load some data. */
-gboolean zMapConnect(ZMap zmap, char *machine, int port, char *sequence)
+gboolean zMapConnect(ZMap zmap, char *sequence)
 {
   gboolean result = TRUE ;
+  char **server_list = NULL ;
+
+  zmap->sequence = sequence ;
 
+  /* We need to retrieve the connect data here from the config stuff.... */
   if (result)
     {
-      if (!(zmap->connection = zMapConnCreate(machine, port, sequence)))
+      if (!(zMapConfigGetServers(zmap->config, &server_list)))
 	result = FALSE ;
     }
 
-  /* We should pass in the address of our "idle" function to the window create routine...or
-   * perhaps we can just set up the idle function here.....better ?? */
 
+  /* Set up a connection to the named server. */
   if (result)
     {
-      /* The destroy_func bit is probably not right...needs to be another window func... */
-      if ((zmap->window = zMapWindowCreate(machine, port, sequence,
-					   zmap->destroy_zmap_cb, zmap->app_data)))
-	{
-	  zmap->state = ZMAP_CONNECTED ;
+      char **next = server_list ;
+      int connections = 0 ;
 
-	}
-      else
+      /* Error handling is tricky here, if we manage to connect to some servers and not
+       * others, what do we do ?  THINK ABOUT THIS..... */
+      while (result && *next != NULL)
 	{
-	  /* NOTE, we do a _kill_ here, not a destroy. This just signals the thread to die, it
-	   * will actually die sometime later and be properly cleaned up by code in
-	   * zMapManagerCheckConnections() */
-	  zMapConnKill(zmap->connection) ;
+	  char *machine, *port, *protocol ;
+	  ZMapConnection connection ;
+
+	  if (getServer(*next, &machine, &port, &protocol)
+	      && (connection = zMapConnCreate(machine, port, protocol, sequence)))
+	    {
+	      zmap->connection_list = g_list_append(zmap->connection_list, connection) ;
+	      connections++ ;
+	    }
+	  else
+	    {
+	      gchar *err_msg ;
 
-	  result = FALSE ;
+	      err_msg = g_strdup_printf("Could not connect to %s protocol server "
+					"on %s, port %s", protocol, machine, port) ;
+
+	      zmapGUIShowMsg(err_msg) ;
+
+	      g_free(err_msg) ;
+	    }
+
+	  next++ ;
 	}
+
+      if (!connections)
+	result = FALSE ;
+    }
+
+  /* Create the zmap window itself. */
+  if (result)
+    {
+      if (!(zmap->window = zMapWindowCreate(sequence, zmap->zmap_id, zmapWindowCB, zmap)))
+	result = FALSE ;
     }
 
   /* Now set up our idle routine to check the connection. */
@@ -103,11 +154,36 @@ gboolean zMapConnect(ZMap zmap, char *machine, int port, char *sequence)
       startConnectionChecking(zmap) ;
     }
 
+  /* If everything is ok then we are connected to the server, otherwise signal failure
+   * and clean up. */
+  if (result)
+    {
+      zmap->state = ZMAP_CONNECTED ;
+    }
+  else
+    {
+      if (zmap->connection_list)
+	{
+
+	  /* OK HERE WE NEED TO CLEAN UP PROPERLY.....NEED A FUNCTION I THINK.... */
+
+	  /* NOTE, we do a _kill_ here, not a destroy. This just signals the thread to die, it
+	   * will actually die sometime later and be properly cleaned up by code in
+	   * zMapManagerCheckConnections() */
+	  zMapConnKill(zmap->connection) ;
+	}
+
+      if (zmap->window)
+	{
+	  killGUI(zmap) ;
+	}
+    }
 
   return result ;
 }
 
 
+/* Signal that we want data to stick into the ZMap */
 gboolean zMapLoad(ZMap zmap, char *sequence)
 {
   gboolean result = TRUE ;
@@ -141,6 +217,42 @@ gboolean zMapReset(ZMap zmap)
 }
 
 
+/*
+ *    A set of accessor functions.
+ */
+
+char *zMapGetZMapID(ZMap zmap)
+{
+  char *id ;
+
+  id = zmap->zmap_id ;
+
+  return id ;
+}
+
+
+char *zMapGetSequence(ZMap zmap)
+{
+  char *sequence ;
+
+  sequence = zmap->sequence ;
+
+  return sequence ;
+}
+
+char *zMapGetZMapStatus(ZMap zmap)
+{
+  /* Array must be kept in synch with ZmapState enum in ZMap_P.h */
+  static char *zmapStates[] = {"ZMAP_INIT", "ZMAP_CONNECTED", "ZMAP_LOADING",
+			       "ZMAP_DISPLAYED", "ZMAP_QUITTING"} ;
+  char *state ;
+
+  state = zmapStates[zmap->state] ;
+
+  return state ;
+}
+
+
 
 /* Called to kill a zmap window and get the associated thread killed, this latter will be
  * asynchronous. */
@@ -151,50 +263,102 @@ gboolean zMapDestroy(ZMap zmap)
   killGUI(zmap) ;
 
   /* NOTE, we do a _kill_ here, not a destroy. This just signals the thread to die, it
-   * will actually die sometime later and be properly cleaned up by code in
-   * zMapManagerCheckConnections() */
+   * will actually die sometime later...check clean up sequence..... */
   zMapConnKill(zmap->connection) ;
 
+  /* CHECK THAT THIS ALL WORKS...IT SHOULD DO..... */
+  g_free(zmap->zmap_id) ;
+
+  g_free(zmap) ;
+
   return TRUE ;
 }
 
 
 
-/* Start and stop our idle function (gets run when the GUI is doing nothing). This routine
- * checks the status of the connection to the server. */
-static void startConnectionChecking(ZMap zmap)
+/* This is really the guts of the code to check what a connection thread is up
+ * to. Every time the GUI thread has stopped doing things this routine gets called
+ * so then we check our connection for action..... */
+static gint zmapIdleCB(gpointer cb_data)
 {
-  zmap->idle_handle = gtk_idle_add(idleCB, (gpointer)zmap) ;
+  ZMap zmap = (ZMap)cb_data ;
 
-  return ;
+  checkConnection(zmap) ;
+
+  return 1 ;						    /* > 0 tells gtk to keep calling zmapIdleCB */
 }
 
-static void stopConnectionChecking(ZMap zmap)
+
+/* I'M NOT COMPLETELY SURE WE NEED THIS "REASON" STUFF....BUT PERHAPS IT IS A GOOD THING. */
+/* Gets called when zmap Window code needs to signal us that the user has done something
+ * such as click "quit". */
+static void zmapWindowCB(void *cb_data, int reason)
 {
-  gtk_idle_remove(zmap->idle_handle) ;
+  ZMap zmap = (ZMap)cb_data ;
+  ZmapWindowCmd window_cmd = (ZmapWindowCmd)reason ;
+  char *debug ;
+
+  if (window_cmd == ZMAP_WINDOW_QUIT)
+    {
+      debug = "ZMAP_WINDOW_QUIT" ;
+
+      zMapDestroy(zmap) ;
+
+      (*(zmap->destroy_zmap_cb))(zmap, zmap->app_data) ;
+    }
+  else if (window_cmd == ZMAP_WINDOW_LOAD)
+    {
+      debug = "ZMAP_WINDOW_LOAD" ;
+
+      zMapLoad(zmap, "") ;
+    }
+  else if (window_cmd == ZMAP_WINDOW_STOP)
+    {
+      debug = "ZMAP_WINDOW_STOP" ;
+    }
+
+
+#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
+  ZMAP_DEBUG(("GUI: received %s from thread %x\n", debug,
+	      zMapConnGetThreadid(zmap->connection))) ;
+#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
+
 
   return ;
 }
 
 
 
-/* This is really the guts of the code to check what a connection thread is up
- * to. Every time the GUI thread has stopped doing things this routine gets called
- * so then we check our connection for action..... */
-static gint idleCB(gpointer cb_data)
+
+
+/*
+ *  ------------------- Internal functions -------------------
+ */
+
+
+
+
+/* Start and stop the ZMap GTK idle function (gets run when the GUI is doing nothing).
+ * */
+static void startConnectionChecking(ZMap zmap)
 {
-  ZMap zmap = (ZMap)cb_data ;
+  zmap->idle_handle = gtk_idle_add(zmapIdleCB, (gpointer)zmap) ;
 
-  checkConnection(zmap) ;
+  return ;
+}
 
-  return 1 ;						    /* > 0 tells gtk to keep calling idleCB */
+static void stopConnectionChecking(ZMap zmap)
+{
+  gtk_idle_remove(zmap->idle_handle) ;
+
+  return ;
 }
 
 
 
 
 /* This function checks the status of the connection and checks for any reply and
- * then acts on it.
+ * then acts on it, it gets called from the ZMap idle function.
  *
  * NOTE that you cannot use a condvar here, if the connection thread signals us using a
  * condvar we will probably miss it, that just doesn't work, we have to pole for changes
@@ -271,15 +435,8 @@ static void checkConnection(ZMap zmap)
 
 
 
-
-
-/*
- *  ------------------- Internal functions -------------------
- */
-
 /* SOME ORDER ISSUES NEED TO BE ATTENDED TO HERE...WHEN SHOULD THE IDLE ROUTINE BE REMOVED ? */
 
-
 /* Calls the control window callback to remove any reference to the zmap and then destroys
  * the actual zmap itself.
  * 
@@ -319,4 +476,34 @@ static void killZMap(ZMap zmap)
   return ;
 }
 
+/* In some ways this code should really be in zmapConfig...maybe....
+ * We are expecting server_string to be of the form:
+ * 
+ *         "machine_id port protocol"
+ * 
+ * i.e. three words only. */
+static gboolean getServer(char *server_string, char **machine, char **port, char **protocol)
+{
+  gboolean result = FALSE ;
+  static gchar **tokens = NULL ;			    /* Static because caller needs strings
+							       for a short while. */
+
+  if (tokens)
+    {
+      g_strfreev(tokens) ;
+      tokens = NULL ;
+    }
+
+  if ((tokens = g_strsplit(server_string, " ", 3)))
+    {
+      *machine = tokens[0] ;
+      *port = (++tokens)[0] ;
+      *protocol = (++tokens)[0] ;
 
+      /* NOTE WELL the minimalistic error handling here.... */
+      if (machine && port && protocol)
+	result = TRUE ;
+    }
+
+  return result ;
+}
diff --git a/src/zmapManager/zmapManager.c b/src/zmapManager/zmapManager.c
index 545920fc6..5555d786a 100755
--- a/src/zmapManager/zmapManager.c
+++ b/src/zmapManager/zmapManager.c
@@ -25,21 +25,21 @@
  * Description: 
  * Exported functions: See zmapManager.h
  * HISTORY:
- * Last edited: Nov 18 10:50 2003 (edgrif)
+ * Last edited: Jan 22 13:26 2004 (edgrif)
  * Created: Thu Jul 24 16:06:44 2003 (edgrif)
- * CVS info:   $Id: zmapManager.c,v 1.2 2003-11-18 11:27:07 edgrif Exp $
+ * CVS info:   $Id: zmapManager.c,v 1.3 2004-01-23 13:28:10 edgrif Exp $
  *-------------------------------------------------------------------
  */
 
 #include <zmapManager_P.h>
+#include <ZMap/zmapConfig.h>
 
+static void managerCB(ZMap zmap, void *cb_data) ;
+static void removeZmapEntry(ZMapManager zmaps, ZMap zmap) ;
 
-static void zmapWindowCB(void *cb_data, int reason) ;
 
 
-
-ZMapManager zMapManagerInit(zmapAppCallbackFunc zmap_deleted_func,
-			    void *gui_data)
+ZMapManager zMapManagerInit(zmapAppCallbackFunc zmap_deleted_func, void *gui_data)
 {
   ZMapManager manager ;
 
@@ -47,6 +47,8 @@ ZMapManager zMapManagerInit(zmapAppCallbackFunc zmap_deleted_func,
 
   manager->zmap_list = NULL ;
 
+  manager->config = zMapConfigInit("any_old_file") ;
+
   manager->gui_zmap_deleted_func = zmap_deleted_func ;
   manager->gui_data = gui_data ;
 
@@ -55,26 +57,17 @@ ZMapManager zMapManagerInit(zmapAppCallbackFunc zmap_deleted_func,
 
 
 /* Add a new zmap window with associated thread and all the gubbins. */
-ZMap zMapManagerAdd(ZMapManager zmaps, char *machine, int port, char *sequence)
+ZMap zMapManagerAdd(ZMapManager zmaps, char *sequence)
 {
   ZMap zmap ;
-  ZMapManagerCB zmap_cb ;
-
-  zmap_cb = g_new(ZMapManagerCBStruct, sizeof(ZMapManagerCBStruct)) ;
 
-  if ((zmap = zMapCreate((void *)zmap_cb, zmapWindowCB))
-      && zMapConnect(zmap, machine, port, sequence))
+  if ((zmap = zMapCreate((void *)zmaps, managerCB, zmaps->config))
+      && zMapConnect(zmap, sequence))
     {
-      zmap_cb->zmap_list = zmaps ;
-      zmap_cb->zmap = zmap ;
-
       zmaps->zmap_list = g_list_append(zmaps->zmap_list, zmap) ;
     }
   else
     {
-      if (zmap_cb)
-	g_free(zmap_cb) ;
-
       printf("Aggghhhh, not able to create a zmap....\n") ;
     }
 
@@ -117,76 +110,40 @@ void zMapManagerReset(ZMap zmap)
 
 
 
-/* Called to kill a zmap window and get the associated thread killed, this latter will be
- * asynchronous. */
-/* Calls the control window callback to remove any reference to the zmap and then destroys
- * the actual zmap itself.
- * 
- * The window pointer must be null'd because this prevents us trying to doubly destroy
- * the window when a thread is killed but only signals its own destruction some time
- * later.
- *  */
 void zMapManagerKill(ZMapManager zmaps, ZMap zmap)
 {
-
-  /* THIS IS ALMOST CERTAINLY MESSED UP NOW..... */
-
   zMapDestroy(zmap) ;
 
-  zmaps->zmap_list = g_list_remove(zmaps->zmap_list, zmap) ;
-
-  (*(zmaps->gui_zmap_deleted_func))(zmaps->gui_data, zmap) ;
+  removeZmapEntry(zmaps, zmap) ;
 
   return ;
 }
 
 
 
-
-
-/*
- *  ------------------- Internal functions -------------------
- */
-
-
-
-
-/* Gets called when zmap Window needs Manager to do something. */
-static void zmapWindowCB(void *cb_data, int reason)
+/* Gets called when ZMap quits from "under our feet" as a result of user interaction,
+ * we then make sure we clean up. */
+static void managerCB(ZMap zmap, void *cb_data)
 {
-  ZMapManagerCB zmap_cb = (ZMapManagerCB)cb_data ;
-  ZmapWindowCmd window_cmd = (ZmapWindowCmd)reason ;
-  char *debug ;
-
-
-  if (window_cmd == ZMAP_WINDOW_QUIT)
-    {
-      debug = "ZMAP_WINDOW_QUIT" ;
+  ZMapManager zmaps = (ZMapManager)cb_data ;
 
-      zMapManagerKill(zmap_cb->zmap_list, zmap_cb->zmap) ;
+  removeZmapEntry(zmaps, zmap) ;
 
-      g_free(zmap_cb) ;					    /* Only free on destroy. */
-    }
-  else if (window_cmd == ZMAP_WINDOW_LOAD)
-    {
-      debug = "ZMAP_WINDOW_LOAD" ;
+  return ;
+}
 
-      zMapManagerLoadData(zmap_cb->zmap) ;
-    }
-  else if (window_cmd == ZMAP_WINDOW_STOP)
-    {
-      debug = "ZMAP_WINDOW_STOP" ;
-    }
 
 
+/*
+ *  ------------------- Internal functions -------------------
+ */
 
-#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
-  /* We need to pass back the info here....or something..... */
 
-  ZMAP_DEBUG(("GUI: received %s from thread %x\n", debug,
-	      zMapConnGetThreadid(zmap_cb->zmap->connection))) ;
-#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
+static void removeZmapEntry(ZMapManager zmaps, ZMap zmap)
+{
+  zmaps->zmap_list = g_list_remove(zmaps->zmap_list, zmap) ;
 
+  (*(zmaps->gui_zmap_deleted_func))(zmaps->gui_data, zmap) ;
 
   return ;
 }
diff --git a/src/zmapManager/zmapManager_P.h b/src/zmapManager/zmapManager_P.h
index a4ed420c8..988a1e02d 100755
--- a/src/zmapManager/zmapManager_P.h
+++ b/src/zmapManager/zmapManager_P.h
@@ -25,42 +25,31 @@
  * Description: 
  * Exported functions: See XXXXXXXXXXXXX.h
  * HISTORY:
- * Last edited: Nov 18 10:51 2003 (edgrif)
+ * Last edited: Jan 22 13:22 2004 (edgrif)
  * Created: Thu Jul 24 14:39:06 2003 (edgrif)
- * CVS info:   $Id: zmapManager_P.h,v 1.2 2003-11-18 11:27:07 edgrif Exp $
+ * CVS info:   $Id: zmapManager_P.h,v 1.3 2004-01-23 13:28:11 edgrif Exp $
  *-------------------------------------------------------------------
  */
 #ifndef ZMAP_MANAGER_P_H
 #define ZMAP_MANAGER_P_H
 
 #include <glib.h>
-
-/* THERE IS STUFF IN HERE WHICH SHOULD BE IN ZMAP.H */
-#include <ZMap/zmapWindow.h>
-
 #include <ZMap/ZMap.h>
 #include <ZMap/zmapManager.h>
+#include <ZMap/zmapConfig.h>
 
-
-/* A list of connections of type ZMapConnection. */
+/* Contains the list of ZMaps maintained by manager, plus a record of the callback stuff
+ * registered by the application. */
 typedef struct _ZMapManagerStruct
 {
   GList *zmap_list ;
 
+  ZMapConfig config ;
+
   zmapAppCallbackFunc gui_zmap_deleted_func ;
   void *gui_data ;
 
 } ZMapManagerStruct ;
 
 
-
-typedef struct _ZMapManagerCBStruct
-{
-  ZMapManager zmap_list ;
-
-  ZMap zmap ;
-} ZMapManagerCBStruct, *ZMapManagerCB ;
-
-
-
 #endif /* !ZMAP_MANAGER_P_H */
diff --git a/src/zmapServer/makefile b/src/zmapServer/makefile
index 34c94e962..4bfeefbb3 100755
--- a/src/zmapServer/makefile
+++ b/src/zmapServer/makefile
@@ -15,7 +15,7 @@ SERV_OBJ = zmapServer.o
 # These must all be set for the common includes to work.
 # Need to include AceConn header.
 #
-CURRENT_LIB = $(ZMAP_LIB)
+CURRENT_LIB = $(ZMAPTHR_LIB)
 CURRENT_OBJ = $(SERV_OBJ)
 CURRENT_DEP = $(PUB_HDRS) $(SERV_PRIV_HDRS)
 CURRENT_SRC = $(SERV_PRIV_HDRS) $(SERV_SRC)
diff --git a/src/zmapThreads/makefile b/src/zmapThreads/makefile
index adf511833..b7426fe13 100755
--- a/src/zmapThreads/makefile
+++ b/src/zmapThreads/makefile
@@ -15,7 +15,7 @@ APP_OBJ = zmapConn.o zmapSlave.o zmapConnutils.o
 #
 # These must all be set for the common includes to work.
 #
-CURRENT_LIB = $(ZMAP_LIB)
+CURRENT_LIB = $(ZMAPTHR_LIB)
 CURRENT_OBJ = $(APP_OBJ)
 CURRENT_DEP = $(PUB_HDRS) $(APP_PRIV_HDRS)
 CURRENT_SRC = $(APP_PRIV_HDRS) $(APP_SRC)
diff --git a/src/zmapThreads/zmapConn.c b/src/zmapThreads/zmapConn.c
index bef8e0df6..228f66294 100755
--- a/src/zmapThreads/zmapConn.c
+++ b/src/zmapThreads/zmapConn.c
@@ -26,9 +26,9 @@
  * Description: 
  * Exported functions: See XXXXXXXXXXXXX.h
  * HISTORY:
- * Last edited: Sep  3 16:25 2003 (edgrif)
+ * Last edited: Jan 22 13:52 2004 (edgrif)
  * Created: Thu Jul 24 14:37:18 2003 (edgrif)
- * CVS info:   $Id: zmapConn.c,v 1.1 2003-11-13 15:02:12 edgrif Exp $
+ * CVS info:   $Id: zmapConn.c,v 1.2 2004-01-23 13:27:53 edgrif Exp $
  *-------------------------------------------------------------------
  */
 
@@ -41,7 +41,7 @@ gboolean zmap_thr_debug_G = TRUE ;
 
 
 
-ZMapConnection zMapConnCreate(char *machine, int port, char *sequence)
+ZMapConnection zMapConnCreate(char *machine, char *port, char *protocol, char *sequence)
 {
   ZMapConnection connection ;
   pthread_t thread_id ;
@@ -51,7 +51,8 @@ ZMapConnection zMapConnCreate(char *machine, int port, char *sequence)
   connection = g_new(ZMapConnectionStruct, sizeof(ZMapConnectionStruct)) ;
 
   connection->machine = g_strdup(machine) ;
-  connection->port = port ;
+  connection->port = atoi(port) ;
+  connection->protocol = g_strdup(protocol) ;
   connection->sequence = g_strdup(sequence) ;
 
   /* ok to just set state here because we have not started the thread yet.... */
@@ -130,9 +131,9 @@ gboolean zMapConnGetReplyWithData(ZMapConnection connection, ZMapThreadReply *st
 
 
 
-pthread_t zMapConnGetThreadid(ZMapConnection connection)
+void *zMapConnGetThreadid(ZMapConnection connection)
 {
-  return connection->thread_id ;
+  return (void *)(connection->thread_id) ;
 }
 
 /* Kill the thread by cancelling it, as this will asynchronously we cannot release the connections
diff --git a/src/zmapThreads/zmapConn_P.h b/src/zmapThreads/zmapConn_P.h
index 749d9969e..556f2af7b 100755
--- a/src/zmapThreads/zmapConn_P.h
+++ b/src/zmapThreads/zmapConn_P.h
@@ -26,9 +26,9 @@
  * Description: 
  * Exported functions: See XXXXXXXXXXXXX.h
  * HISTORY:
- * Last edited: Nov 12 16:35 2003 (edgrif)
+ * Last edited: Jan 22 13:53 2004 (edgrif)
  * Created: Thu Jul 24 14:36:08 2003 (edgrif)
- * CVS info:   $Id: zmapConn_P.h,v 1.1 2003-11-13 15:02:12 edgrif Exp $
+ * CVS info:   $Id: zmapConn_P.h,v 1.2 2004-01-23 13:27:54 edgrif Exp $
  *-------------------------------------------------------------------
  */
 #ifndef ZMAP_CONN_PRIV_H
@@ -83,6 +83,7 @@ typedef struct _ZMapConnectionStruct
   /* These are read only after creation of the thread. */
   gchar *machine ;
   int port ;
+  gchar *protocol ;
   gchar *sequence ;
   pthread_t thread_id ;
 
diff --git a/src/zmapThreads/zmapConnutils.c b/src/zmapThreads/zmapConnutils.c
index 49cbf9f07..f14e5fac5 100755
--- a/src/zmapThreads/zmapConnutils.c
+++ b/src/zmapThreads/zmapConnutils.c
@@ -26,9 +26,9 @@
  * Description: 
  * Exported functions: See XXXXXXXXXXXXX.h
  * HISTORY:
- * Last edited: Nov 12 16:42 2003 (edgrif)
+ * Last edited: Jan  8 16:27 2004 (edgrif)
  * Created: Thu Jul 24 14:37:35 2003 (edgrif)
- * CVS info:   $Id: zmapConnutils.c,v 1.1 2003-11-13 15:02:13 edgrif Exp $
+ * CVS info:   $Id: zmapConnutils.c,v 1.2 2004-01-23 13:27:55 edgrif Exp $
  *-------------------------------------------------------------------
  */
 
@@ -37,7 +37,7 @@
 
 
 static void releaseCondvarMutex(void *thread_data) ;
-
+static int getAbsTime(const TIMESPEC *relative_timeout, TIMESPEC *abs_timeout) ;
 
 
 
@@ -131,7 +131,7 @@ ZMapThreadRequest zmapCondVarWaitTimed(ZMapRequest condvar, ZMapThreadRequest wa
 {
   ZMapThreadRequest signalled_state = ZMAP_REQUEST_INIT ;
   int status ;
-  TIMESPEC systimeout ;
+  TIMESPEC abs_timeout ;
 
 
   pthread_cleanup_push(releaseCondvarMutex, (void *)condvar) ;
@@ -143,13 +143,19 @@ ZMapThreadRequest zmapCondVarWaitTimed(ZMapRequest condvar, ZMapThreadRequest wa
     }
   
   /* Get the relative timeout converted to absolute for the call. */
-  if ((status = pthread_get_expiration_np(relative_timeout, &systimeout)) != 0)
+
+#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
+  if ((status = pthread_get_expiration_np(relative_timeout, &abs_timeout)) != 0)
+    ZMAPSYSERR(status, "zmapCondVarWaitTimed invalid time") ;
+#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
+
+  if ((status = getAbsTime(relative_timeout, &abs_timeout)) != 0)
     ZMAPSYSERR(status, "zmapCondVarWaitTimed invalid time") ;
 
   while (condvar->state == waiting_state)
     {
       if ((status = pthread_cond_timedwait(&(condvar->cond), &(condvar->mutex),
-					   &systimeout)) != 0)
+					   &abs_timeout)) != 0)
 	{
 	  if (status == ETIMEDOUT)			    /* Timed out so return. */
 	    {
@@ -403,3 +409,38 @@ static void releaseCondvarMutex(void *thread_data)
 
   return ;
 }
+
+
+/* This function is a cheat really. You can only portably get the time in seconds
+ * as far as I can see so specifying small relative timeouts will not work....
+ * to this end I have inserted code to check that the relative timeout is not
+ * less than a single clock tick, hardly perfect but better than nothing.
+ * 
+ * On the alpha you can do this:
+ * 
+ *       pthread_get_expiration_np(relative_timeout, &abs_timeout)
+ * 
+ * to get a timeout in seconds and nanoseconds but this call is unavailable on
+ * Linux at least....
+ * 
+ *  */
+static int getAbsTime(const TIMESPEC *relative_timeout, TIMESPEC *abs_timeout)
+{
+  int status = 1 ;					    /* Fail by default. */
+  static int clock_tick_nano ;
+
+  
+  clock_tick_nano = 1000000000 / CLK_TCK ;		    /* CLK_TCK can be a function. */
+
+  if ((relative_timeout->tv_sec > 0 && relative_timeout->tv_nsec >= 0)
+      || (relative_timeout->tv_sec == 0 && relative_timeout->tv_nsec > clock_tick_nano))
+    {
+      *abs_timeout = *relative_timeout ;		    /* struct copy */
+      abs_timeout->tv_sec += time(NULL) ;
+
+      status = 0 ;
+    }
+
+
+  return status ;
+}
diff --git a/src/zmapWindow/zmapWindow.c b/src/zmapWindow/zmapWindow.c
index 466ebb292..8955cb61c 100755
--- a/src/zmapWindow/zmapWindow.c
+++ b/src/zmapWindow/zmapWindow.c
@@ -26,9 +26,9 @@
  * Description: 
  * Exported functions: See XXXXXXXXXXXXX.h
  * HISTORY:
- * Last edited: Nov 17 18:12 2003 (edgrif)
+ * Last edited: Jan 22 14:36 2004 (edgrif)
  * Created: Thu Jul 24 14:36:27 2003 (edgrif)
- * CVS info:   $Id: zmapWindow.c,v 1.3 2003-11-18 11:30:40 edgrif Exp $
+ * CVS info:   $Id: zmapWindow.c,v 1.4 2004-01-23 13:27:49 edgrif Exp $
  *-------------------------------------------------------------------
  */
 
@@ -41,7 +41,7 @@ static void dataEventCB(GtkWidget *widget, GdkEventClient *event, gpointer data)
 
 
 
-ZMapWindow zMapWindowCreate(char *machine, int port, char *sequence, 
+ZMapWindow zMapWindowCreate(char *sequence, char *zmap_id,
 			    zmapVoidIntCallbackFunc app_routine, void *app_data)
 {
   ZMapWindow window ;
@@ -50,15 +50,13 @@ ZMapWindow zMapWindowCreate(char *machine, int port, char *sequence,
 
   window = g_new(ZMapWindowStruct, sizeof(ZMapWindowStruct)) ;
 
-  window->machine = g_strdup(machine) ;
-  window->port = port ;
-  window->sequence = g_strdup(sequence) ;
+  if (sequence)
+    window->sequence = g_strdup(sequence) ;
   window->app_routine = app_routine ;
   window->app_data = app_data ;
   window->zmap_atom = gdk_atom_intern(ZMAP_ATOM, FALSE) ;
 
-  title = g_strdup_printf("ZMap (%s, port %d): %s", machine, port,
-			  sequence ? sequence : "") ;
+  title = g_strdup_printf("ZMap - %s : %s", zmap_id, sequence ? sequence : "") ;
 
   window->toplevel = toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL) ;
   gtk_window_set_policy(GTK_WINDOW(toplevel), FALSE, TRUE, FALSE ) ;
@@ -142,8 +140,8 @@ void zMapWindowDestroy(ZMapWindow window)
 
   gtk_widget_destroy(window->toplevel) ;
 
-  g_free(window->machine) ;
-  g_free(window->sequence) ;
+  if (window->sequence)
+    g_free(window->sequence) ;
 
   g_free(window) ;
 
diff --git a/src/zmapWindow/zmapWindow_P.h b/src/zmapWindow/zmapWindow_P.h
index 8fd4531fd..6dd001da9 100755
--- a/src/zmapWindow/zmapWindow_P.h
+++ b/src/zmapWindow/zmapWindow_P.h
@@ -26,9 +26,9 @@
  * Description: 
  * Exported functions: See XXXXXXXXXXXXX.h
  * HISTORY:
- * Last edited: Nov 17 17:33 2003 (edgrif)
+ * Last edited: Jan 22 13:57 2004 (edgrif)
  * Created: Fri Aug  1 16:45:58 2003 (edgrif)
- * CVS info:   $Id: zmapWindow_P.h,v 1.2 2003-11-18 11:30:40 edgrif Exp $
+ * CVS info:   $Id: zmapWindow_P.h,v 1.3 2004-01-23 13:27:51 edgrif Exp $
  *-------------------------------------------------------------------
  */
 #ifndef ZMAP_WINDOW_P_H
@@ -39,8 +39,6 @@
 
 typedef struct _ZMapWindowStruct
 {
-  gchar *machine ;
-  int port ;
   gchar *sequence ;
 
   GtkWidget *toplevel ;
-- 
GitLab