diff options
author | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 1999-02-02 13:20:04 +0000 |
---|---|---|
committer | goodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 1999-02-02 13:20:04 +0000 |
commit | 9aa201144159a3f62dc2b4e8a9dfd7db90cfa1be (patch) | |
tree | 6f53160383e599ed395c26eee1c154195fb806d7 /src/comm | |
parent | 746ed41ca317127998f04103fdd6a157e14b21e5 (diff) |
Written RegisterGHExtension.
Tom
git-svn-id: http://svn.cactuscode.org/flesh/trunk@172 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/comm')
-rw-r--r-- | src/comm/GHExtensions.c | 68 |
1 files changed, 65 insertions, 3 deletions
diff --git a/src/comm/GHExtensions.c b/src/comm/GHExtensions.c index 96a0a247..7cc2d098 100644 --- a/src/comm/GHExtensions.c +++ b/src/comm/GHExtensions.c @@ -7,10 +7,22 @@ @enddesc @@*/ +#include <stdlib.h> + #include "flesh.h" +#include "StoreHandledData.h" static char *rcsid = "$Id$"; +static cHandledData *GHExtensions = NULL; +static int num_extensions = 0; + +struct GHExtension +{ + int number; + void *(*init)(cGH *); +}; + int CCTK_TraverseGHExtensions(cGH *GH, const char *when) { return 0; @@ -18,10 +30,60 @@ int CCTK_TraverseGHExtensions(cGH *GH, const char *when) int CCTK_RegisterGHExtension(cGH *GH, const char *name) { - return -1; + int return_val; + + int handle; + + struct GHExtension *new_extension; + + /* Check that the extension hasn't already been registered */ + handle = CCTK_GetHandle(GHExtensions, name, NULL); + + if(handle < 0) + { + /* New extension. */ + new_extension = (struct GHExtension *)malloc(sizeof(struct GHExtension)); + + if(new_extension) + { + handle = CCTK_NewHandle(&GHExtensions, name, new_extension); + + new_extension->init = NULL; + + /* Remember how many extensions there are */ + num_extensions++; + } + else + { + /* Memory failure. */ + handle = -2; + } + } + else + { + /* Extension already exists. */ + handle = -1; + } + + return handle; } -int CCTK_RegisterGHExtensionInitialiser(int handle, void (*func)()) +int CCTK_RegisterGHExtensionInitialiser(int handle, void *(*func)(cGH *)) { - return -1; + int return_code; + struct GHExtension *extension; + + extension = CCTK_GetHandledData(GHExtensions, handle); + + if(extension) + { + extension->init = func; + return_code = 1; + } + else + { + return_code = 0; + } + + return return_code; } |