From a217bcc04f766a3893b4207d63bc728f5dc8a73a Mon Sep 17 00:00:00 2001
From: edgrif <edgrif>
Date: Thu, 18 Mar 2004 10:40:57 +0000
Subject: [PATCH] intial versions of separated out acedb server specific code

---
 src/zmapServer/acedb/acedbServer.c   | 158 +++++++++++++++++++++++++++
 src/zmapServer/acedb/acedbServer_P.h |  45 ++++++++
 src/zmapServer/acedb/makefile        |  28 +++++
 3 files changed, 231 insertions(+)
 create mode 100755 src/zmapServer/acedb/acedbServer.c
 create mode 100755 src/zmapServer/acedb/acedbServer_P.h
 create mode 100755 src/zmapServer/acedb/makefile

diff --git a/src/zmapServer/acedb/acedbServer.c b/src/zmapServer/acedb/acedbServer.c
new file mode 100755
index 000000000..9d9ad5a4f
--- /dev/null
+++ b/src/zmapServer/acedb/acedbServer.c
@@ -0,0 +1,158 @@
+/*  File: zmapServer.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,
+ *	Simon Kelley (Sanger Institute, UK) srk@sanger.ac.uk and
+ *      Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk
+ *
+ * Description: 
+ * Exported functions: See zmapServer.h
+ * HISTORY:
+ * Last edited: Mar 18 09:54 2004 (edgrif)
+ * Created: Wed Aug  6 15:46:38 2003 (edgrif)
+ * CVS info:   $Id: acedbServer.c,v 1.1 2004-03-18 10:40:57 edgrif Exp $
+ *-------------------------------------------------------------------
+ */
+
+#include <AceConn.h>
+#include <zmapServer_P.h>
+#include <acedbServer_P.h>
+
+
+
+static gboolean createConnection(void **server_out,
+				 char *host, int port,
+				 char *userid, char *passwd, int timeout) ;
+static gboolean openConnection(void *server) ;
+static gboolean request(void *server, char *request, void **reply, int *reply_len) ;
+char *lastErrorMsg(void *server) ;
+static gboolean closeConnection(void *server) ;
+static gboolean destroyConnection(void *server) ;
+
+
+
+
+/* Compulsory routine, without this we can't do anything....returns a list of functions
+ * that can be used to contact an acedb server. The functions are only visible through
+ * this struct. */
+void acedbGetServerFuncs(ZMapServerFuncs acedb_funcs)
+{
+  acedb_funcs->create = createConnection ;
+  acedb_funcs->open = openConnection ;
+  acedb_funcs->request = request ;
+  acedb_funcs->errmsg = lastErrorMsg ;
+  acedb_funcs->close = closeConnection;
+  acedb_funcs->destroy = destroyConnection ;
+
+  return ;
+}
+
+
+
+
+/* 
+ * ---------------------  Internal routines.  ---------------------
+ */
+
+
+static gboolean createConnection(void **server_out,
+				 char *host, int port,
+				 char *userid, char *passwd, int timeout)
+{
+  gboolean result = FALSE ;
+  AcedbServer server ;
+
+  server = (AcedbServer)g_new(AcedbServerStruct, 1) ;
+  server->last_err_status = ACECONN_OK ;
+
+  if ((server->last_err_status =
+       AceConnCreate(&(server->connection), host, port, userid, passwd, 20)) == ACECONN_OK)
+    {
+      *server_out = (void *)server ;
+
+      result = TRUE ;
+    }
+
+  return result ;
+}
+
+
+static gboolean openConnection(void *server_in)
+{
+  gboolean result = FALSE ;
+  AcedbServer server = (AcedbServer)server_in ;
+
+  if ((server->last_err_status = AceConnConnect(server->connection)) == ACECONN_OK)
+    result = TRUE ;
+
+  return result ;
+}
+
+
+static gboolean request(void *server_in, char *request, void **reply, int *reply_len)
+{
+  gboolean result = FALSE ;
+  AcedbServer server = (AcedbServer)server_in ;
+
+  if ((server->last_err_status =
+       AceConnRequest(server->connection, request, reply, reply_len)) == ACECONN_OK)
+    result = TRUE ;
+
+  return result ;
+}
+
+
+/* ummm, this doesn't seem to work for aceconn...where does the status come from...???? */
+char *lastErrorMsg(void *server_in)
+{
+  AcedbServer server = (AcedbServer)server_in ;
+
+  AceConnGetErrorMsg(server->connection, server->last_err_status) ;
+
+  return NULL ;
+}
+
+
+static gboolean closeConnection(void *server_in)
+{
+  gboolean result = TRUE ;
+  AcedbServer server = (AcedbServer)server_in ;
+
+  if ((server->last_err_status = AceConnConnectionOpen(server->connection)) == ACECONN_OK)
+    {
+      if ((server->last_err_status = AceConnDisconnect(server->connection)) != ACECONN_OK)
+	result = FALSE ;
+    }
+
+  return result ;
+}
+
+static gboolean destroyConnection(void *server_in)
+{
+  gboolean result = TRUE ;
+  AcedbServer server = (AcedbServer)server_in ;
+
+  AceConnDestroy(server->connection) ;			    /* Does not fail. */
+
+  return result ;
+}
+
+
diff --git a/src/zmapServer/acedb/acedbServer_P.h b/src/zmapServer/acedb/acedbServer_P.h
new file mode 100755
index 000000000..ee79fd934
--- /dev/null
+++ b/src/zmapServer/acedb/acedbServer_P.h
@@ -0,0 +1,45 @@
+/*  File: acedbServer_P.h
+ *  Author: Ed Griffiths (edgrif@sanger.ac.uk)
+ *  Copyright (c) Sanger Institute, 2004
+ *-------------------------------------------------------------------
+ * 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
+ * originated by
+ * 	Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk,
+ *      Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk
+ *
+ * Description: 
+ * HISTORY:
+ * Last edited: Mar 18 09:44 2004 (edgrif)
+ * Created: Wed Mar 17 16:23:17 2004 (edgrif)
+ * CVS info:   $Id: acedbServer_P.h,v 1.1 2004-03-18 10:40:58 edgrif Exp $
+ *-------------------------------------------------------------------
+ */
+#ifndef ACEDB_SERVER_P_H
+#define ACEDB_SERVER_P_H
+
+/* Holds all the state we need to manage the acedb connection. */
+typedef struct _AcedbServerStruct
+{
+  AceConnection connection ;
+
+  AceConnStatus last_err_status ;			    /* Needed so we can return err mesgs. */
+} AcedbServerStruct, *AcedbServer ;
+
+
+
+#endif /* !ACEDB_SERVER_P_H */
diff --git a/src/zmapServer/acedb/makefile b/src/zmapServer/acedb/makefile
new file mode 100755
index 000000000..99609b117
--- /dev/null
+++ b/src/zmapServer/acedb/makefile
@@ -0,0 +1,28 @@
+#
+# Makes the manager part of the ZMap application.
+#
+
+
+# local macros
+SERV_PRIV_HDRS = acedbServer_P.h
+PUB_HDRS = 
+SERV_SRC = acedbServer.c
+SERV_OBJ = acedbServer.o
+
+#
+# These must all be set for the common includes to work.
+# Need to include AceConn header.
+#
+CURRENT_LIB = $(ZMAPTHR_LIB)
+CURRENT_OBJ = $(SERV_OBJ)
+CURRENT_DEP = $(PUB_HDRS) $(SERV_PRIV_HDRS)
+CURRENT_SRC = $(SERV_PRIV_HDRS) $(SERV_SRC)
+CURRENT_INC = -I.. -I$(HOME)/acedb/CODE/Ace-Conn
+
+#
+# point to common make include file which contains all the rules etc.
+#
+ROOT_DIRECTORY = ../../
+MAKE_DIR = $(ROOT_DIRECTORY)/zmapMake
+include $(MAKE_DIR)/build.make
+
-- 
GitLab