Exemple #1
0
int myfree(void * blockPtr) {
    if (!_initialized)
        return -1;

    DescriptorNode * node = findDescriptor(blockPtr, _usedList);
    //printf("Chunk to free: blocks=%d, ptr=%d\n", node->value->blockCount, node->value->memory);

    size_t nodeSize = node->value->blockCount * (BLOCK_SIZE << 10);

    if (node == NULL)
        return 0;

    removeFromList(node, &_usedList);
    pushFront(node, &_freeList);

    _usedCount--;
    _freeCount++;
    _totalFreeSize += nodeSize;

    if (nodeSize < _minFreeSize)
        _minFreeSize = nodeSize;
    if (nodeSize > _maxFreeSize)
        _maxFreeSize = nodeSize;

    return 1;
}
//-----------------------------------------------------------------------------
void MetadataTemplateManager::collectDescriptors()
{
    QStringList fileNames;
    // Collect predefined and user-defined template descriptors.
    // A user-defined descriptor will supercede a predefined one with the same
    // base name.
    // A user may also remove a predefined template by overriding it with one
    // that does not match any object.
    // wxDir::GetAllFiles(config().getCodeTemplatesPath(), &fileNames,
    //     QString::fromLatin1("*.template"), wxDIR_FILES);
	QStringList templateFilter;
	templateFilter << QString::fromLatin1("*.template");
	fileNames = QDir(config().getCodeTemplatesPath())
				.entryList(templateFilter, QDir::Files);
    QString userPath = config().getUserCodeTemplatesPath();

	QDir userPathDir(userPath);
    if (userPathDir.exists()) {
		fileNames << userPathDir.entryList(templateFilter, QDir::Files);
        // wxDir::GetAllFiles(userPath, &fileNames, QString::fromLatin1("*.template"), wxDIR_FILES);
	}
    descriptorsM.clear();
    for (int i = 0; i < fileNames.size(); i++)
    {
        QFileInfo fileName(fileNames[i]);
        TemplateDescriptorPtr tdp = findDescriptor(fileName.baseName());
        if (tdp)
        {
            // Present already - override it (and re-check matching).
            tdp->setTemplateFileName(fileName);
            if (!tdp->matches(metadataItemM))
                descriptorsM.remove(tdp);
        }
        else
        {
            tdp.reset(new TemplateDescriptor(fileName, metadataItemM));
            if (tdp->matches(metadataItemM))
                descriptorsM.push_back(tdp);
        }
    }
    // Sort everything by menu position.
    descriptorsM.sort(templateDescriptorPointerLT);
}
Exemple #3
0
// Called in ISR context
// Called by USBDevice on Endpoint0 request
// This is used to handle extensions to standard requests
// and class specific requests
// Return true if class handles this request
bool USBHID::USBCallback_request() {
    bool success = false;
    CONTROL_TRANSFER * transfer = getTransferPtr();
    uint8_t *hidDescriptor;

    // Process additional standard requests

    if ((transfer->setup.bmRequestType.Type == STANDARD_TYPE))
    {
        switch (transfer->setup.bRequest)
        {
            case GET_DESCRIPTOR:
                switch (DESCRIPTOR_TYPE(transfer->setup.wValue))
                {
                    case REPORT_DESCRIPTOR:
                        if ((reportDesc() != NULL) \
                            && (reportDescLength() != 0))
                        {
                            transfer->remaining = reportDescLength();
                            transfer->ptr = reportDesc();
                            transfer->direction = DEVICE_TO_HOST;
                            success = true;
                        }
                        break;
                    case HID_DESCRIPTOR:
                            // Find the HID descriptor, after the configuration descriptor
                            hidDescriptor = findDescriptor(HID_DESCRIPTOR);
                            if (hidDescriptor != NULL)
                            {
                                transfer->remaining = HID_DESCRIPTOR_LENGTH;
                                transfer->ptr = hidDescriptor;
                                transfer->direction = DEVICE_TO_HOST;
                                success = true;
                            }
                            break;

                    default:
                        break;
                }
                break;
            default:
                break;
        }
    }

    // Process class-specific requests

    if (transfer->setup.bmRequestType.Type == CLASS_TYPE)
    {
        switch (transfer->setup.bRequest)
        {
             case SET_REPORT:
                // First byte will be used for report ID
                outputReport.data[0] = transfer->setup.wValue & 0xff;
                outputReport.length = transfer->setup.wLength + 1;

                transfer->remaining = sizeof(outputReport.data) - 1;
                transfer->ptr = &outputReport.data[1];
                transfer->direction = HOST_TO_DEVICE;
                transfer->notify = true;
                success = true;
            default:
                break;
        }
    }

    return success;
}