IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 23, 2007, 4:38:07 PM (19 years ago)
Author:
Paul Price
Message:

Allow multiple (only input, currently) filerules of the same name.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPAfileIO.c

    r13193 r13496  
    55#include <stdio.h>
    66#include <string.h>
    7 #include <strings.h>            /* for strn?casecmp */
     7#include <strings.h>            /* for strn?casecmp */
    88#include <pslib.h>
    99
     
    661661      case PM_FPA_FILE_HEADER:
    662662      case PM_FPA_FILE_FRINGE:
    663         // XXX note that for CMF and PSF, we do not know yet if there is actually any data to
    664         // write out.  this is because these types of output files have their data stored on the
    665         // readout->analysis metadata structure of another (existing) fpa
     663        // XXX note that for CMF and PSF, we do not know yet if there is actually any data to
     664        // write out.  this is because these types of output files have their data stored on the
     665        // readout->analysis metadata structure of another (existing) fpa
    666666      case PM_FPA_FILE_CMF:
    667667      case PM_FPA_FILE_PSF:
     
    848848    PS_ASSERT_PTR_NON_NULL(files, false);
    849849
    850     if (!name) {
    851         psMetadataItem *item = NULL;
    852         psMetadataIterator *iter = psMetadataIteratorAlloc (files, PS_LIST_HEAD, NULL);
    853         while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
    854             pmFPAfile *file = item->data.V;
    855             if (state) {
    856                 file->state &= PS_NOT_U8(PM_FPA_STATE_INACTIVE);
    857             } else {
    858                 file->state |= PM_FPA_STATE_INACTIVE;
    859             }
    860         }
    861         psFree (iter);
    862         return true;
    863     }
    864 
    865     bool status = false;
    866     pmFPAfile *file = psMetadataLookupPtr (&status, files, name);
    867     if (!status) {
    868         psTrace("psModules.camera", 6, "%s is not a defined IO file", name);
    869         return false;
    870     }
    871     if (!file) {
    872         psError(PS_ERR_IO, true, "file %s is NULL", name);
    873         return false;
    874     }
    875     if (state) {
    876         file->state &= PS_NOT_U8(PM_FPA_STATE_INACTIVE);
    877     } else {
    878         file->state |= PM_FPA_STATE_INACTIVE;
    879     }
    880     return true;
    881 }
     850    // Do this as an iteration rather than a lookup, since we may want to turn on/off multiple files at once
     851    // (if there are multiple files defined with the same name).
     852
     853    psString regex = NULL;              // Regular expression for psMetadataIteratorAlloc
     854    if (name) {
     855        psStringAppend(&regex, "^%s$", name);
     856    }
     857
     858    int num = 0;                        // Number of files activated
     859    psMetadataItem *item = NULL;        // Item from iteration
     860    psMetadataIterator *iter = psMetadataIteratorAlloc(files, PS_LIST_HEAD, regex); // Iterator
     861    while ((item = psMetadataGetAndIncrement(iter))) {
     862        pmFPAfile *file = item->data.V; // File of interest
     863        if (state) {
     864            file->state &= PS_NOT_U8(PM_FPA_STATE_INACTIVE);
     865        } else {
     866            file->state |= PM_FPA_STATE_INACTIVE;
     867        }
     868        num++;
     869    }
     870    psFree(iter);
     871    psFree(regex);
     872
     873    if (num == 0) {
     874        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find any files matching %s", name);
     875        return false;
     876    }
     877
     878    return true;
     879}
Note: See TracChangeset for help on using the changeset viewer.