From 4205f42dd1821914be61d54ba9841518f7719cd5 Mon Sep 17 00:00:00 2001
From: edgrif <edgrif>
Date: Wed, 2 Feb 2005 11:26:26 +0000
Subject: [PATCH] redundant code moved from main build.

---
 zmap-no-threads/zmapNoThreads/README          |  11 ++
 zmap-no-threads/zmapNoThreads/makefile        |  49 ++++++
 zmap-no-threads/zmapNoThreads/zmapConnNoThr.c | 158 ++++++++++++++++++
 .../zmapNoThreads/zmapConnNoThr_P.h           |  89 ++++++++++
 4 files changed, 307 insertions(+)
 create mode 100755 zmap-no-threads/zmapNoThreads/README
 create mode 100755 zmap-no-threads/zmapNoThreads/makefile
 create mode 100755 zmap-no-threads/zmapNoThreads/zmapConnNoThr.c
 create mode 100755 zmap-no-threads/zmapNoThreads/zmapConnNoThr_P.h

diff --git a/zmap-no-threads/zmapNoThreads/README b/zmap-no-threads/zmapNoThreads/README
new file mode 100755
index 000000000..a98ad970f
--- /dev/null
+++ b/zmap-no-threads/zmapNoThreads/README
@@ -0,0 +1,11 @@
+================================================================================   
+No threads
+
+A non-threaded, non-server version of the calls to get data from a database.
+
+This is (hopefully) a cheap and cheerful way to integrate zmap into acedb without
+compromising the zmap design too much.
+
+We replicate the zmapConn interface but with direct calls to the attached database.
+
+
diff --git a/zmap-no-threads/zmapNoThreads/makefile b/zmap-no-threads/zmapNoThreads/makefile
new file mode 100755
index 000000000..853a3248d
--- /dev/null
+++ b/zmap-no-threads/zmapNoThreads/makefile
@@ -0,0 +1,49 @@
+#
+# Makes the manager part of the ZMap application.
+#
+
+
+#
+# point to common make include file which contains all the rules etc.
+#
+ROOT_DIRECTORY = ..
+MAKE_DIR = $(ROOT_DIRECTORY)/zmapMake
+
+
+# local macros
+PUB_HDRS = zmapSys.h zmapConn.h
+APP_PRIV_HDRS = zmapConnNoThr_P.h
+APP_SRC = zmapConnNoThr.c
+APP_OBJ = zmapConnNoThr.o
+
+# the main routines will need some different treatment maybe...???? try putting
+# them all together, don't know if it will work.....
+
+#
+# These must all be set for the common includes to work.
+#
+CURRENT_LIB = $(ZMAPNOTHR_LIB)
+CURRENT_OBJ = $(APP_OBJ)
+CURRENT_DEP = $(PUB_HDRS) $(APP_PRIV_HDRS)
+CURRENT_SRC = $(APP_PRIV_HDRS) $(APP_SRC)
+
+#
+# include all common defines
+#
+include $(MAKE_DIR)/common.defs
+
+
+#
+# override any of the common defines that you need to here...
+#
+
+
+#
+# include all common targets
+#
+include $(MAKE_DIR)/common.targets
+
+
+#
+# include your own targets here.
+#
diff --git a/zmap-no-threads/zmapNoThreads/zmapConnNoThr.c b/zmap-no-threads/zmapNoThreads/zmapConnNoThr.c
new file mode 100755
index 000000000..e4f16e5be
--- /dev/null
+++ b/zmap-no-threads/zmapNoThreads/zmapConnNoThr.c
@@ -0,0 +1,158 @@
+/*  File: zmapthrcontrol.c
+ *  Author: Ed Griffiths (edgrif@sanger.ac.uk)
+ *  Copyright (c) Sanger Institute, 2003
+ *-------------------------------------------------------------------
+ * ZMap is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
+ *-------------------------------------------------------------------
+ * 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
+ *
+ * Description: 
+ * Exported functions: See zmapConn.h
+ * HISTORY:
+ * Last edited: Dec 14 09:42 2004 (edgrif)
+ * Created: Thu Jul 24 14:37:18 2003 (edgrif)
+ * CVS info:   $Id: zmapConnNoThr.c,v 1.1 2005-02-02 11:26:26 edgrif Exp $
+ *-------------------------------------------------------------------
+ */
+
+#include <ZMap/zmapSys.h>
+#include <zmapConnNoThr_P.h>
+
+/* temp. */
+extern char *testGetData(void) ;
+
+/* Turn on/off all debugging messages for threads. */
+gboolean zmap_thr_debug_G = TRUE ;
+
+
+/* NEEDED */
+ZMapConnection zMapConnCreate(char *machine, int port, char *protocol,
+			      int timeout, char *version,
+			      char *sequence, int start, int end, GData *types,
+			      ZMapProtocolAny initial_request)
+{
+  ZMapConnection connection ;
+  int status ;
+
+  connection = g_new0(ZMapConnectionStruct, 1) ;
+
+  connection->machine = g_strdup(machine) ;
+  connection->port = port ;
+  connection->sequence = g_strdup(sequence) ;
+  connection->thread_id = (void *)connection ;
+  connection->request.state = ZMAP_REQUEST_WAIT ;
+  connection->reply.state = ZMAP_REPLY_WAIT ;
+
+  return connection ;
+}
+
+
+
+/* NEEDED */
+void zMapConnLoadData(ZMapConnection connection, gchar *data)
+{
+  connection->request.state = ZMAP_REQUEST_GETDATA ;
+
+  /* call acedb routine to get the data. */
+  connection->reply.data = testGetData() ;
+
+  connection->reply.state = ZMAP_REPLY_GOTDATA ;
+
+  return ;
+}
+
+
+
+#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
+gboolean zMapConnGetReply(ZMapConnection connection, ZMapThreadReply *state)
+{
+  gboolean got_value = TRUE ;
+  
+  *state = connection->reply.state ;
+  
+  return got_value ;
+}
+#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
+
+
+
+/* NEEDED */
+void zMapConnSetReply(ZMapConnection connection, ZMapThreadReply state)
+{
+  connection->reply.state = state ;
+
+  return ;
+}
+
+/* NEEDED */
+gboolean zMapConnGetReplyWithData(ZMapConnection connection, ZMapThreadReply *state,
+				  void **data, char **err_msg)
+{
+  gboolean got_value = TRUE ;
+  
+  *state = connection->reply.state ;
+  *data = connection->reply.data ;
+  *err_msg = connection->reply.error_msg ;
+  
+  return got_value ;
+}
+
+/* NEEDED */
+/* We need to hack this to have the process number or something like that....actually the
+ * address of the connection would do..... */
+void *zMapConnGetThreadid(ZMapConnection connection)
+{
+  return connection->thread_id ;
+}
+
+
+/* NEEDED */
+/* Kill the thread by cancelling it, as this will asynchronously we cannot release the connections
+ * resources in this call. */
+void zMapConnKill(ZMapConnection connection)
+{
+  int status ;
+
+  ZMAP_THR_DEBUG(("GUI: killing and destroying connection for thread %x\n", connection->thread_id)) ;
+
+  /* code here did a pthread_cancel only, so nothing to be done here.... */
+
+  return ;
+}
+
+
+/* NEEDED */
+/* Release the connections resources, don't do this until the slave thread has gone. */
+void zMapConnDestroy(ZMapConnection connection)
+{
+  g_free(connection->machine) ;
+  g_free(connection->sequence) ;
+
+  g_free(connection) ;
+
+  return ;
+}
+
+
+
+
+/* 
+ * ---------------------  Internal routines  ------------------------------
+ */
+
diff --git a/zmap-no-threads/zmapNoThreads/zmapConnNoThr_P.h b/zmap-no-threads/zmapNoThreads/zmapConnNoThr_P.h
new file mode 100755
index 000000000..111e3bd4c
--- /dev/null
+++ b/zmap-no-threads/zmapNoThreads/zmapConnNoThr_P.h
@@ -0,0 +1,89 @@
+/*  File: zmapConn_P.h
+ *  Author: Ed Griffiths (edgrif@sanger.ac.uk)
+ *  Copyright (c) Sanger Institute, 2003
+ *-------------------------------------------------------------------
+ * ZMap is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
+ *-------------------------------------------------------------------
+ * This file is part of the ZMap genome database package
+ * and was written by
+ *      Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk,
+ * 	Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk and
+ *	Simon Kelley (Sanger Institute, UK) srk@sanger.ac.uk
+ *
+ * Description: 
+ * Exported functions: See XXXXXXXXXXXXX.h
+ * HISTORY:
+ * Last edited: Nov 19 11:48 2003 (edgrif)
+ * Created: Thu Jul 24 14:36:08 2003 (edgrif)
+ * CVS info:   $Id: zmapConnNoThr_P.h,v 1.1 2005-02-02 11:26:27 edgrif Exp $
+ *-------------------------------------------------------------------
+ */
+#ifndef ZMAP_CONN_PRIV_H
+#define ZMAP_CONN_PRIV_H
+
+#include <glib.h>
+
+#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
+#include <ZMap/zmapSys.h>
+#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
+
+#include <ZMap/zmapConn.h>
+
+
+#define ZMAP_THR_DEBUG(ALL_ARGS_WITH_BRACKETS) \
+do { \
+     if (zmap_thr_debug_G) \
+       printf ALL_ARGS_WITH_BRACKETS ; \
+   } while (0)
+
+
+typedef struct
+{
+  ZMapThreadRequest state ;				    /* Contains request to slave. */
+} ZMapRequestStruct, *ZMapRequest ;
+
+/* Replies via a simpler mutex. */
+typedef struct
+{
+  ZMapThreadReply state ;				    /* Contains reply from slave. */
+  char *data ;						    /* May also contain data for some replies. */
+  char *error_msg ;					    /* May contain error message for when
+							       thread fails. */
+} ZMapReplyStruct, *ZMapReply ;
+
+
+
+/* The ZMapConnection, there is one per connection to a database, i.e. one per slave
+ * thread. */
+typedef struct _ZMapConnectionStruct
+{
+  /* These are read only after creation of the thread. */
+  gchar *machine ;
+  int port ;
+  gchar *sequence ;
+  char *thread_id ;					    /* will contain connect addr. */
+
+
+  /* These control the communication between the GUI thread and the connection threads,
+   * they are mutex locked and the request code makes use of the condition variable. */
+  ZMapRequestStruct request ;				    /* GUIs request. */
+  ZMapReplyStruct reply ;				    /* Slaves reply. */
+
+} ZMapConnectionStruct ;
+
+
+
+#endif /* !ZMAP_CONN_PRIV_H */
-- 
GitLab