IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 23, 2011, 4:27:17 PM (15 years ago)
Author:
rhenders
Message:

Introduced new logging system in order to provide proper audit trail

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/src/FitsGenerator.c

    r31025 r31030  
    1717  Finds a column within this table
    1818  */
    19 static Column* findColumn(Table* table, const char* name) {
     19static Column* findColumn(FitsGenerator* this, Table* table, const char* name) {
    2020
    2121    Column* column = NULL;
     
    2929    }
    3030
    31     if (!column) psError(PS_ERR_IO, false, "Could not find column '%s' in table '%s'", name, table->name);
     31    if (!column) this->logger->print(this->logger, MSG_ERROR, "Could not find column '%s' in table '%s'\n", name, table->name);
    3232
    3333    return column;
     
    4949    }
    5050
    51     if (!table) psError(PS_ERR_IO, false, "Could not find table '%s'", name);
     51    if (!table) this->logger->print(this->logger, MSG_ERROR, "Could not find table '%s'\n", name);
    5252
    5353    return table;
     
    214214   opens an XML file and returns the document
    215215   */
    216 static xmlDoc* openXmlFile(const char* path) {
     216static xmlDoc* openXmlFile(FitsGenerator* this, const char* path) {
    217217
    218218    xmlDoc* doc = xmlReadFile(path, NULL, 0);
    219     if (doc == NULL) psError(PS_ERR_IO, false, "Unable to open XML file at %s", path);
     219    if (doc == NULL) this->logger->print(this->logger, MSG_ERROR, "Unable to open XML file at %s\n", path);
    220220    return doc;
    221221}
     
    235235  Populates the provided table with data from XML
    236236  */
    237 static bool populateTable(Table* table, xmlNode* rootElement, Fits *fitsOut) {
     237static bool populateTable(FitsGenerator* this, Table* table, xmlNode* rootElement, Fits *fitsOut) {
    238238
    239239    char tempStr[100];
     
    253253    if(!tableNode) {
    254254
    255         psError(PS_ERR_IO,"Could not find table: %s", table->name);
     255        this->logger->print(this->logger, MSG_ERROR, "Could not find table: %s\n", table->name);
    256256        return false;
    257257    }
     
    320320
    321321            }
    322             if (status) psError(PS_ERR_IO, false, "Unable to write value of %s to column %s in table %s",
     322            if (status) this->logger->print(this->logger, MSG_ERROR, "Unable to write value of %s to column %s in table %s\n",
    323323                    tempStr, table->columns[i].pspsName, table->name);
    324324        }
     
    339339  Loads a table description from XML
    340340  */
    341 static bool loadTableDescription(Table* table, xmlNode* tableNode) {
     341static bool loadTableDescription(FitsGenerator* this, Table* table, xmlNode* tableNode) {
    342342
    343343    bool ret = true;
     
    391391    if (columnNum < 1) {
    392392
    393         psError(PS_ERR_IO, false, "Found no columns for table '%s'", tableName);
     393        this->logger->print(this->logger, MSG_ERROR, "Found no columns for table '%s'\n", tableName);
    394394        ret = false;
    395395    }
    396396
    397397    if (columnNum != table->numOfColumns)
    398         psError(PS_ERR_IO, false, "Mismatch between number of columns expected (%d) and those found (%d)", table->numOfColumns, columnNum);
     398        this->logger->print(this->logger, MSG_ERROR, "Mismatch between number of columns expected (%d) and those found (%d)\n", table->numOfColumns, columnNum);
    399399
    400400    return ret;
     
    411411    psStringAppend(&path, "%s/tables.xml", this->configsPath);
    412412
    413     xmlDoc* doc = openXmlFile(path);
     413    xmlDoc* doc = openXmlFile(this, path);
    414414
    415415    if (doc == NULL) {
     
    424424    if (strcmp((const char*)rootElement->name, "tableDescriptions")!=0) {
    425425
    426         psError(PS_ERR_IO, false, "Root node of XML is not 'tableDescriptions', as it should be");
     426        this->logger->print(this->logger, MSG_ERROR, "Root node of XML is not 'tableDescriptions', as it should be\n");
    427427        return false;
    428428    }
     
    445445                table = this->tables+tableNum;
    446446
    447                 if (!loadTableDescription(table, node)) ret = false;
     447                if (!loadTableDescription(this, table, node)) ret = false;
    448448                else tableNum++;
    449449            }
     
    452452
    453453    if (tableNum != this->numOfTables)
    454         psError(PS_ERR_IO, false, "Mismatch between number of tables expected (%d) and those found (%d)", this->numOfTables, tableNum);
     454        this->logger->print(this->logger, MSG_ERROR, "Mismatch between number of tables expected (%d) and those found (%d)\n", this->numOfTables, tableNum);
    455455
    456456    closeXmlFile(doc);
     
    486486                // column type
    487487                getAttribute(node, "pspsName", buffer);
    488                 column = findColumn(table, buffer);
     488                column = findColumn(this, table, buffer);
    489489
    490490                if (!column) continue;
     
    518518    psStringAppend(&path, "%s/map.xml", this->configsPath);
    519519
    520     xmlDoc* doc = openXmlFile(path);
     520    xmlDoc* doc = openXmlFile(this, path);
    521521
    522522    if (doc == NULL) {
     
    529529
    530530    if (strcmp((const char*)rootElement->name, "tabledata")!=0) {
    531         psError(PS_ERR_IO, false, "Root node of XML is not 'tabledata', as it should be");
     531        this->logger->print(this->logger, MSG_ERROR, "Root node of XML is not 'tabledata', as it should be\n");
    532532        return false;
    533533    }
     
    560560    psStringAppend(&path, "%s/data.xml", this->configsPath);
    561561
    562     xmlDoc* doc = openXmlFile(path);
     562    xmlDoc* doc = openXmlFile(this, path);
    563563
    564564    if (doc == NULL) {
     
    571571
    572572    if (strcmp((const char*)rootElement->name, "tabledata")!=0) {
    573         psError(PS_ERR_IO, false, "Root node of XML is not 'tabledata', as it should be");
     573        this->logger->print(this->logger, MSG_ERROR, "Root node of XML is not 'tabledata', as it should be\n");
    574574        return false;
    575575    }
    576576
    577577    for (uint32_t i=0; i<this->numOfTables; i++) {
    578         if (!populateTable(this->tables+i, rootElement, fitsOut)) {
     578        if (!populateTable(this, this->tables+i, rootElement, fitsOut)) {
    579579            ret = false;
    580580        }
     
    590590  */
    591591static bool populateTableFromFits(
     592        FitsGenerator* this,
    592593        Table* table,
    593594        Fits *fitsIn,
     
    678679
    679680                default:
    680                     psError(PS_ERR_IO, false, "Don't know IPP type (%d) for mapping from  '%d'  '%s' to '%s'", table->columns[i].ippType,
     681                    this->logger->print(this->logger, MSG_ERROR, "Don't know IPP type (%d) for mapping from  '%d'  '%s' to '%s'\n", table->columns[i].ippType,
    681682                            table->columns[i].ippColNum, table->columns[i].ippName, table->columns[i].pspsName);
    682683                    break;
     
    711712
    712713    if(!createTable(table, fitsOut, nRows)) return false;
    713     return populateTableFromFits(table, fitsIn, fitsOut, nRows, fromHeader);
     714    return populateTableFromFits(this, table, fitsIn, fitsOut, nRows, fromHeader);
    714715}
    715716
     
    733734  Constructor.
    734735  */
    735 FitsGenerator* new_FitsGenerator(const char* path) {
     736FitsGenerator* new_FitsGenerator(Logger* logger, const char* path) {
    736737
    737738    FitsGenerator* this = (FitsGenerator*)calloc(1, sizeof(FitsGenerator));
     
    739740    this->configsPath = NULL;
    740741    psStringAppend(&this->configsPath, path);
     742    this->logger = logger;
    741743
    742744    // method pointers
Note: See TracChangeset for help on using the changeset viewer.