IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 29, 2008, 3:02:07 PM (18 years ago)
Author:
eugene
Message:

merge updates from cleanup branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/chiptool.c

    r18336 r18366  
    4545static bool unmaskedMode(pxConfig *config);
    4646static bool unblockMode(pxConfig *config);
    47 static bool pendingcleanupMode(pxConfig *config);
     47static bool pendingcleanuprunMode(pxConfig *config);
     48static bool pendingcleanupimfileMode(pxConfig *config);
    4849static bool donecleanupMode(pxConfig *config);
     50static bool runMode(pxConfig *config);
    4951
    5052static bool chipProcessedCompleteExp(pxConfig *config);
     
    6769
    6870    switch (config->mode) {
    69         MODECASE(CHIPTOOL_MODE_DEFINEBYQUERY,                   definebyqueryMode);
     71        MODECASE(CHIPTOOL_MODE_DEFINEBYQUERY,           definebyqueryMode);
    7072        MODECASE(CHIPTOOL_MODE_UPDATERUN,               updaterunMode);
    7173        MODECASE(CHIPTOOL_MODE_PENDINGIMFILE,           pendingimfileMode);
     
    7880        MODECASE(CHIPTOOL_MODE_UNMASKED,                unmaskedMode);
    7981        MODECASE(CHIPTOOL_MODE_UNBLOCK,                 unblockMode);
    80         MODECASE(CHIPTOOL_MODE_PENDINGCLEANUP,          pendingcleanupMode);
     82        MODECASE(CHIPTOOL_MODE_PENDINGCLEANUPRUN,       pendingcleanuprunMode);
     83        MODECASE(CHIPTOOL_MODE_PENDINGCLEANUPIMFILE,    pendingcleanupimfileMode);
    8184        MODECASE(CHIPTOOL_MODE_DONECLEANUP,             donecleanupMode);
     85        MODECASE(CHIPTOOL_MODE_RUN,                     runMode);
    8286        default:
    8387            psAbort("invalid option (this should not happen)");
     
    835839
    836840
    837 static bool pendingcleanupMode(pxConfig *config)
     841static bool pendingcleanuprunMode(pxConfig *config)
    838842{
    839843    PS_ASSERT_PTR_NON_NULL(config, NULL);
     
    845849    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
    846850
    847     psString query = pxDataGet("chiptool_pendingcleanup.sql");
     851    psString query = pxDataGet("chiptool_pendingcleanuprun.sql");
    848852    if (!query) {
    849853        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     
    884888
    885889    // negative simple so the default is true
    886     if (!ippdbPrintMetadatas(stdout, output, "chipPendingCleanup", !simple)) {
     890    if (!ippdbPrintMetadatas(stdout, output, "chipPendingCleanupRun", !simple)) {
    887891        psError(PS_ERR_UNKNOWN, false, "failed to print array");
    888892        psFree(output);
     
    896900
    897901
    898 static bool donecleanupMode(pxConfig *config)
     902static bool pendingcleanupimfileMode(pxConfig *config)
    899903{
    900904    PS_ASSERT_PTR_NON_NULL(config, NULL);
    901905
     906    PXOPT_LOOKUP_S64(chip_id, config->args, "-chip_id", false, false);
    902907    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    903908    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    904909
    905910    psMetadata *where = psMetadataAlloc();
     911    if (chip_id) {
     912        PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
     913    }
    906914    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
    907915
    908     psString query = pxDataGet("chiptool_donecleanup.sql");
     916    psString query = pxDataGet("chiptool_pendingcleanupimfile.sql");
    909917    if (!query) {
    910918        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     
    945953
    946954    // negative simple so the default is true
     955    if (!ippdbPrintMetadatas(stdout, output, "chipPendingCleanupImfile", !simple)) {
     956        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     957        psFree(output);
     958        return false;
     959    }
     960
     961    psFree(output);
     962
     963    return true;
     964}
     965
     966
     967static bool donecleanupMode(pxConfig *config)
     968{
     969    PS_ASSERT_PTR_NON_NULL(config, NULL);
     970
     971    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     972    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     973
     974    psMetadata *where = psMetadataAlloc();
     975    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     976
     977    psString query = pxDataGet("chiptool_donecleanup.sql");
     978    if (!query) {
     979        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     980        return false;
     981    }
     982
     983    if (where && psListLength(where->list)) {
     984        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     985        psStringAppend(&query, " AND %s", whereClause);
     986        psFree(whereClause);
     987    }
     988    psFree(where);
     989
     990    // treat limit == 0 as "no limit"
     991    if (limit) {
     992        psString limitString = psDBGenerateLimitSQL(limit);
     993        psStringAppend(&query, " %s", limitString);
     994        psFree(limitString);
     995    }
     996
     997    if (!p_psDBRunQuery(config->dbh, query)) {
     998        psError(PS_ERR_UNKNOWN, false, "database error");
     999        psFree(query);
     1000        return false;
     1001    }
     1002    psFree(query);
     1003
     1004    psArray *output = p_psDBFetchResult(config->dbh);
     1005    if (!output) {
     1006        psError(PS_ERR_UNKNOWN, false, "database error");
     1007        return false;
     1008    }
     1009    if (!psArrayLength(output)) {
     1010        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     1011        psFree(output);
     1012        return true;
     1013    }
     1014
     1015    // negative simple so the default is true
     1016    if (!ippdbPrintMetadatas(stdout, output, "chipDoneCleanup", !simple)) {
     1017        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1018        psFree(output);
     1019        return false;
     1020    }
     1021
     1022    psFree(output);
     1023
     1024    return true;
     1025}
     1026
     1027
     1028static bool runMode(pxConfig *config)
     1029{
     1030    PS_ASSERT_PTR_NON_NULL(config, NULL);
     1031
     1032    PXOPT_LOOKUP_STR(state, config->args, "-state", true, false);
     1033    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1034    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1035
     1036    // make sure that the state string is valid
     1037    if (!pxIsValidState(state)) {
     1038        psError(PXTOOLS_ERR_DATA, false, "%s is not a valid state", state);
     1039        return false;
     1040    }
     1041
     1042    psMetadata *where = psMetadataAlloc();
     1043    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     1044    PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
     1045
     1046    psString query = pxDataGet("chiptool_run.sql");
     1047    if (!query) {
     1048        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1049        return false;
     1050    }
     1051
     1052    if (where && psListLength(where->list)) {
     1053        psString whereClause = psDBGenerateWhereSQL(where, NULL);
     1054        psStringAppend(&query, " %s", whereClause);
     1055        psFree(whereClause);
     1056    }
     1057    psFree(where);
     1058
     1059    // treat limit == 0 as "no limit"
     1060    if (limit) {
     1061        psString limitString = psDBGenerateLimitSQL(limit);
     1062        psStringAppend(&query, " %s", limitString);
     1063        psFree(limitString);
     1064    }
     1065
     1066    if (!p_psDBRunQuery(config->dbh, query)) {
     1067        psError(PS_ERR_UNKNOWN, false, "database error");
     1068        psFree(query);
     1069        return false;
     1070    }
     1071    psFree(query);
     1072
     1073    psArray *output = p_psDBFetchResult(config->dbh);
     1074    if (!output) {
     1075        psError(PS_ERR_UNKNOWN, false, "database error");
     1076        return false;
     1077    }
     1078    if (!psArrayLength(output)) {
     1079        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     1080        psFree(output);
     1081        return true;
     1082    }
     1083
     1084    // negative simple so the default is true
    9471085    if (!ippdbPrintMetadatas(stdout, output, "chipDoneCleanup", !simple)) {
    9481086        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     
    9921130        chipRunRow *chipRun = chipRunObjectFromMetadata(row);
    9931131        // set chipRun.state to 'stop'
    994         if (!pxchipRunSetState(config, chipRun->chip_id, "stop")) {
     1132        if (!pxchipRunSetState(config, chipRun->chip_id, "full")) {
    9951133            psError(PS_ERR_UNKNOWN, false, "failed to change chipRun.state for chip_id: %" PRId64, chipRun->chip_id);
    9961134            psFree(chipRun);
Note: See TracChangeset for help on using the changeset viewer.