Beispiel #1
0
/*
 * Initializes the DetChanElement data structure.
 */
HANDEL_STATIC int HANDEL_API xiaInitDetChanDS(void)
{
    DetChanElement *current = NULL;
    DetChanElement *head    = xiaDetChanHead;

    current = head;

    while (current != NULL) {
        head = current;
        current = current->next;

        switch (head->type) {
        case SINGLE:
            handel_md_free((void *)head->data.modAlias);
            break;

        case SET:
            xiaFreeDetSet(head->data.detChanSet);
            break;

        default:
            break;
        }

        handel_md_free((void *)head);
    }

    xiaDetChanHead = NULL;

    return XIA_SUCCESS;
}
Beispiel #2
0
/*
 * Frees the memory allocated to a Detector structure.
 */
HANDEL_SHARED int HANDEL_API xiaFreeDetector(Detector *detector)
/* Detector *detector;          Input: pointer to structure to free */
{
    int status = XIA_SUCCESS;

    if (detector == NULL) {
        status = XIA_NOMEM;
        sprintf(info_string,"Detector object unallocated:  can not free");
        xiaLogError("xiaFreeDetector", info_string, status);
        return status;
    }

    if (detector->alias != NULL) {
        handel_md_free(detector->alias);
    }
    if (detector->polarity != NULL) {
        handel_md_free(detector->polarity);
    }
    if (detector->gain != NULL) {
        handel_md_free(detector->gain);
    }

    handel_md_free(detector->typeValue);

    /* Free the Board_Info structure */
    handel_md_free(detector);
    detector = NULL;

    return status;
}
Beispiel #3
0
/*
 * Frees the memory allocated to a FirmwareSet structure.
 */
HANDEL_SHARED int HANDEL_API xiaFreeFirmwareSet(FirmwareSet *firmwareSet)
/* FirmwareSet *firmwareSet;        Input: pointer to structure to free */
{
    int status = XIA_SUCCESS;

    unsigned int i;

    Firmware *next, *current;

    if (firmwareSet == NULL) {
        status = XIA_NOMEM;
        sprintf(info_string,"FirmwareSet object unallocated:  can not free");
        xiaLogError("xiaFreeFirmwareSet", info_string, status);
        return status;
    }

    if (firmwareSet->alias != NULL) {
        handel_md_free(firmwareSet->alias);
    }

    if (firmwareSet->filename != NULL) {
        handel_md_free(firmwareSet->filename);
    }

    if (firmwareSet->mmu != NULL) {
        handel_md_free(firmwareSet->mmu);
    }

    if (firmwareSet->tmpPath != NULL) {
        handel_md_free(firmwareSet->tmpPath);
    }

    /* Loop over the Firmware information, deallocating memory */
    current = firmwareSet->firmware;

    while (current != NULL) {
        next = current->next;
        status = xiaFreeFirmware(current);
        if (status != XIA_SUCCESS) {
            xiaLogError("xiaFreeFirmwareSet", "Error freeing firmware", status);
            return status;
        }

        current = next;
    }

    for (i = 0; i < firmwareSet->numKeywords; i++) {
        handel_md_free((void *)firmwareSet->keywords[i]);
    }

    handel_md_free((void *)firmwareSet->keywords);

    /* Free the FirmwareSet structure */
    handel_md_free(firmwareSet);
    firmwareSet = NULL;

    return status;
}
Beispiel #4
0
/*
 * Frees the memory allocated to an XiaDaqEntry structure.
 */
HANDEL_SHARED int HANDEL_API xiaFreeXiaDaqEntry(XiaDaqEntry *entry)
{
    int status = XIA_SUCCESS;

    if (entry == NULL) {
        status = XIA_NOMEM;
        sprintf(info_string,"XiaDaqEntry object unallocated:  can not free");
        xiaLogError("xiaFreeXiaDaqEntry", info_string, status);
        return status;
    }

    if (entry->name != NULL) {
        handel_md_free(entry->name);
    }

    /* Free the XiaDaqEntry structure */
    handel_md_free(entry);
    entry = NULL;

    return status;
}
Beispiel #5
0
/*
 * Frees the memory allocated to an XiaDefaults structure.
 */
