Changeset 15217 for trunk/psModules/src/config/pmConfig.c
- Timestamp:
- Oct 4, 2007, 10:15:48 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/config/pmConfig.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfig.c
r15180 r15217 229 229 } 230 230 231 // Read a file into a metadataItem, if required 232 static bool metadataItemReadFile(psMetadataItem *item, // Item into which to read file 233 const char *description // Description, for error messages 234 ) 235 { 236 assert(item); 237 assert(description); 238 239 if (item->type == PS_DATA_METADATA) { 240 return true; // We've already read it 241 } 242 if (item->type != PS_DATA_STRING) { 243 psTrace("config", 2, "Element %s in %s metadata is not of type STR.\n", 244 item->name, description); 245 return false; 246 } 247 248 psTrace("config", 2, "Reading %s %s: %s\n", description, item->name, item->data.str); 249 psMetadata *new = NULL; // New metadata 250 if (!pmConfigFileRead(&new, item->data.str, item->name)) { 251 psError(PM_ERR_CONFIG, false, "Trouble reading reading %s %s.\n", 252 description, item->name); 253 psFree(new); 254 return false; 255 } 256 257 // Muck around under the hood to replace the filename with the metadata; don't try this at home, kids 258 item->type = PS_DATA_METADATA; 259 psFree(item->data.str); 260 item->data.md = new; 261 262 return true; 263 } 264 231 265 // Read metadata config files in a metadata 232 266 // The metadata contains file names, which will be replaced with the metadata that are in the files. … … 239 273 psMetadataItem *item; // Item from iteration 240 274 while ((item = psMetadataGetAndIncrement(iter))) { 241 if (item->type == PS_DATA_METADATA) { 242 continue; // We've already read it 243 } 244 if (item->type != PS_DATA_STRING) { 245 psTrace("config", 2, "Element %s in %s metadata is not of type STR.\n", 246 item->name, description); 247 continue; 248 } 249 250 psTrace("config", 2, "Reading %s %s: %s\n", description, item->name, item->data.str); 251 psMetadata *new = NULL; // New metadata 252 if (!pmConfigFileRead(&new, item->data.str, item->name)) { 253 psError(PM_ERR_CONFIG, false, "Trouble reading reading %s %s --- " 254 "ignored.\n", description, item->name); 255 psFree(new); 275 if (!metadataItemReadFile(item, description)) { 276 psError(PM_ERR_CONFIG, false, "Unable to read %s %s.", description, item->name); 256 277 psFree(iter); 257 278 return false; 258 279 } 259 260 // Muck around under the hood to replace the filename with the metadata; don't try this at home, kids261 item->type = PS_DATA_METADATA;262 psFree(item->data.str);263 item->data.md = new;264 280 } 265 281 psFree(iter); … … 694 710 } 695 711 psMetadata *camera = cameraItem->data.md; // Camera configuration 712 713 psMetadata *newRule = pmConfigFileRule(config, camera, new); // The rule of interest 714 if (!newRule) { 715 psWarning("Unable to find filerule %s in camera %s --- ignored.", new, cameraItem->name); 716 continue; 717 } 718 719 // By calling pmConfigFileRule, we've assured that the FILERULES is now a metadata 696 720 psMetadata *filerules = psMetadataLookupMetadata(NULL, camera, "FILERULES"); // File rules 697 721 if (!filerules) { … … 700 724 continue; 701 725 } 702 psMetadataItem *newItem = psMetadataLookup(filerules, new); // The rule of interest, or a redir. 703 if (!newItem) { 704 psWarning("Can't find file rule %s in camera %s --- ignored.", new, cameraItem->name); 705 continue; 706 } 707 psMetadata *newRule; // New rule (replacement) 708 switch (newItem->type) { 709 case PS_DATA_STRING: 710 // A redirection 711 newRule = psMetadataLookupMetadata(NULL, filerules, newItem->data.str); 712 break; 713 case PS_DATA_METADATA: 714 // The rule itself 715 newRule = newItem->data.md; 716 break; 717 default: 718 psWarning("Unable to find filerule %s of the correct type in camera %s --- ignored.", 719 new, cameraItem->name); 720 continue; 721 } 726 722 727 psMetadataAddMetadata(filerules, PS_LIST_TAIL, old, PS_META_REPLACE, 723 728 "Original replaced by -F option", newRule); … … 1414 1419 return psStringCopy(filename); 1415 1420 } 1421 1422 psMetadata *pmConfigFileRule(const pmConfig *config, const psMetadata *camera, const char *name) 1423 { 1424 PS_ASSERT_PTR_NON_NULL(config, NULL); 1425 PS_ASSERT_METADATA_NON_NULL(camera, NULL); 1426 PS_ASSERT_STRING_NON_EMPTY(name, NULL); 1427 1428 psMetadataItem *item = psMetadataLookup(camera, "FILERULES"); // Item with the file rule of interest 1429 if (!item) { 1430 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FILERULES in the camera configuration."); 1431 return NULL; 1432 } 1433 1434 if (!metadataItemReadFile(item, "file rules ")) { 1435 psError(PM_ERR_CONFIG, false, "Unable to read file rules for camera."); 1436 return NULL; 1437 } 1438 1439 assert(item->type == PS_DATA_METADATA); 1440 psMetadata *filerules = item->data.md; // File rules from the camera configuration 1441 1442 // select the name from the FILERULES 1443 // check for alias name (type == STR, name is aliased name) 1444 bool mdok; // Status of MD lookup 1445 const char *realname = psMetadataLookupStr(&mdok, filerules, name); // Name of file rule to look up 1446 if (!realname || strlen(realname) == 0) { 1447 realname = name; 1448 } 1449 1450 return psMetadataLookupMetadata(NULL, filerules, realname); 1451 } 1452
Note:
See TracChangeset
for help on using the changeset viewer.
