From b0b2c2fab4f256a500334af161adc87babf30d76 Mon Sep 17 00:00:00 2001 From: goodale Date: Sat, 16 Sep 2000 00:09:56 +0000 Subject: Adding stuff to parameter page. Tom git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPD/trunk@19 1faa4e14-9dd3-4be0-9f0e-ffe519881164 --- src/Content.c | 289 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 236 insertions(+), 53 deletions(-) (limited to 'src/Content.c') diff --git a/src/Content.c b/src/Content.c index 9681a0d..cdcc1e0 100644 --- a/src/Content.c +++ b/src/Content.c @@ -16,6 +16,9 @@ #include "cctk.h" +#include "cctk_Parameter.h" +#include "cctk_ActiveThorns.h" + #include "util_String.h" #include "http_Request.h" @@ -43,8 +46,10 @@ struct httpStaticPage static int RegisterImages(void); +static int RegisterParameterPages(void); static int MainPage(cGH *cctkGH, httpRequest *request, void *data); -static int ParameterPage(cGH *cctkGH, httpRequest *request, void *data); +static int MainParameterPage(cGH *cctkGH, httpRequest *request, void *data); +static int ThornParameterPage(cGH *cctkGH, httpRequest *request, void *data); static int ShowStaticPage(cGH *cctkGH, httpRequest *request, void *data); @@ -89,9 +94,9 @@ int HTTP_RegisterPages(void) /* Register the master page. */ HTTP_RegisterPage("/index.html", MainPage, NULL); - /* Register a duff parameters page */ - - HTTP_RegisterPage("/parameters", ParameterPage, NULL); + /* Register parameter stuff */ + + RegisterParameterPages(); /* Register a test page */ HTTP_RegisterPage("/test_page", TestPage, NULL); @@ -132,45 +137,36 @@ static int CompareStrings(const void *string1, const void *string2) ******************************************************************************/ -static const char *cactus_mainheader = " \ -\n \ -\n \ -
\ -\"Cactus\" \ - \ -
\ -\n"; - -static const char *cactus_header = " \ -\n \ -\n \ -
\ - \ -
\ -\n"; - -static const char *cactus_footer = \ -"
" \ -"\n \ -
\n \ -
\n \ -\n \ -Cactus Home Page
\n\ -Cactus Web Interface by The Cactus Team
\n\ -
\n"; - -static const char base_page[] = -"\nTest Page for Tom's trivial web server\ -\n \ -
\ -\"Cactus\" \ - \ -"; +static const char *cactus_mainheader = +"\n" +"\n" +"
" +"\"Cactus\"" +"" +"
" +"\n"; + +static const char *cactus_header = +"\n" +"\n" +"
" +"" +"
" +"\n"; + +static const char *cactus_footer = +"
" +"\n" +"
\n" +"
\n" +"\n" +"Cactus Home Page
\n" +"Cactus Web Interface by The Cactus Team
\n" +"
\n"; + /*@@ @routine MainPage @@ -334,11 +330,45 @@ static int MainPage(cGH *cctkGH, httpRequest *request, void *data) /****************************************************************************** - ***************************** Parameter Page ********************************* + ***************************** Parameter Pages ******************************** ******************************************************************************/ + +static int RegisterParameterPages(void) +{ + int i; + const char *thorn; + char pagename[27+20]; /* Thorns have maximum length */ + char *namecopy; + + /* Two ways to do this - can either just have one function + * registered as /Parameters which then checks request->residual, + * to see what the actual accessed page is, or can register a + * main page and one for each thorn. + * Choose the latter for the mo to keep functions smaller, and also + * since the compiled thorn list is static at the moment. + */ + + HTTP_RegisterPage("/Parameters/index.html", MainParameterPage, NULL); + + for (i = 0; i < CCTK_NumCompiledThorns (); i++) + { + thorn = CCTK_CompiledThorn(i); + + sprintf(pagename,"/Parameters/%s", thorn); + + namecopy = Util_Strdup(thorn); + + HTTP_RegisterPage(pagename, ThornParameterPage, namecopy); + } + + return 0; +} + + + /*@@ - @routine ParameterPage + @routine MainParameterPage @date Wed Sep 13 23:47:43 2000 @author Tom Goodale @desc @@ -351,10 +381,12 @@ static int MainPage(cGH *cctkGH, httpRequest *request, void *data) @endhistory @@*/ -static int ParameterPage(cGH *cctkGH, httpRequest *request, void *data) +static int MainParameterPage(cGH *cctkGH, httpRequest *request, void *data) { int retval; char message[4098]; + int i; + const char *thorn; /* Status message */ strcpy(message,"HTTP/1.0 200 OK\r\n"); @@ -367,23 +399,174 @@ static int ParameterPage(cGH *cctkGH, httpRequest *request, void *data) HTTP_Write(request, message, strlen(message)); /* Start the page */ - strcpy(message,"Running CACTUS Status Information\n"); - + strcpy(message, "Cactus Parameters Request\n"); + strcat(message, cactus_header); + strcat(message,""); HTTP_Write(request, message, strlen(message)); - /* Write out the main header part */ - HTTP_Write(request, cactus_header, strlen(cactus_header)); + strcpy(message, "
"); + HTTP_Write(request, message, strlen(message)); - /* This is just a test to see what the actual page requested was. */ - sprintf(message, "Residual is '%s'\n", request->residual); + strcpy(message, + "