HANDEL_SHARED int HANDEL_API xiaFreeXiaDefaults(XiaDefaults *xiaDefaults)
{
    int status = XIA_SUCCESS;

    XiaDaqEntry *next = NULL;
    XiaDaqEntry *current = NULL;

    if (xiaDefaults == NULL) {
        status = XIA_NOMEM;
        sprintf(info_string,"XiaDefaults object unallocated:  can not free");
        xiaLogError("xiaFreeXiaDefaults", info_string, status);
        return status;
    }

    if (xiaDefaults->alias != NULL) {
        handel_md_free(xiaDefaults->alias);
    }

    /* Loop over the xiaDaqEntry information, deallocating memory */
    current = xiaDefaults->entry;
    while (current != NULL) {
        next = current->next;
        status = xiaFreeXiaDaqEntry(current);

        if (status != XIA_SUCCESS) {
            xiaLogError("xiaFreeXiaDefaults", "Error freeing DAQ entry", status);
            return status;
        }

        current = next;
    }

    /* Free the XiaDefaults structure */
    handel_md_free(xiaDefaults);
    xiaDefaults = NULL;

    return status;
}
Beispiel #6
0
/*
 * Frees the memory allocated to a Firmware structure.
 */
HANDEL_SHARED int HANDEL_API xiaFreeFirmware(Firmware *firmware)
/* Firmware *firmware;        Input: pointer to structure to free */
{
    int status = XIA_SUCCESS;

    if (firmware == NULL) {
        status = XIA_NOMEM;
        sprintf(info_string,"Firmware object unallocated:  can not free");
        xiaLogError("xiaFreeFirmware", info_string, status);
        return status;
    }

    if (firmware->dsp != NULL) {
        handel_md_free((void *)firmware->dsp);
    }

    if (firmware->fippi != NULL) {
        handel_md_free((void *)firmware->fippi);
    }

    if (firmware->user_fippi != NULL) {
        handel_md_free((void *)firmware->user_fippi);
    }

    if (firmware->user_dsp != NULL) {
        handel_md_free((void *)firmware->user_dsp);
    }

    if (firmware->system_fpga != NULL) {
        handel_md_free((void *)firmware->system_fpga);
    }

    if (firmware->filterInfo != NULL) {
        handel_md_free((void *)firmware->filterInfo);
    }

    handel_md_free((void *)firmware);
    firmware = NULL;

    return status;
}
Beispiel #7
0
/*
 * Frees a previously allocated module and all if its subcomponents.
 *
 * Assumes module has been allocated. Does _not_ assume that all of
 * modules's subcomponents have.
 */
