Changeset 25835 for trunk/ippTools/src/magicdstool.c
- Timestamp:
- Oct 14, 2009, 11:06:18 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/magicdstool.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/magicdstool.c
r25822 r25835 33 33 34 34 static bool definebyqueryMode(pxConfig *config); 35 static psS64 definerunMode(pxConfig *config);36 35 static bool updaterunMode(pxConfig *config); 37 36 static bool todestreakMode(pxConfig *config); … … 46 45 47 46 static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, psMetadata *where, const char *state); 48 static bool magicDSGetIDs(pxConfig *config, psString stage, psS64 magic_id, psS64 *stage_id, psS64 *cam_id);49 47 50 48 # define MODECASE(caseName, func) \ … … 67 65 switch (config->mode) { 68 66 MODECASE(MAGICDSTOOL_MODE_DEFINEBYQUERY, definebyqueryMode); 69 MODECASE(MAGICDSTOOL_MODE_DEFINERUN, definerunMode);70 67 MODECASE(MAGICDSTOOL_MODE_UPDATERUN, updaterunMode); 71 68 MODECASE(MAGICDSTOOL_MODE_TODESTREAK, todestreakMode); … … 110 107 PXOPT_LOOKUP_BOOL(noreplace, config->args, "-noreplace", false); 111 108 PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false); 109 PXOPT_LOOKUP_STR(set_data_group, config->args, "-set_data_group", false, false); 110 PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false); 112 111 PXOPT_LOOKUP_BOOL(rerun, config->args, "-rerun", false); 113 112 PXOPT_LOOKUP_BOOL(dry_run, config->args, "-dry_run", false); … … 248 247 psS64 cam_id = psMetadataLookupS64(NULL, row, "cam_id"); 249 248 psString magicRunLabel = psMetadataLookupStr(NULL, row, "label"); 249 psString magicRunDataGroup = psMetadataLookupStr(NULL, row, "data_group"); 250 250 psString magicRunWorkdir = psMetadataLookupStr(NULL, row, "workdir"); 251 251 … … 269 269 cam_id, 270 270 set_label ? set_label : magicRunLabel, 271 set_data_group ? set_data_group : magicRunDataGroup, 271 272 outroot, 272 273 recoveryroot, 273 274 noreplace ? 0 :1, // re_place 274 0); // remove 275 0, // remove 276 0, // fault 277 note); // remove 275 278 276 279 psFree(outroot); … … 315 318 } 316 319 317 static psS64 definerunMode(pxConfig *config)318 {319 PS_ASSERT_PTR_NON_NULL(config, false);320 321 // required322 PXOPT_LOOKUP_S64(magic_id, config->args, "-magic_id", true, false);323 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false);324 PXOPT_LOOKUP_STR(outroot, config->args, "-outroot", true, false);325 326 // optional327 PXOPT_LOOKUP_STR(recoveryroot, config->args, "-recoveryroot", false, false);328 PXOPT_LOOKUP_BOOL(re_place, config->args, "-replace", false);329 PXOPT_LOOKUP_BOOL(remove, config->args, "-remove", false);330 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);331 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);332 333 psS64 stage_id = 0, cam_id = 0;334 335 if (!magicDSGetIDs(config, stage, magic_id, &stage_id, &cam_id)) {336 psError(PS_ERR_UNKNOWN, false, "failed to get ids");337 return false;338 }339 340 magicDSRunRow *run = magicDSRunRowAlloc(341 0, // ID342 magic_id,343 0, // inv_magic_id344 "new", // state345 stage,346 stage_id,347 cam_id,348 label,349 outroot,350 recoveryroot,351 re_place,352 remove353 );354 355 if (!run) {356 psError(PS_ERR_UNKNOWN, false, "failed to alloc magicRun object");357 return false;358 }359 if (!magicDSRunInsertObject(config->dbh, run)) {360 psError(PS_ERR_UNKNOWN, false, "database error");361 psFree(run);362 return false;363 }364 365 psS64 magic_ds_id = psDBLastInsertID(config->dbh);366 run->magic_ds_id = magic_ds_id;367 368 if (!magicDSRunPrintObject(stdout, run, !simple)) {369 psError(PS_ERR_UNKNOWN, false, "failed to print object");370 psFree(run);371 return false;372 }373 374 psFree(run);375 376 return magic_id;377 }378 379 320 380 321 static bool updaterunMode(pxConfig *config) … … 696 637 } 697 638 698 static bool magicDSGetIDs(pxConfig *config, psString stage, psS64 magic_id, psS64 *stage_id, psS64 *cam_id)699 {700 PS_ASSERT_PTR_NON_NULL(config, false);701 PS_ASSERT_PTR_NON_NULL(stage, false);702 PS_ASSERT_PTR_NON_NULL(stage_id, false);703 PS_ASSERT_PTR_NON_NULL(cam_id, false);704 705 int stageNum = ippStringToStage(stage);;706 if (stageNum == IPP_STAGE_NONE) {707 psError(PXTOOLS_ERR_DATA, false, "%s is not a valid value for stage", stage);708 return false;709 }710 711 psString query = pxDataGet("magicdstool_getrunids.sql");712 if (!query) {713 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");714 return false;715 }716 717 if (!p_psDBRunQueryF(config->dbh, query, magic_id)) {718 psError(PS_ERR_UNKNOWN, false, "database error");719 psFree(query);720 return false;721 }722 psFree(query);723 724 psArray *output = p_psDBFetchResult(config->dbh);725 if (!output) {726 psError(PS_ERR_UNKNOWN, false, "database error");727 return false;728 }729 if (!psArrayLength(output)) {730 psTrace("magicdstool", PS_LOG_INFO, "no rows found");731 psFree(output);732 return true;733 }734 if (psArrayLength(output) > 1) {735 psError(PS_ERR_UNKNOWN, true, "unexpected number of rows found %ld for magic_id %" PRId64,736 psArrayLength(output), magic_id);737 return false;738 }739 psMetadata *row = output->data[0];740 741 *cam_id = psMetadataLookupS64(NULL, row, "cam_id");742 switch (stageNum) {743 case IPP_STAGE_RAW:744 *stage_id = psMetadataLookupS64(NULL, row, "exp_id");745 break;746 case IPP_STAGE_CHIP:747 *stage_id = psMetadataLookupS64(NULL, row, "chip_id");748 break;749 case IPP_STAGE_CAMERA:750 *stage_id = *cam_id;751 return true;752 case IPP_STAGE_WARP:753 *stage_id = psMetadataLookupS64(NULL, row, "warp_id");754 break;755 case IPP_STAGE_DIFF:756 *stage_id = psMetadataLookupS64(NULL, row, "diff_id");757 break;758 }759 760 return true;761 }762 639 763 640 static bool advancerunMode(pxConfig *config)
Note:
See TracChangeset
for help on using the changeset viewer.