Check/Modify Parameters

\n" + "
[This Simulation Homepage]
\n" + "

From this page you can check the values \n" + "of all parameters for the \n" + "simulation, and modify any parameters which have been designated as steerable

\n" + "

Parameters can be viewed for all Active Thorns, that is, for thorns which \n" + "have been activated in the parameter file for the simulation. \n" + "Select one of the active thorns for this simulation from the list below to \n" + "view all of its parameters

\n" + "

Steerable parameters can be identified by the presence of a form input box, \n" + "to change the value of a parameter, simply edit the value in the box and press \n" + " the submit button to register the new values.

\n" + "" + "\n"); HTTP_Write(request, message, strlen(message)); + for (i = 0; i < CCTK_NumCompiledThorns (); i++) + { + thorn = CCTK_CompiledThorn (i); + + if (CCTK_IsThornActive (thorn)) + { + sprintf(message, + "\n" + "", + thorn, thorn,CCTK_ThornImplementation(thorn)); + HTTP_Write(request, message, strlen(message)); + + } + } + + strcpy(message,"
Thorn NameImplementation
%s%s
"); + HTTP_Write(request, message, strlen(message)); + /* Write out the footer part. */ retval = HTTP_Write(request, cactus_footer, strlen(cactus_footer)); - /* retval = HTTP_Write(request, base_page, strlen(base_page)); */ + return retval; +} + +static int ThornParameterPage(cGH *cctkGH, httpRequest *request, void *data) +{ + int retval; + char message[4098]; + int i; + const char *thorn; + int first; + const cParamData *pData; + char *value; + const char *prefix; + + thorn = (const char *)data; + + /* Status message */ + strcpy(message,"HTTP/1.0 200 OK\r\n"); + + HTTP_Write(request, message, strlen(message)); + + /* Content-Type */ + strcpy(message,"Content-Type: text/html\r\n\r\n"); + + HTTP_Write(request, message, strlen(message)); + + /* Start the page */ + sprintf(message, "Cactus Parameters Request : %s\n", thorn); + strcat(message, cactus_header); + strcat(message,""); + HTTP_Write(request, message, strlen(message)); + + strcpy(message, "
"); + HTTP_Write(request, message, strlen(message)); + + if (!CCTK_IsThornActive(thorn)) + { + sprintf(message,"

Thorn %s is not active !!!

\n",thorn); + HTTP_Write(request, message, strlen(message)); + } + else + { + strcpy(message,"
"); + HTTP_Write(request, message, strlen(message)); + + /* Send table of available parameters for given thorn */ + /* Steerable parameters can be edited in a FORM. */ + sprintf(message, + "

Check/Modify Parameters for Thorn %s

\n", + thorn); + strcat(message, + "
[This Simulation Homepage]
\n" + "

Steerable parameters can be identified by the presence of a form input box, \n" + "to change the value of a parameter, simply edit the value in the box and press \n" + " the submit button to register the new values.

\n" + "

Return to active thorn list

\n" + "\n"); + + HTTP_Write(request, message, strlen(message)); + + sprintf(message,"\n", thorn); + HTTP_Write(request, message, strlen(message)); + + /* Walk through all parameters of given implementation. */ + first = 1; + + while(CCTK_ParameterWalk(first, thorn, NULL, &pData) == 0) + { + first = 0; + //strcpy(message,""); + strcpy(message,""); + + value = CCTK_ParameterValString (pData->name, pData->thorn); + if(value) + { + if (pData->scope == SCOPE_PRIVATE) + { + prefix = pData->thorn; + } + else + { + prefix = CCTK_ThornImplementation (pData->thorn); + } + + if (pData->steerable == CCTK_STEERABLE_ALWAYS) + { + sprintf(message, + "%s" + "\n", + message,prefix, pData->name, pData->name, value); + } + else + { + sprintf(message, + "%s" + "\n", + message, prefix,pData->name, value); + } + free (value); + } + HTTP_Write(request, message, strlen(message)); + + } + + strcpy(message, + "\n" + "
%s::%s" + "
%s::%s%s

\n" + "\n"); + HTTP_Write(request, message, strlen(message)); + + } + + strcpy(message,"
"); + + HTTP_Write(request, message, strlen(message)); + + /* Write out the footer part. */ + + retval = HTTP_Write(request, cactus_footer, strlen(cactus_footer)); return retval; } -- cgit v1.2.3