diff options
author | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 1999-02-03 12:28:51 +0000 |
---|---|---|
committer | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 1999-02-03 12:28:51 +0000 |
commit | ffbd7fd2422102c26829ef9db9b44ea6b422f0b4 (patch) | |
tree | a187459ae03e8d030e1dd696fff3c7e2319dbb89 /src | |
parent | 1a33b01d99a25b76a71671b5a199bb149ce2f3c8 (diff) |
More changes for the GH extension registration.
Tom
git-svn-id: http://svn.cactuscode.org/flesh/trunk@193 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src')
-rw-r--r-- | src/comm/CactusDefaultComm.c | 2 | ||||
-rw-r--r-- | src/comm/GHExtensions.c | 119 | ||||
-rw-r--r-- | src/include/GHExtensions.h | 5 | ||||
-rw-r--r-- | src/include/flesh.h | 2 |
4 files changed, 121 insertions, 7 deletions
diff --git a/src/comm/CactusDefaultComm.c b/src/comm/CactusDefaultComm.c index 4981c603..f4d166e0 100644 --- a/src/comm/CactusDefaultComm.c +++ b/src/comm/CactusDefaultComm.c @@ -91,7 +91,7 @@ cGH *CactusDefaultSetupGH(tFleshConfig *config, int convergence_level) thisGH->GroupData) { /* Traverse list of GH setup routines. */ - CCTK_TraverseGHExtensions(config, convergence_level, thisGH); + CCTK_SetupGHExtensions(config, convergence_level, thisGH); retval = thisGH; } diff --git a/src/comm/GHExtensions.c b/src/comm/GHExtensions.c index 188d2abe..1a866651 100644 --- a/src/comm/GHExtensions.c +++ b/src/comm/GHExtensions.c @@ -7,6 +7,7 @@ @enddesc @@*/ +#include <stdio.h> #include <stdlib.h> #include "flesh.h" @@ -21,14 +22,56 @@ static int num_extensions = 0; struct GHExtension { int number; - void *(*init)(cGH *); + void *(*SetupGH)(tFleshConfig *, int, cGH *); + int (*InitGH)(cGH *); }; +static int CheckAllExtensionsSetup(void); +static void *DummySetupGH(tFleshConfig *config, int convergence_level, cGH *GH); +static int DummyInitGH(cGH *GH); + + 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; +} + int CCTK_RegisterGHExtension(const char *name) { int return_val; @@ -47,9 +90,12 @@ int CCTK_RegisterGHExtension(const char *name) if(new_extension) { + /* Get a handle for it. */ handle = CCTK_NewHandle(&GHExtensions, name, new_extension); - new_extension->init = NULL; + /* Initialise the extension structure. */ + new_extension->InitGH = NULL; + new_extension->SetupGH = NULL; /* Remember how many extensions there are */ num_extensions++; @@ -69,7 +115,28 @@ int CCTK_RegisterGHExtension(const char *name) return handle; } -int CCTK_RegisterGHExtensionInitialiser(int handle, void *(*func)(cGH *)) +int CCTK_RegisterGHExtensionInitGH(int handle, int (*func)(cGH *)) +{ + int return_code; + struct GHExtension *extension; + + extension = CCTK_GetHandledData(GHExtensions, handle); + + if(extension) + { + extension->InitGH = func; + return_code = 1; + } + else + { + return_code = 0; + } + + return return_code; +} + +int CCTK_RegisterGHExtensionSetupGH(int handle, + void *(*func)(tFleshConfig *, int, cGH *)) { int return_code; struct GHExtension *extension; @@ -78,7 +145,7 @@ int CCTK_RegisterGHExtensionInitialiser(int handle, void *(*func)(cGH *)) if(extension) { - extension->init = func; + extension->SetupGH = func; return_code = 1; } else @@ -88,3 +155,47 @@ int CCTK_RegisterGHExtensionInitialiser(int handle, void *(*func)(cGH *)) return return_code; } + +static int CheckAllExtensionsSetup(void) +{ + int return_code; + int handle; + struct GHExtension *extension; + + return_code = 1; + + for(handle = 0; handle < num_extensions; handle++) + { + extension = (struct GHExtension *)CCTK_GetHandledData(GHExtensions, handle); + + if(!extension->SetupGH) + { + fprintf(stderr, + "Warning: GH Extension '%s' has not regidtered a SetupGH routine.\n", + CCTK_GetHandleName(GHExtensions, handle)); + extension->SetupGH=DummySetupGH; + } + + if(!extension->InitGH) + { + fprintf(stderr, + "Warning: GH Extension '%s' has not regidtered an InitGH routine.\n", + CCTK_GetHandleName(GHExtensions, handle)); + extension->SetupGH=DummySetupGH; + } + + } + + return return_code; +} + +static void *DummySetupGH(tFleshConfig *config, int convergence_level, cGH *GH) +{ + return NULL; +} + +static int DummyInitGH(cGH *GH) +{ + return 0; +} + diff --git a/src/include/GHExtensions.h b/src/include/GHExtensions.h index cafd23b4..a9e29862 100644 --- a/src/include/GHExtensions.h +++ b/src/include/GHExtensions.h @@ -17,8 +17,11 @@ extern "C" { int CCTK_RegisterGHExtension(const char *name); -int CCTK_RegisterGHExtensionInitialiser(int handle, void *(*func)(cGH *)); +int CCTK_RegisterGHExtensionInitialiser(int handle, int (*func)(cGH *)); +int CCTK_SetupGHExtensions(tFleshConfig *config, + int convergence_level, + cGH *GH); #ifdef _cplusplus } diff --git a/src/include/flesh.h b/src/include/flesh.h index 900ed1a8..cdad508c 100644 --- a/src/include/flesh.h +++ b/src/include/flesh.h @@ -49,7 +49,7 @@ typedef struct void **data; /* The extension array */ - void *extensions; + void **extensions; /* All the group data for this GH (storage, comm, etc. */ cGHGroupData *GroupData; |