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

Remove much function from manager layer and put it into a separate ZMap

layer which manager calls. Manager now deals with the list of zmaps and
with calls to create/manage/destroy zmaps using a ZMap interface.
In particular manager does not now have an idle function to check the
status of zmap connections...this is all done within the zmap.
parent 2353c75c
No related branches found
No related tags found
No related merge requests found
......@@ -19,29 +19,27 @@
*-------------------------------------------------------------------
* 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
* Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk
*
* Description:
* Exported functions: See XXXXXXXXXXXXX.h
* Exported functions: See zmapManager.h
* HISTORY:
* Last edited: Nov 7 17:43 2003 (edgrif)
* Last edited: Nov 18 10:50 2003 (edgrif)
* Created: Thu Jul 24 16:06:44 2003 (edgrif)
* CVS info: $Id: zmapManager.c,v 1.1 2003-11-10 17:04:27 edgrif Exp $
* CVS info: $Id: zmapManager.c,v 1.2 2003-11-18 11:27:07 edgrif Exp $
*-------------------------------------------------------------------
*/
#include <zmapManager_P.h>
static void killGUI(ZMapManager zmaps, ZMapWinConn zmap) ;
static void killZMap(ZMapManager zmaps, ZMapWinConn zmap) ;
static void zmapWindowCB(void *cb_data, int reason) ;
ZMapManager zMapManagerInit(zmapAppCallbackFunc delete_func,
void *app_data)
ZMapManager zMapManagerInit(zmapAppCallbackFunc zmap_deleted_func,
void *gui_data)
{
ZMapManager manager ;
......@@ -49,38 +47,47 @@ ZMapManager zMapManagerInit(zmapAppCallbackFunc delete_func,
manager->zmap_list = NULL ;
manager->delete_zmap_guifunc = delete_func ;
manager->app_data = app_data ;
manager->gui_zmap_deleted_func = zmap_deleted_func ;
manager->gui_data = gui_data ;
return manager ;
}
/* Add a new zmap window with associated thread and all the gubbins. */
ZMapWinConn zMapManagerAdd(ZMapManager zmaps, char *machine, int port, char *sequence)
ZMap zMapManagerAdd(ZMapManager zmaps, char *machine, int port, char *sequence)
{
ZMapWinConn zmapconn ;
ZMap zmap ;
ZMapManagerCB zmap_cb ;
zmapconn = g_new(ZMapWinConnStruct, sizeof(ZMapWinConnStruct)) ;
zmapconn->connection = zMapConnCreate(machine, port, sequence) ;
zmap_cb = g_new(ZMapManagerCBStruct, sizeof(ZMapManagerCBStruct)) ;
zmap_cb->zmap_list = zmaps ;
zmap_cb->zmap = zmapconn ;
zmapconn->window = zMapWindowCreate(machine, port, sequence, zmapWindowCB, (void *)zmap_cb) ;
if ((zmap = zMapCreate((void *)zmap_cb, zmapWindowCB))
&& zMapConnect(zmap, machine, port, 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) ;
zmaps->zmap_list = g_list_append(zmaps->zmap_list, zmapconn) ;
printf("Aggghhhh, not able to create a zmap....\n") ;
}
return zmapconn ;
return zmap ;
}
void zMapManagerLoadData(ZMapWinConn zmapconn)
void zMapManagerLoadData(ZMap zmap)
{
zMapConnLoadData(zmapconn->connection) ;
/* For now I've put in a blank sequence, in the end we would like the user to be able
* to interactively set this.... */
zMapLoad(zmap, "") ;
return ;
}
......@@ -97,7 +104,7 @@ void zMapManagerLoadData(ZMapWinConn zmapconn)
* machine/port/sequence or to enter data for a new sequence etc.
*
* */
void zMapManagerReset(ZMapWinConn zmap)
void zMapManagerReset(ZMap zmap)
{
/* We need a new windows call to reset the window and blank it. */
......@@ -112,116 +119,23 @@ void zMapManagerReset(ZMapWinConn zmap)
/* Called to kill a zmap window and get the associated thread killed, this latter will be
* asynchronous. */
void zMapManagerKill(ZMapManager zmaps, ZMapWinConn zmap)
{
killGUI(zmaps, 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() */
zMapConnKill(zmap->connection) ;
return ;
}
/* This function passes through the list of connections once and checks for any replies
* from the any of the connections and acts on those replies.
* 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
* and this is possible because this routine is called from the idle function of the GUI.
/* 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 zMapManagerCheckConnections(ZMapManager zmaps)
void zMapManagerKill(ZMapManager zmaps, ZMap zmap)
{
ZMapThreadReply reply ;
if (zmaps->zmap_list)
{
GList* next ;
next = g_list_first(zmaps->zmap_list) ;
do
{
ZMapWinConn zmap ;
gboolean got_value ;
void *data = NULL ;
char *err_msg = NULL ;
/* THIS IS ALMOST CERTAINLY MESSED UP NOW..... */
zmap = (ZMapWinConn)next->data ;
zMapDestroy(zmap) ;
zmaps->zmap_list = g_list_remove(zmaps->zmap_list, zmap) ;
#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
ZMAP_DEBUG(("GUI: checking connection for thread %x\n",
zMapConnGetThreadid(zmap->connection))) ;
#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
data = NULL ;
if (!(got_value = zMapConnGetReplyWithData(zmap->connection, &reply, &data, &err_msg)))
{
printf("GUI: thread state locked, cannot access it....\n") ;
}
else
{
#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
ZMAP_DEBUG(("GUI: got state for thread %x, state = %s\n",
zMapConnGetThreadid(zmap->connection),
zmapVarGetStringState(reply))) ;
#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
if (reply == ZMAP_REPLY_WAIT)
{
; /* nothing to do. */
}
else if (reply == ZMAP_REPLY_GOTDATA)
{
ZMAP_DEBUG(("GUI: got data for thread %x\n",
zMapConnGetThreadid(zmap->connection))) ;
zMapConnSetReply(zmap->connection, ZMAP_REPLY_WAIT) ;
/* Signal the ZMap that there is work to be done. */
zMapWindowSignalData(zmap->window, data) ;
}
else if (reply == ZMAP_REPLY_DIED)
{
/* This means the thread has failed for some reason and we should clean up. */
ZMAP_DEBUG(("GUI: thread %x has died so cleaning up....\n",
zMapConnGetThreadid(zmap->connection))) ;
if (err_msg && *err_msg)
zmapGUIShowMsg(err_msg) ;
next = g_list_next(next) ; /* Move next pointer _before_ we
remove the current zmap otherwise
what happens if this is the last
one...... */
zmaps->zmap_list = g_list_remove(zmaps->zmap_list, zmap) ;
killZMap(zmaps, zmap) ;
}
else if (reply == ZMAP_REPLY_CANCELLED)
{
/* This means the thread was cancelled so we should clean up..... */
ZMAP_DEBUG(("GUI: thread %x has been cancelled so cleaning up....\n",
zMapConnGetThreadid(zmap->connection))) ;
next = g_list_next(next) ; /* Move next pointer _before_ we
remove the current zmap otherwise
what happens if this is the last
one...... */
zmaps->zmap_list = g_list_remove(zmaps->zmap_list, zmap) ;
killZMap(zmaps, zmap) ;
}
}
} while ((next = g_list_next(next))) ;
}
(*(zmaps->gui_zmap_deleted_func))(zmaps->gui_data, zmap) ;
return ;
}
......@@ -235,39 +149,6 @@ void zMapManagerCheckConnections(ZMapManager zmaps)
*/
/* 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.
* */
static void killGUI(ZMapManager zmaps, ZMapWinConn zmap)
{
(*(zmaps->delete_zmap_guifunc))(zmaps->app_data, zmap) ;
zMapWindowDestroy(zmap->window) ;
zmap->window = NULL ;
return ;
}
/* destroys the window if this has not happened yet and then destroys the slave thread
* control block.
*/
static void killZMap(ZMapManager zmaps, ZMapWinConn zmap)
{
if (zmap->window != NULL)
{
killGUI(zmaps, zmap) ;
}
zMapConnDestroy(zmap->connection) ;
return ;
}
/* Gets called when zmap Window needs Manager to do something. */
......@@ -298,8 +179,14 @@ static void zmapWindowCB(void *cb_data, int reason)
}
#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 */
return ;
}
......
......@@ -19,24 +19,26 @@
*-------------------------------------------------------------------
* 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
* Rob Clack (Sanger Institute, UK) rnc@sanger.ac.uk
*
* Description:
* Exported functions: See XXXXXXXXXXXXX.h
* HISTORY:
* Last edited: Nov 7 17:07 2003 (edgrif)
* Last edited: Nov 18 10:51 2003 (edgrif)
* Created: Thu Jul 24 14:39:06 2003 (edgrif)
* CVS info: $Id: zmapManager_P.h,v 1.1 2003-11-10 17:04:28 edgrif Exp $
* CVS info: $Id: zmapManager_P.h,v 1.2 2003-11-18 11:27:07 edgrif Exp $
*-------------------------------------------------------------------
*/
#ifndef ZMAP_MANAGER_P_H
#define ZMAP_MANAGER_P_H
#include <glib.h>
#include <ZMap/zmapConn.h>
/* THERE IS STUFF IN HERE WHICH SHOULD BE IN ZMAP.H */
#include <ZMap/zmapWindow.h>
#include <ZMap/ZMap.h>
#include <ZMap/zmapManager.h>
......@@ -45,36 +47,19 @@ typedef struct _ZMapManagerStruct
{
GList *zmap_list ;
zmapAppCallbackFunc delete_zmap_guifunc ;
void *app_data ;
zmapAppCallbackFunc gui_zmap_deleted_func ;
void *gui_data ;
} ZMapManagerStruct ;
/* Each ZMap has window data and connection data, the intent is that the window code knows about
* the window data and the connection data knows about the connection data.... */
typedef struct _ZMapWinConnStruct
{
ZMapWindow window ;
ZMapConnection connection ;
} ZMapWinConnStruct ;
typedef struct _ZMapManagerCBStruct
{
ZMapManager zmap_list ;
ZMapWinConn zmap ;
} ZMapManagerCBStruct, *ZMapManagerCB ;
void zmapCleanUpConnection(ZMapConnection connection, void *cleanupdata) ;
void zmapSignalData(ZMapConnection connection, void *cleanupdata) ;
ZMap zmap ;
} ZMapManagerCBStruct, *ZMapManagerCB ;
......
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