Skip to content
Snippets Groups Projects
Commit e56b27ba authored by edgrif's avatar edgrif
Browse files

initial version of thread library that works by direct function calls for embedding zmap in xace

parent 4f98c099
No related branches found
No related tags found
No related merge requests found
================================================================================
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.
#
# Makes the manager part of the ZMap application.
#
# 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)
#
# point to common make include file which contains all the rules etc.
#
ROOT_DIRECTORY = ..
MAKE_DIR = $(ROOT_DIRECTORY)/zmapMake
include $(MAKE_DIR)/build.make
/* 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: Jan 22 13:47 2004 (edgrif)
* Created: Thu Jul 24 14:37:18 2003 (edgrif)
* CVS info: $Id: zmapConnNoThr.c,v 1.1 2004-03-03 12:28:43 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, char *port, char *protocol, char *sequence)
{
ZMapConnection connection ;
int status ;
connection = g_new(ZMapConnectionStruct, sizeof(ZMapConnectionStruct)) ;
connection->machine = g_strdup(machine) ;
connection->port = atoi(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)
{
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 ------------------------------
*/
/* 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 2004-03-03 12:28:43 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 */
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment