Changeset 18908 for trunk/psModules/src/config/pmConfig.c
- Timestamp:
- Aug 4, 2008, 5:45:56 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/config/pmConfig.c (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfig.c
r18905 r18908 57 57 psFree(config->site); 58 58 psFree(config->system); 59 psFree(config->complete);60 59 psFree(config->files); 61 60 psFree(config->camera); … … 139 138 config->site = NULL; 140 139 config->system = NULL; 141 config->complete = NULL;142 140 config->camera = NULL; 143 141 config->cameraName = NULL; … … 232 230 bool pmConfigFileRead(psMetadata **config, const char *name, const char *description) 233 231 { 234 PS_ASSERT_PTR_NON_NULL(config, false);235 PS_ASSERT_STRING_NON_EMPTY(name, false);236 PS_ASSERT_STRING_NON_EMPTY(description, false);232 assert(config); 233 assert(name); 234 assert(description); 237 235 238 236 char *realName = NULL; … … 313 311 } 314 312 315 // Read a file into a metadataItem, if required 316 static bool metadataItemReadFile(psMetadataItem *item, // Item into which to read file 317 const char *description // Description, for error messages 318 ) 319 { 320 assert(item); 321 assert(description); 313 bool pmConfigFileIngest(psMetadataItem *item, const char *description) 314 { 315 PS_ASSERT_METADATA_ITEM_NON_NULL(item, false); 316 PS_ASSERT_STRING_NON_EMPTY(description, false); 322 317 323 318 if (item->type == PS_DATA_METADATA) { … … 357 352 psMetadataItem *item; // Item from iteration 358 353 while ((item = psMetadataGetAndIncrement(iter))) { 359 if (! metadataItemReadFile(item, description)) {354 if (!pmConfigFileIngest(item, description)) { 360 355 psError(PM_ERR_CONFIG, false, "Unable to read %s %s.", description, item->name); 361 356 psFree(iter); … … 400 395 psMetadataItem *darkNorm = psMetadataLookup(camera, "DARK.NORM"); // The dark normalisation calibration 401 396 if (darkNorm) { 402 if (darkNorm->type == PS_DATA_STRING) { 403 const char *darkNormName = darkNorm->data.str; // The file name 404 psTrace("config", 2, "Reading %s dark normalisation: %s\n", cameraName, darkNormName); 405 psMetadata *new = NULL; // New metadata 406 if (!pmConfigFileRead(&new, darkNormName, "Dark normalisation")) { 407 psError(PM_ERR_CONFIG, false, "Trouble reading reading %s dark normalisation %s --- " 408 "ignored.\n", cameraName, darkNormName); 409 psFree(new); 410 return false; 411 } 412 413 // Muck around under the hood to replace the filename with the metadata; 414 // don't try this at home, kids 415 darkNorm->type = PS_DATA_METADATA; 416 psFree(darkNorm->data.str); 417 darkNorm->data.md = new; 418 } else if (darkNorm->type != PS_DATA_METADATA) { 419 psWarning("DARK.NORM in camera %s is not of type STR or METADATA (%x)", 420 cameraName, darkNorm->type); 397 if (!pmConfigFileIngest(darkNorm, "dark normalisation")) { 398 psWarning("Unable to ingest DARK.NORM in camera %s", cameraName); 421 399 } 422 400 } else { … … 505 483 506 484 // read the SITE file 507 psString siteFile = psMetadataLookupStr(NULL, config->user, "SITE"); 508 if (!pmConfigFileRead(&config->site, siteFile, "site")) { 485 psMetadataItem *siteItem = psMetadataLookup(config->user, "SITE"); 486 if (!siteItem) { 487 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find SITE in user configuration."); 509 488 psFree(config); 510 489 return NULL; 511 490 } 512 513 // load the SYSTEM file 514 psString systemFile = psMetadataLookupStr(NULL, config->user, "SYSTEM"); 515 if (!pmConfigFileRead(&config->system, systemFile, "system")) { 491 if (!pmConfigFileIngest(siteItem, "site configuration")) { 492 psError(PS_ERR_UNKNOWN, false, "Unable to read site configuration"); 516 493 psFree(config); 517 494 return NULL; 518 495 } 519 520 // interpolate USER, SITE and SYSTEM into the config->complete metadata 521 config->complete = psMetadataCopy (NULL, config->user); 522 config->complete = psMetadataCopy (config->complete, config->site); 523 config->complete = psMetadataCopy (config->complete, config->system); 496 config->site = psMemIncrRefCounter(siteItem->data.md); 497 498 // load the SYSTEM file 499 psMetadataItem *systemItem = psMetadataLookup(config->user, "SYSTEM"); 500 if (!systemItem) { 501 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find SYSTEM in user configuration."); 502 psFree(config); 503 return NULL; 504 } 505 if (!pmConfigFileIngest(systemItem, "system configuration")) { 506 psError(PS_ERR_UNKNOWN, false, "Unable to read system configuration"); 507 psFree(config); 508 return NULL; 509 } 510 config->system = psMemIncrRefCounter(systemItem->data.md); 524 511 525 512 // Set LOG and TRACE options based on the user configuration. These must be set AFTER … … 651 638 // Initialise the psLib time handling 652 639 // XXX is this still needed / desired? 653 psString timeName = psMetadataLookupStr(&mdok, config->complete, "TIME"); 654 if (mdok && timeName) 655 { 640 psString timeName = psMetadataLookupStr(&mdok, config->system, "TIME"); 641 if (mdok && timeName) { 656 642 psTrace("psModules.config", 7, "Initialising psTime with file %s\n", timeName); 657 643 psTimeInit(timeName); … … 671 657 char *cameraName = argv[argNum]; // symbolic name of the camera 672 658 673 // look for the CAMERAS list in config-> complete674 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config-> complete, "CAMERAS");659 // look for the CAMERAS list in config->system 660 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS"); 675 661 if (!cameras) { 676 662 psError(PS_ERR_IO, false, "Unable to find CAMERAS in site configuration.\n"); … … 718 704 "Camera specified on command line", config->camera); 719 705 720 if (!pmConfigCameraSkycellVersion(config-> complete, cameraName)) {706 if (!pmConfigCameraSkycellVersion(config->system, cameraName)) { 721 707 psError(PS_ERR_UNKNOWN, false, 722 708 "Unable to generate skycell versions of specified camera %s.\n", … … 726 712 } 727 713 728 if (!pmConfigCameraMosaickedVersions(config-> complete, cameraName)) {714 if (!pmConfigCameraMosaickedVersions(config->system, cameraName)) { 729 715 psError(PS_ERR_UNKNOWN, false, 730 716 "Unable to generate mosaicked versions of specified camera %s.\n", … … 739 725 if (!config->camera && readCameraConfig) { 740 726 bool mdok; // Status of MD lookup 741 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config-> complete, "CAMERAS"); // List of cameras727 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS"); // List of cameras 742 728 if (!mdok || !cameras) { 743 729 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the system configuration.\n"); … … 773 759 psFree(iter); 774 760 775 if (!pmConfigCameraSkycellVersionsAll(config-> complete)) {761 if (!pmConfigCameraSkycellVersionsAll(config->system)) { 776 762 psError(PS_ERR_UNKNOWN, false, "Unable to generate skycell versions of cameras.\n"); 777 763 psFree(config); 778 764 return NULL; 779 765 } 780 if (!pmConfigCameraMosaickedVersionsAll(config-> complete)) {766 if (!pmConfigCameraMosaickedVersionsAll(config->system)) { 781 767 psError(PS_ERR_UNKNOWN, false, "Unable to generate mosaicked versions of cameras.\n"); 782 768 psFree(config); … … 817 803 psArgumentRemove(argNum, argc, argv); 818 804 819 psMetadata *cameras = psMetadataLookupMetadata(NULL, config-> complete, "CAMERAS"); // List of cameras805 psMetadata *cameras = psMetadataLookupMetadata(NULL, config->system, "CAMERAS"); // List of cameras 820 806 if (!cameras) { 821 807 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find CAMERAS in the site configuration.\n"); … … 865 851 } else { 866 852 char *dbserver = argv[argNum]; // The camera configuration file to read 867 if (!psMetadataAddStr(config-> complete, PS_LIST_TAIL, "DBSERVER", PS_META_REPLACE,853 if (!psMetadataAddStr(config->user, PS_LIST_TAIL, "DBSERVER", PS_META_REPLACE, 868 854 NULL, dbserver)) { 869 855 psWarning("Failed to overwrite .ipprc DBSERVER value"); … … 881 867 } else { 882 868 char *dbname = argv[argNum]; // The camera configuration file to read 883 if (!psMetadataAddStr(config-> complete, PS_LIST_TAIL, "DBNAME", PS_META_REPLACE, NULL, dbname)) {869 if (!psMetadataAddStr(config->user, PS_LIST_TAIL, "DBNAME", PS_META_REPLACE, NULL, dbname)) { 884 870 psWarning("Failed to overwrite .ipprc DBNAME value"); 885 871 } … … 896 882 } else { 897 883 char *dbuser = argv[argNum]; // The camera configuration file to read 898 if (!psMetadataAddStr(config-> complete, PS_LIST_TAIL, "DBUSER", PS_META_REPLACE, NULL, dbuser)) {884 if (!psMetadataAddStr(config->user, PS_LIST_TAIL, "DBUSER", PS_META_REPLACE, NULL, dbuser)) { 899 885 psWarning("Failed to overwrite .ipprc DBUSER value"); 900 886 } … … 911 897 } else { 912 898 char *dbpassword = argv[argNum]; // The camera configuration file to read 913 if (!psMetadataAddStr(config-> complete, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE,899 if (!psMetadataAddStr(config->user, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE, 914 900 NULL, dbpassword)) { 915 901 psWarning("Failed to overwrite .ipprc DBPASSWORD value"); … … 927 913 } else { 928 914 char *dbport = argv[argNum]; // The camera configuration file to read 929 if (!psMetadataAddS32(config-> complete, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL,915 if (!psMetadataAddS32(config->user, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL, 930 916 (psS32)atoi(dbport))) { 931 917 psWarning("Failed to overwrite .ipprc DBPORT value"); … … 1113 1099 1114 1100 bool mdok; // Metadata lookup status 1115 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config-> complete, "CAMERAS");1101 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS"); 1116 1102 if (! mdok || !cameras) { 1117 1103 psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration."); … … 1183 1169 char *testName = NULL; 1184 1170 1185 psMetadata *cameras = psMetadataLookupMetadata (NULL, config-> complete, "CAMERAS");1171 psMetadata *cameras = psMetadataLookupMetadata (NULL, config->system, "CAMERAS"); 1186 1172 psAssert (cameras, "missing CAMERAS in complete metadata"); 1187 1173 … … 1263 1249 PS_ASSERT_STRING_NON_EMPTY(cameraName, NULL); 1264 1250 1265 psMetadata *cameras = psMetadataLookupMetadata(NULL, config-> complete, "CAMERAS");1251 psMetadata *cameras = psMetadataLookupMetadata(NULL, config->system, "CAMERAS"); 1266 1252 if (!cameras) { 1267 1253 psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration."); … … 1269 1255 } 1270 1256 1271 char *cameraPath = psMetadataLookupStr(NULL, cameras, cameraName);1272 if (! cameraPath) {1273 psError(PS_ERR_ IO, true, "Unable to find requested CAMERA in theconfiguration.");1257 psMetadataItem *item = psMetadataLookup(cameras, cameraName); // Item with camera of interest 1258 if (!pmConfigFileIngest(item, "camera configuration")) { 1259 psError(PS_ERR_UNKNOWN, false, "Unable to ingest camera configuration."); 1274 1260 return NULL; 1275 1261 } 1276 1262 1277 psMetadata *camera = NULL; // Camera to test against what we've got: 1278 1279 if (!pmConfigFileRead(&camera, cameraPath, cameraName)) { 1280 psWarning("Trouble reading reading camera configuration %s", cameraName); 1281 psFree(camera); 1282 return NULL; 1283 } 1284 1285 return camera; 1263 return psMemIncrRefCounter(item->data.md); 1286 1264 } 1287 1265 … … 1289 1267 { 1290 1268 PS_ASSERT_PTR_NON_NULL(config, NULL); 1291 PS_ASSERT_PTR_NON_NULL(config-> complete, NULL);1269 PS_ASSERT_PTR_NON_NULL(config->user, NULL); 1292 1270 1293 1271 #ifndef HAVE_PSDB … … 1310 1288 1311 1289 // XXX leaky strings 1312 psString dbServer = psMetadataLookupStr(&mdStatus01, config-> complete, "DBSERVER");1313 psString dbUsername = psMetadataLookupStr(&mdStatus02, config-> complete, "DBUSER");1314 psString dbPassword = psMetadataLookupStr(&mdStatus03, config-> complete, "DBPASSWORD");1315 psString dbName = psMetadataLookupStr(&mdStatus04, config-> complete, "DBNAME");1316 psS32 dbPort = psMetadataLookupS32(&mdStatus05, config-> complete, "DBPORT");1290 psString dbServer = psMetadataLookupStr(&mdStatus01, config->user, "DBSERVER"); 1291 psString dbUsername = psMetadataLookupStr(&mdStatus02, config->user, "DBUSER"); 1292 psString dbPassword = psMetadataLookupStr(&mdStatus03, config->user, "DBPASSWORD"); 1293 psString dbName = psMetadataLookupStr(&mdStatus04, config->user, "DBNAME"); 1294 psS32 dbPort = psMetadataLookupS32(&mdStatus05, config->user, "DBPORT"); 1317 1295 if (!mdStatus05) { 1318 1296 dbPort = 0; … … 1527 1505 // replace path://PATH with matched datapath 1528 1506 if (!strncasecmp(filename, "path://", strlen("path://"))) { 1529 PS_ASSERT_METADATA_NON_NULL(config-> complete, NULL);1507 PS_ASSERT_METADATA_NON_NULL(config->site, NULL); 1530 1508 1531 1509 psString newName = psStringCopy(filename); 1532 1510 1533 1511 // filename should be of the form: path://PATH/rest/of/file 1534 // replace PATH with matching name from config-> complete:DATAPATH1535 psMetadata *datapath = psMetadataLookupPtr (NULL, config-> complete, "DATAPATH");1512 // replace PATH with matching name from config->site:DATAPATH 1513 psMetadata *datapath = psMetadataLookupPtr (NULL, config->site, "DATAPATH"); 1536 1514 if (datapath == NULL) { 1537 1515 psError(PS_ERR_UNKNOWN, true, "DATAPATH is not defined in config.site"); … … 1586 1564 // if env isn't set, check the config system 1587 1565 if (!neb_server) { 1588 neb_server = psMetadataLookupStr(&status, config-> complete, "NEB_SERVER");1566 neb_server = psMetadataLookupStr(&status, config->site, "NEB_SERVER"); 1589 1567 if (!status) { 1590 1568 psError(PM_ERR_CONFIG, true, "failed to lookup config value for NEB_SERVER."); … … 1662 1640 } 1663 1641 1664 if (! metadataItemReadFile(item, "file rules ")) {1642 if (!pmConfigFileIngest(item, "file rules ")) { 1665 1643 psError(PM_ERR_CONFIG, false, "Unable to read file rules for camera."); 1666 1644 return NULL; … … 1695 1673 } 1696 1674 1697 if (! metadataItemReadFile(item, "FITS Types")) {1675 if (!pmConfigFileIngest(item, "FITS Types")) { 1698 1676 psError(PM_ERR_CONFIG, false, "Unable to read fits types for camera."); 1699 1677 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.
