diff options
author | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 1999-02-03 13:59:56 +0000 |
---|---|---|
committer | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 1999-02-03 13:59:56 +0000 |
commit | 50f5ef75c88d9a6345e7b82c9c3833c67c59f0d6 (patch) | |
tree | 958511a3fe69a91c80093d73057d6c8c9565f774 | |
parent | ffbd7fd2422102c26829ef9db9b44ea6b422f0b4 (diff) |
Some new functions, some reorganisation, more grdoc, and comments.
Tom
git-svn-id: http://svn.cactuscode.org/flesh/trunk@194 17b73243-c579-4c4c-a9d2-2d5706c11dac
-rw-r--r-- | src/comm/GHExtensions.c | 379 | ||||
-rw-r--r-- | src/include/GHExtensions.h | 11 |
2 files changed, 344 insertions, 46 deletions
diff --git a/src/comm/GHExtensions.c b/src/comm/GHExtensions.c index 1a866651..f5ef4693 100644 --- a/src/comm/GHExtensions.c +++ b/src/comm/GHExtensions.c @@ -14,64 +14,66 @@ #include "GHExtensions.h" #include "StoreHandledData.h" + static char *rcsid = "$Id$"; + +/* Local data holding info on extensions..*/ + static cHandledData *GHExtensions = NULL; static int num_extensions = 0; +/* The GH extension structure. + * This contains pointers to functions which the extension requires. + * + * To add a new function, you must: + * + * a) Add it to this structure + * b) Initialise it to NULL in CCTK_RegisterGHExtension + * c) Check its value in CheckAllExtensionsSetup + * d) Provide a dummy function for CheckAllExtensionsSetup to use + * e) Provide a registration function. + * f) Add a prototype for the registration function to GHExtensions.h + */ struct GHExtension { - int number; void *(*SetupGH)(tFleshConfig *, int, cGH *); int (*InitGH)(cGH *); + int (*rfrTraverseGH)(cGH *, int); }; + +/* Function which checks that all the functions on all extensions have been + * filled in. + */ static int CheckAllExtensionsSetup(void); + +/* Dummy function prototypes. */ + static void *DummySetupGH(tFleshConfig *config, int convergence_level, cGH *GH); static int DummyInitGH(cGH *GH); +static int DummyrfrTraverseGH(cGH *GH, int rfrpoint); -int CCTK_TraverseGHExtensions(cGH *GH, const char *when) -{ - return 0; -} +/************************************************************************** + ************************************************************************** + **************************************************************************/ -int CCTK_SetupGHExtensions(tFleshConfig *config, - int convergence_level, - cGH *GH) -{ - int return_code; - int handle; - struct GHExtension *extension; - - if(CheckAllExtensionsSetup()) - { - GH->extensions = (void **)malloc(num_extensions*sizeof(void *)); - if(GH->extensions) - { - for(handle = 0; handle < num_extensions; handle++) - { - extension = (struct GHExtension *)CCTK_GetHandledData(GHExtensions, handle); - GH->extensions[handle] = extension->SetupGH(config, - convergence_level, - GH); - } - return_code = 0; - } - else - { - return_code = 1; - } - } - else - { - return_code = 2; - } - - return return_code; -} + /*@@ + @routine CCTK_RegisterGHExtension + @date Wed Feb 3 13:33:09 1999 + @author Tom Goodale + @desc + Registers a new GH extension. + @enddesc + @calls + @calledby + @history + + @endhistory +@@*/ int CCTK_RegisterGHExtension(const char *name) { int return_val; @@ -96,6 +98,7 @@ int CCTK_RegisterGHExtension(const char *name) /* Initialise the extension structure. */ new_extension->InitGH = NULL; new_extension->SetupGH = NULL; + new_extension->rfrTraverseGH = NULL; /* Remember how many extensions there are */ num_extensions++; @@ -115,11 +118,68 @@ int CCTK_RegisterGHExtension(const char *name) return handle; } +/*************************************************************************** + * + * Function Registration Routines. + * + ***************************************************************************/ + + /*@@ + @routine CCTK_RegisterGHExtensionSetupGH + @date Wed Feb 3 13:34:12 1999 + @author Tom Goodale + @desc + Registers a function to setup a GH extension. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +int CCTK_RegisterGHExtensionSetupGH(int handle, + void *(*func)(tFleshConfig *, int, cGH *)) +{ + int return_code; + struct GHExtension *extension; + + /* Get the extension. */ + extension = CCTK_GetHandledData(GHExtensions, handle); + + if(extension) + { + extension->SetupGH = func; + return_code = 1; + } + else + { + return_code = 0; + } + + return return_code; +} + + /*@@ + @routine CCTK_RegisterGHExtensionInitGH + @date Wed Feb 3 13:33:36 1999 + @author Tom Goodale + @desc + Registers a GH extension initialisation routine. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ int CCTK_RegisterGHExtensionInitGH(int handle, int (*func)(cGH *)) { int return_code; struct GHExtension *extension; + /* Get the extension. */ extension = CCTK_GetHandledData(GHExtensions, handle); if(extension) @@ -135,17 +195,31 @@ int CCTK_RegisterGHExtensionInitGH(int handle, int (*func)(cGH *)) return return_code; } -int CCTK_RegisterGHExtensionSetupGH(int handle, - void *(*func)(tFleshConfig *, int, cGH *)) + /*@@ + @routine CCTK_RegisterGHExtensionrfrTraverseGH + @date Wed Feb 3 14:31:20 1999 + @author Tom Goodale + @desc + Registers a GH extension rfr traversal routine routine. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +int CCTK_RegisterGHExtensionrfrTraverseGH(int handle, int (*func)(cGH *, int)) { int return_code; struct GHExtension *extension; + /* Get the extension. */ extension = CCTK_GetHandledData(GHExtensions, handle); if(extension) { - extension->SetupGH = func; + extension->rfrTraverseGH = func; return_code = 1; } else @@ -156,6 +230,148 @@ int CCTK_RegisterGHExtensionSetupGH(int handle, return return_code; } + +/*************************************************************************** + * + * Function Calling Routines. + * + ***************************************************************************/ + + /*@@ + @routine CCTK_SetupGHExtensions + @date Wed Feb 3 13:32:26 1999 + @author Tom Goodale + @desc + Sets up all registered GH extensions on a GH. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +int CCTK_SetupGHExtensions(tFleshConfig *config, + int convergence_level, + cGH *GH) +{ + int return_code; + int handle; + struct GHExtension *extension; + + if(CheckAllExtensionsSetup()) + { + /* Create GHExtension array on the GH. */ + GH->extensions = (void **)malloc(num_extensions*sizeof(void *)); + + if(GH->extensions) + { + for(handle = 0; handle < num_extensions; handle++) + { + /* Call the SetupGH routines for each extension. */ + extension = (struct GHExtension *)CCTK_GetHandledData(GHExtensions, handle); + GH->extensions[handle] = extension->SetupGH(config, + convergence_level, + GH); + } + return_code = 0; + } + else + { + return_code = 1; + } + } + else + { + return_code = 2; + } + + return return_code; +} + + + + + + /*@@ + @routine CCTK_InitGHExtensions + @date Wed Feb 3 14:12:18 1999 + @author Tom Goodale + @desc + Calls the initialisation routine for a GH extension. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +int CCTK_InitGHExtensions(cGH *GH) +{ + int handle; + struct GHExtension *extension; + + for(handle = 0; handle < num_extensions; handle++) + { + extension = (struct GHExtension *)CCTK_GetHandledData(GHExtensions, handle); + extension->InitGH(GH); + } + + return 0; +} + + + /*@@ + @routine CCTK_rfrTraverseGHExtensions + @date Wed Feb 3 14:16:17 1999 + @author Tom Goodale + @desc + Calls the routines which an extension needs called at an rfr traversal. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +int CCTK_rfrTraverseGHExtensions(cGH *GH, int rfrpoint) +{ + int handle; + struct GHExtension *extension; + + for(handle = 0; handle < num_extensions; handle++) + { + extension = (struct GHExtension *)CCTK_GetHandledData(GHExtensions, handle); + extension->rfrTraverseGH(GH, rfrpoint); + } + + return 0; +} + + +/*************************************************************************** + * + * Checking routines + * + ***************************************************************************/ + + + /*@@ + @routine CheckAllExtensionsSetup + @date Wed Feb 3 13:34:58 1999 + @author Tom Goodale + @desc + Checks the state of all extensions. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ static int CheckAllExtensionsSetup(void) { int return_code; @@ -164,24 +380,40 @@ static int CheckAllExtensionsSetup(void) return_code = 1; + /* Check all registered extensions. */ for(handle = 0; handle < num_extensions; handle++) { extension = (struct GHExtension *)CCTK_GetHandledData(GHExtensions, handle); + /* Check that each function has been registered. + * Print a warning if not, and then register a dummy function. + */ + + /* SetupGH */ if(!extension->SetupGH) { fprintf(stderr, - "Warning: GH Extension '%s' has not regidtered a SetupGH routine.\n", + "Warning: GH Extension '%s' has not registered a SetupGH routine.\n", CCTK_GetHandleName(GHExtensions, handle)); extension->SetupGH=DummySetupGH; } + /* InitGH */ if(!extension->InitGH) { fprintf(stderr, - "Warning: GH Extension '%s' has not regidtered an InitGH routine.\n", + "Warning: GH Extension '%s' has not registered an InitGH routine.\n", CCTK_GetHandleName(GHExtensions, handle)); - extension->SetupGH=DummySetupGH; + extension->InitGH=DummyInitGH; + } + + /* rfrTraverse */ + if(!extension->rfrTraverseGH) + { + fprintf(stderr, + "Warning: GH Extension '%s' has not registered an rfrTraverseGH routine.\n", + CCTK_GetHandleName(GHExtensions, handle)); + extension->rfrTraverseGH=DummyrfrTraverseGH; } } @@ -189,13 +421,70 @@ static int CheckAllExtensionsSetup(void) return return_code; } + +/************************************************************************ + * + * Dummy functions. Registered if no real function registered. + * + ************************************************************************/ + + + /*@@ + @routine DummySetupGH + @date Wed Feb 3 13:36:52 1999 + @author Tom Goodale + @desc + Dummy for SetupGH functions. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ static void *DummySetupGH(tFleshConfig *config, int convergence_level, cGH *GH) { return NULL; } + + /*@@ + @routine DummyInitGH + @date Wed Feb 3 13:37:31 1999 + @author Tom Goodale + @desc + Dummy for InitGH functions. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ static int DummyInitGH(cGH *GH) { return 0; } + + /*@@ + @routine DummyrfrTraverseGH + @date Wed Feb 3 14:17:57 1999 + @author Tom Goodale + @desc + Dummy for rfrTraverseGH functions. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +static int DummyrfrTraverseGH(cGH *GH, int rfrpoint) +{ + return 0; +} + diff --git a/src/include/GHExtensions.h b/src/include/GHExtensions.h index a9e29862..a6542c01 100644 --- a/src/include/GHExtensions.h +++ b/src/include/GHExtensions.h @@ -17,12 +17,21 @@ extern "C" { int CCTK_RegisterGHExtension(const char *name); -int CCTK_RegisterGHExtensionInitialiser(int handle, int (*func)(cGH *)); +int CCTK_RegisterGHExtensionSetupGH(int handle, + void *(*func)(tFleshConfig *, int, cGH *)); + +int CCTK_RegisterGHExtensionInitGH(int handle, int (*func)(cGH *)); + +int CCTK_RegisterGHExtensionrfrTraverseGH(int handle, int (*func)(cGH *, int)); int CCTK_SetupGHExtensions(tFleshConfig *config, int convergence_level, cGH *GH); +int CCTK_InitGHExtensions(cGH *GH); + +int CCTK_rfrTraverseGHExtensions(cGH *GH, int rfrpoint); + #ifdef _cplusplus } #endif |