Changeset 5356 for trunk/psModules/src/config
- Timestamp:
- Oct 17, 2005, 1:37:11 PM (21 years ago)
- Location:
- trunk/psModules/src/config
- Files:
-
- 2 deleted
- 1 edited
-
pmConfig.c (modified) (14 diffs)
-
psAdditionals.c (deleted)
-
psAdditionals.h (deleted)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfig.c
r5355 r5356 3 3 * @author PAP, IfA 4 4 * 5 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $6 * @date $Date: 2005-10-17 2 1:34:12$5 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2005-10-17 23:37:11 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 13 13 #include <assert.h> 14 14 #include "pslib.h" 15 #include "psAdditionals.h"15 //#include "psAdditionals.h" 16 16 #include "pmConfig.h" 17 17 18 // XXX: These comments should have PS-specific prefixes. 19 #define PS_SITE "PS_SITE" // Name of the environment variable containing the site config file 20 #define DEFAULT_SITE "ipprc.config" // Default site config file 18 #define PS_SITE "PS_SITE" // Name of the environment variable containing the site config file 19 #define PS_DEFAULT_SITE "ipprc.config" // Default site config file 21 20 22 21 … … 41 40 description, name); 42 41 } 43 if (! *config) {42 if (!*config) { 44 43 psError(PS_ERR_IO, false, "Unable to read %s configuration from %s\n", 45 44 description, name); 46 45 return false; 47 46 } 47 48 48 return true; 49 49 } 50 50 51 51 52 52 /****************************************************************************** 53 pmConfigRead(**site, **camera, **recipe, *argc, **argv, char *recipeName) 54 55 XXX: The log/trace command line options (as processed by psArgumentVerbosity) 56 must take precedence override the values set here. This must be, somehow, 57 coded. 58 *****************************************************************************/ 53 59 bool pmConfigRead( 54 psMetadata **site, psMetadata **camera, 60 psMetadata **site, 61 psMetadata **camera, 55 62 psMetadata **recipe, 56 63 int *argc, … … 76 83 // First, try command line 77 84 // 78 int argNum = 0; 79 if ((argNum = psArgumentGet(*argc, argv, "-site"))) { 80 (void)psArgumentRemove(argNum, argc, argv); 85 psS32 argNum = psArgumentGet(*argc, argv, "-site"); 86 if (argNum != 0) { 87 // 88 // We remove the "-site" argument from argv. Then 89 // we look for the next argument, which should be the filename, and 90 // remove it as well. 91 // 92 psArgumentRemove(argNum, argc, argv); 81 93 if (argNum >= *argc) { 82 94 psLogMsg(__func__, PS_LOG_WARN, … … 84 96 } else { 85 97 siteName = argv[argNum]; 86 (void)psArgumentRemove(argNum, argc, argv); 87 } 88 } 89 98 psArgumentRemove(argNum, argc, argv); 99 } 100 } 90 101 // 91 102 // Next, try environment variable 92 103 // 93 if (! siteName) {104 if (!siteName) { 94 105 siteName = getenv(PS_SITE); 95 106 } … … 99 110 // 100 111 bool cleanupSiteName = false; // Do I have to psFree siteName? 101 if (! siteName) {102 siteName = psStringCopy( DEFAULT_SITE);112 if (!siteName) { 113 siteName = psStringCopy(PS_DEFAULT_SITE); 103 114 cleanupSiteName = true; 104 115 } 105 116 106 if (! readConfig(site, siteName, "site")) { 107 if (cleanupSiteName) { 108 psFree(siteName); 109 } 117 // 118 // We have the connfiguration filename; now we read and parse the config 119 // file and store in psMetadata struct site. 120 // 121 if (!readConfig(site, siteName, "site")) { 110 122 return false; 111 123 } 112 113 114 // 115 // Next is the camera configuration 116 // 117 if ((argNum = psArgumentGet(*argc, argv, "-camera"))) { 118 (void)psArgumentRemove(argNum, argc, argv); 124 if (cleanupSiteName) { 125 psFree(siteName); 126 } 127 128 129 // 130 // Next, we do a similar thing for the recipe configuration file. The 131 // file is read and parsed into psMetadata struct "recipe". 132 // 133 // 134 argNum = psArgumentGet(*argc, argv, "-recipe"); 135 if (argNum > 0) { 136 psArgumentRemove(argNum, argc, argv); 137 if (argNum >= *argc) { 138 psLogMsg(__func__, PS_LOG_WARN, 139 "-recipe command-line switch provided without the required filename --- ignored.\n"); 140 } else { 141 psArgumentRemove(argNum, argc, argv); 142 readConfig(recipe, argv[argNum], "recipe"); 143 } 144 } 145 // Or, load the recipe from the camera file, if appropriate 146 if (! *recipe && *camera && recipeName) { 147 *recipe = pmConfigRecipeFromCamera(*camera, recipeName); 148 } 149 150 151 // 152 // Next, we do a similar thing for the camera configuration file. The 153 // file is read and parsed into psMetadata struct "camera". 154 // 155 argNum = psArgumentGet(*argc, argv, "-camera"); 156 if (argNum > 0) { 157 psArgumentRemove(argNum, argc, argv); 119 158 if (argNum >= *argc) { 120 159 psLogMsg(__func__, PS_LOG_WARN, 121 160 "-camera command-line switch provided without the required filename --- ignored.\n"); 122 161 } else { 123 (void)psArgumentRemove(argNum, argc, argv); 124 (void)readConfig(camera, argv[argNum], "camera"); 125 } 126 } 127 128 // 129 // And then the recipe configuration 130 // 131 if ((argNum = psArgumentGet(*argc, argv, "-recipe"))) { 132 (void)psArgumentRemove(argNum, argc, argv); 133 if (argNum >= *argc) { 134 psLogMsg(__func__, PS_LOG_WARN, 135 "-recipe command-line switch provided without the required filename --- ignored.\n"); 136 } else { 137 (void)psArgumentRemove(argNum, argc, argv); 138 (void)readConfig(recipe, argv[argNum], "recipe"); 139 } 140 } 141 // Or, load the recipe from the camera file, if appropriate 142 if (! *recipe && *camera && recipeName) { 143 *recipe = pmConfigRecipeFromCamera(*camera, recipeName); 144 } 145 146 147 // 148 // Now we can look into the site configuration and do the required stuff 162 psArgumentRemove(argNum, argc, argv); 163 readConfig(camera, argv[argNum], "camera"); 164 } 165 } else { 166 // XXX: Not sure is this is correct. 167 *camera = NULL; 168 } 169 170 171 // 172 // We now have the config, camera, and recipe files parsed and stored in 173 // metadata. Now, we can look into the site configuration and do 174 // the required stuff. 149 175 // 150 176 bool mdok = true; // Status of MD lookup result 151 psString timeName = psMetadataLookupString(&mdok, *site, "TIME"); // Name of time file 177 178 // 179 // If TIME is specified in the configuration file, then we must initialize 180 // with a call to psTimeInitialize. 181 // 182 psString timeName = psMetadataLookupStr(&mdok, *site, "TIME"); 152 183 if (mdok && timeName) { 153 184 psTrace(__func__, 7, "Initialising psTime with file %s\n", timeName); 154 #ifdef PRODUCTION 155 185 // XXX: PAP had a call to psLibInit is PRODUCTION not set. Why? 156 186 psTimeInitialize(timeName); 157 #else158 159 psLibInit(timeName); 160 #endif161 162 }163 164 int logLevel = psMetadataLookupS32(&mdok, *site, "LOGLEVEL"); // Logging level187 } 188 189 190 // 191 // If LOGLEVEL is specified in the configuration file, then we must initialize 192 // with a call to psLogSetLevel(). 193 // 194 int logLevel = psMetadataLookupS32(&mdok, *site, "LOGLEVEL"); 165 195 if (mdok && logLevel >= 0) { 166 196 psTrace(__func__, 7, "Setting log level to %d\n", logLevel); … … 168 198 } 169 199 170 psString logFormat = psMetadataLookupString(&mdok, *site, "LOGLEVEL"); // Log format 200 201 // 202 // If LOGFORMAT is specified in the configuration file, then we must initialize 203 // with a call to psLogSetFormat(). 204 // 205 psString logFormat = psMetadataLookupStr(&mdok, *site, "LOGFORMAT"); 171 206 if (mdok && logFormat) { 172 207 psTrace(__func__, 7, "Setting log format to %s\n", logFormat); … … 174 209 } 175 210 176 psString logDest = psMetadataLookupString(&mdok, *site, "LOGDEST"); // Log destination 211 212 // 213 // If LOGDEST is specified in the configuration file, then we must initialize 214 // with a call to psLogSetDestination(). 215 // XXX: This is not spec'ed in the SDRS. 216 // 217 psString logDest = psMetadataLookupStr(&mdok, *site, "LOGDEST"); 177 218 if (mdok && logDest) { 178 // XXX: Only stdout is provided for now; this section should be expanded in the future to do files,179 // and perhaps even sockets.219 // XXX: Only stdout is provided for now; this section should be 220 // expanded in the future to do files, and perhaps even sockets. 180 221 if (strcasecmp(logDest, "STDOUT") != 0) { 181 222 psLogMsg(__func__, PS_LOG_WARN, "Only STDOUT is currently supported as a log destination.\n"); … … 186 227 } 187 228 188 psMetadata *trace = psMetadataLookupMD(&mdok, *site, "TRACE"); // Trace levels 229 230 // 231 // If TRACE is specified in the configuration file, then we must initialize 232 // with a call to psTraceSetLevel(). 233 // XXX: This is not spec'ed in the SDRS. 234 // 235 psMetadata *trace = psMetadataLookupMD(&mdok, *site, "TRACE"); 189 236 if (mdok && trace) { 190 237 psMetadataIterator *traceIter = psMetadataIteratorAlloc(trace, PS_LIST_HEAD, NULL); // Iterator … … 197 244 } 198 245 psTrace(__func__, 7, "Setting trace level for %s to %d\n", traceItem->name, traceItem->data.S32); 199 (void)psTraceSetLevel(traceItem->name, traceItem->data.S32);246 psTraceSetLevel(traceItem->name, traceItem->data.S32); 200 247 } 201 248 psFree(traceIter); 202 249 } 203 250 204 if (cleanupSiteName) { 205 psFree(siteName); 206 } 207 return true; 251 return(true); 208 252 } 209 253 … … 213 257 { 214 258 // Read the rule for that camera 215 bool mdStatus = true; // Status of MD lookup259 bool mdStatus = true; 216 260 psMetadata *rule = psMetadataLookupMD(&mdStatus, camera, "RULE"); 217 261 if (! mdStatus || ! rule) { … … 276 320 277 321 278 // Work out what camera we have, based on the FITS header and a set of rules specified in the IPP 279 // configuration; return the camera configuration 280 322 // Work out what camera we have, based on the FITS header and a set of 323 // rules specified in the IPP configuration; return the camera configuration 281 324 psMetadata *pmConfigCameraFromHeader( 282 325 const psMetadata *ipprc, // The IPP configuration … … 289 332 return NULL; 290 333 } 291 292 psMetadata *winner = NULL; // The camera configuration whose rule first matches the supplied header 293 334 psMetadata *winner = NULL; // The camera configuration whose rule first matches 335 // the supplied header 294 336 // Iterate over the cameras 295 psMetadataIterator *iterator = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, NULL); // MD Iterator337 psMetadataIterator *iterator = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, NULL); 296 338 psMetadataItem *cameraItem = NULL; // Item from the metadata 339 297 340 while ((cameraItem = psMetadataGetAndIncrement(iterator))) { 298 341 // Open the camera information … … 355 398 psLogMsg(__func__, PS_LOG_WARN, "RECIPES in the camera configuration file is not of type METADATA\n"); 356 399 } else { 357 psString recipeFileName = psMetadataLookupStr ing(&mdok, recipes, recipeName);400 psString recipeFileName = psMetadataLookupStr(&mdok, recipes, recipeName); 358 401 (void)readConfig(&recipe, recipeFileName, "recipe"); 359 402 }
Note:
See TracChangeset
for help on using the changeset viewer.