HANDEL_SHARED int HANDEL_API xiaFreeModule(Module *module)
{
    int status;

    unsigned int i;
    unsigned int j;
    unsigned int k;
    unsigned int numDetStr;
    unsigned int numFirmStr;
    unsigned int numDefStr;

    PSLFuncs f;


    ASSERT(module != NULL);


    switch (module->interface_info->type) {
    default:
        /* Impossible */
        FAIL();
        break;

    case NO_INTERFACE:
        /* Only free the top-level struct */
        ASSERT(module->interface_info != NULL);
        handel_md_free(module->interface_info);
        break;

#ifndef EXCLUDE_PLX
    case PLX:
        handel_md_free(module->interface_info->info.plx);
        handel_md_free(module->interface_info);
        break;
#endif /* EXCLUDE_PLX */

#ifndef EXCLUDE_EPP
    case EPP:
    case GENERIC_EPP:
        handel_md_free((void *)module->interface_info->info.epp);
        handel_md_free((void *)module->interface_info);
        break;
#endif /* EXCLUDE_EPP */

#ifndef EXCLUDE_SERIAL
    case SERIAL:
        if (module->interface_info->info.serial->device_file)
            handel_md_free(module->interface_info->info.serial->device_file);
        handel_md_free((void *)module->interface_info->info.serial);
        handel_md_free((void *)module->interface_info);
        break;
#endif /* EXCLUDE_SERIAL */

#ifndef EXCLUDE_USB
    case USB:
        handel_md_free((void *)module->interface_info->info.usb);
        handel_md_free((void *)module->interface_info);
        break;
#endif /* EXCLUDE_USB */

#ifndef EXCLUDE_USB2
    case USB2:
        handel_md_free((void *)module->interface_info->info.usb2);
        handel_md_free((void *)module->interface_info);
        break;
#endif /* EXCLUDE_USB2 */

    }
    module->interface_info = NULL;

    for (i = 0; i < module->number_of_channels; i++) {
        if (module->channels[i] != -1) {
            status = xiaRemoveDetChan((unsigned int)module->channels[i]);

            if (status != XIA_SUCCESS) {
                sprintf(info_string, "Error removing detChan member");
                xiaLogError("xiaFreeModule", info_string, status);
                /* Should this continue since we'll leak memory if we return
                 * prematurely?
                 */
                return status;
            }
        }
    }

    handel_md_free(module->channels);
    module->channels = NULL;

    if (module->detector != NULL) {
        numDetStr = module->number_of_channels;

        for (i = 0; i < numDetStr; i++) {
            handel_md_free((void *)module->detector[i]);
        }
    }

    handel_md_free((void *)module->detector);
    handel_md_free((void *)module->detector_chan);

    if (module->firmware != NULL) {
        numFirmStr = module->number_of_channels;

        for (j = 0; j < numFirmStr; j++) {
            handel_md_free((void *)module->firmware[j]);
        }
    }

    handel_md_free((void *)module->firmware);

    if (module->defaults != NULL) {
        numDefStr = module->number_of_channels;

        for (k = 0; k < numDefStr; k++) {
            /* Remove the defaults from the system */
            status = xiaRemoveDefault(module->defaults[k]);

            if (status != XIA_SUCCESS) {

                sprintf(info_string, "Error removing values associated with modChan %u", k);
                xiaLogError("xiaFreeModule", info_string, status);
                return status;
            }

            handel_md_free((void *)module->defaults[k]);
        }
    }

    handel_md_free((void *)module->defaults);
    handel_md_free((void *)module->currentFirmware);

    /* Free up any multichannel info that was allocated */
    if (module->isMultiChannel) {
        handel_md_free(module->state->runActive);
        handel_md_free(module->state);
    }

    /* If the type isn't set, then there is no
     * chance that any of the type-specific data is set
     * like the SCA data.
     */
    if (module->type != NULL) {
        status = xiaLoadPSL(module->type, &f);

        if (status != XIA_SUCCESS) {
            sprintf(info_string, "Error loading PSL for '%s'", module->alias);
            xiaLogError("xiaFreeModule", info_string, status);
            return status;
        }

        if (module->ch != NULL) {
            for (i = 0; i < module->number_of_channels; i++) {
                status = f.freeSCAs(module, i);

                if (status != XIA_SUCCESS) {
                    sprintf(info_string, "Error removing SCAs from modChan '%u', alias '%s'",
                            i, module->alias);
                    xiaLogError("xiaFreeModule", info_string, status);
                    return status;
                }
            }

            handel_md_free(module->ch);
        }

        handel_md_free(module->type);
        module->type = NULL;
    }

    handel_md_free(module->alias);
    module->alias = NULL;



    /* This (freeing the module) was previously absent, which I think was causing a
     * small (16-bit) memory leak.
     */
    handel_md_free(module);
    module = NULL;

    /* XXX If this is the last module, i.e. the # of detChans besides "-1" and
     * any "SET"s is 0, then release the rest of the detChan list.
     */

    return XIA_SUCCESS;
}
Beispiel #8
0
/*****************************************************************************
 * 
 * This routine is used by xiaMergeSort to merge together elements. Taken from
 * the same reference as xiaMergeSort.
 *
 *****************************************************************************/
HANDEL_STATIC int HANDEL_API xiaMerge(void *data, int esize, int i, int j, int k, int (*compare)(const void *key1, const void *key2))
{	
	
	char *a = data;
	char *m;

	int ipos;
	int jpos;
	int mpos;

	
	ipos = i;
	jpos = j + 1;
	mpos = 0;


	if ((m = (char *)handel_md_alloc(esize * ((k - i) + 1))) == NULL)
	{
		return -1;
	}

	while (ipos <= j || jpos <= k)
	{
		if (ipos > j)
		{
			while (jpos <= k)
			{
				memcpy(&m[mpos * esize], &a[jpos * esize], esize);
				jpos++;
				mpos++;
			}

			continue;
		
		} else if (jpos > k) {

			while (ipos <= j)
			{
				memcpy(&m[mpos * esize], &a[ipos * esize], esize);
				ipos++;
				mpos++;
			}

			continue;
		}

		if (compare(&a[ipos * esize], &a[jpos * esize]) < 0)
		{
			memcpy(&m[mpos * esize], &a[ipos * esize], esize);
			ipos++;
			mpos++;
		
		} else {

			memcpy(&m[mpos * esize], &a[jpos * esize], esize);
			jpos++;
			mpos++;
		}
	}

	memcpy(&a[i * esize], m, esize * ((k - i) + 1));
	handel_md_free(m);
	
	return 0;
}