Пример #1
0
static QStringList childKeysOrGroups(HKEY parentHandle, QSettingsPrivate::ChildSpec spec)
{
    QStringList result;
    DWORD numKeys;
    DWORD maxKeySize;
    DWORD numSubgroups;
    DWORD maxSubgroupSize;

    // Find the number of keys and subgroups, as well as the max of their lengths.
    LONG res = RegQueryInfoKey(parentHandle, 0, 0, 0, &numSubgroups, &maxSubgroupSize, 0,
                               &numKeys, &maxKeySize, 0, 0, 0);

    if (res != ERROR_SUCCESS) {
        qWarning("QSettings: RegQueryInfoKey() failed: %s", errorCodeToString(res).toLatin1().data());
        return result;
    }

    ++maxSubgroupSize;
    ++maxKeySize;

    int n;
    int m;
    if (spec == QSettingsPrivate::ChildKeys) {
        n = numKeys;
        m = maxKeySize;
    } else {
        n = numSubgroups;
        m = maxSubgroupSize;
    }

    /* The size does not include the terminating null character. */
    ++m;

    // Get the list
    QByteArray buff(m * sizeof(wchar_t), 0);
    for (int i = 0; i < n; ++i) {
        QString item;
        DWORD l = buff.size() / sizeof(wchar_t);
        if (spec == QSettingsPrivate::ChildKeys) {
            res = RegEnumValue(parentHandle, i, reinterpret_cast<wchar_t *>(buff.data()), &l, 0, 0, 0, 0);
        } else {
            res = RegEnumKeyEx(parentHandle, i, reinterpret_cast<wchar_t *>(buff.data()), &l, 0, 0, 0, 0);
        }
        if (res == ERROR_SUCCESS)
            item = QString::fromWCharArray((const wchar_t *)buff.constData(), l);

        if (res != ERROR_SUCCESS) {
            qWarning("QSettings: RegEnumValue failed: %s", errorCodeToString(res).toLatin1().data());
            continue;
        }
        if (item.isEmpty())
            item = QLatin1String(".");
        result.append(item);
    }
    return result;
}
Пример #2
0
void QWinSettingsPrivate::remove(const QString &uKey)
{
    if (writeHandle() == 0) {
        setStatus(QSettings::AccessError);
        return;
    }

    QString rKey = escapedKey(uKey);

    // try to delete value bar in key foo
    LONG res;
    HKEY handle = openKey(writeHandle(), registryPermissions, keyPath(rKey));
    if (handle != 0) {
        res = RegDeleteValue(handle, reinterpret_cast<const wchar_t *>(keyName(rKey).utf16()));
        RegCloseKey(handle);
    }

    // try to delete key foo/bar and all subkeys
    handle = openKey(writeHandle(), registryPermissions, rKey);
    if (handle != 0) {
        deleteChildGroups(handle);

        if (rKey.isEmpty()) {
            QStringList childKeys = childKeysOrGroups(handle, QSettingsPrivate::ChildKeys);

            for (int i = 0; i < childKeys.size(); ++i) {
                QString group = childKeys.at(i);

                LONG res = RegDeleteValue(handle, reinterpret_cast<const wchar_t *>(group.utf16()));
                if (res != ERROR_SUCCESS) {
                    qWarning("QSettings: RegDeleteValue failed on subkey \"%s\": %s",
                              group.toLatin1().data(), errorCodeToString(res).toLatin1().data());
                }
            }
        } else {
#if defined(Q_OS_WINCE)
            // For WinCE always Close the handle first.
            RegCloseKey(handle);
#endif
            res = RegDeleteKey(writeHandle(), reinterpret_cast<const wchar_t *>(rKey.utf16()));

            if (res != ERROR_SUCCESS) {
                qWarning("QSettings: RegDeleteKey failed on key \"%s\": %s",
                            rKey.toLatin1().data(), errorCodeToString(res).toLatin1().data());
            }
        }
        RegCloseKey(handle);
    }
}
Пример #3
0
std::string getCLErrorString(const cl::Error& err)
{
    std::ostringstream ss;
    ss << "Error:" << err.what() << "(" << err.err() << "), " << errorCodeToString(err.err()) << " " << getCLErrorResolveHint(
           err.err()) << std::endl;
    return ss.str();
}
Пример #4
0
void LogOpenCLError(cl_int err, const char* message) {
    if (err != CL_SUCCESS) {
        std::ostringstream errorMessage;
        errorMessage << "OpenCL Error " << err << ": " << errorCodeToString(err) << " " << getCLErrorResolveHint(err) << std::endl << message;
        LogErrorCustom("OpenCL", errorMessage.str());
    }
}
bool QtLockedFile::unlock()
{
    if (!isOpen()) {
        qWarning("QtLockedFile::unlock(): file is not opened");
        return false;
    }

    if (!isLocked())
        return true;

    int increment;
    if (m_lock_mode == ReadLock)
        increment = 1;
    else
        increment = SEMAPHORE_MAX;

    DWORD ret = ReleaseSemaphore(m_semaphore_hnd, increment, 0);
    if (ret == 0) {
        qWarning("QtLockedFile::unlock(): ReleaseSemaphore: %s",
                    errorCodeToString(GetLastError()).toLatin1().constData());
        return false;
    }

    m_lock_mode = QtLockedFile::NoLock;
    remove();
    return true;
}
Пример #6
0
	static int GLXErrorHandler(Display* display, XErrorEvent* ev) {
		contextErrorOccured = xdl_true;

		char errorstring[128];
		XGetErrorText(display, ev->error_code, errorstring, 128);
		XDEVL_MODULEX_ERROR(XdevLOpenGLContextGLX, "Error Code  : " << errorstring << std::endl);
		XDEVL_MODULEX_ERROR(XdevLOpenGLContextGLX, "Request Code: " << errorCodeToString(ev->request_code) << std::endl);
		XDEVL_MODULEX_ERROR(XdevLOpenGLContextGLX, "Minor Code  : " << (xdl_int)ev->minor_code << std::endl);
		return 0;
	}
QtLockedFile::~QtLockedFile()
{
    if (isOpen())
        unlock();
    if (m_mutex_hnd != 0) {
        DWORD ret = CloseHandle(m_mutex_hnd);
        if (ret == 0) {
            qWarning("QtLockedFile::~QtLockedFile(): CloseHandle (mutex): %s",
                        errorCodeToString(GetLastError()).toLatin1().constData());
        }
        m_mutex_hnd = 0;
    }
    if (m_semaphore_hnd != 0) {
        DWORD ret = CloseHandle(m_semaphore_hnd);
        if (ret == 0) {
            qWarning("QtLockedFile::~QtLockedFile(): CloseHandle (semaphore): %s",
                        errorCodeToString(GetLastError()).toLatin1().constData());
        }
        m_semaphore_hnd = 0;
    }
}
Пример #8
0
QWinSettingsPrivate::~QWinSettingsPrivate()
{
    if (deleteWriteHandleOnExit && writeHandle() != 0) {
#if defined(Q_OS_WINCE)
        remove(regList.at(0).key()); 
#else
        QString emptyKey;
        DWORD res = RegDeleteKey(writeHandle(), reinterpret_cast<const wchar_t *>(emptyKey.utf16()));
        if (res != ERROR_SUCCESS) {
            qWarning("QSettings: Failed to delete key \"%s\": %s",
                    regList.at(0).key().toLatin1().data(), errorCodeToString(res).toLatin1().data());
        }
#endif
    }

    for (int i = 0; i < regList.size(); ++i)
        regList[i].close();
}
Пример #9
0
void Net::DownloadHandler::processFinishedDownload()
{
    QString url = m_reply->url().toString();
    qDebug("Download finished: %s", qUtf8Printable(url));
    // Check if the request was successful
    if (m_reply->error() != QNetworkReply::NoError) {
        // Failure
        qDebug("Download failure (%s), reason: %s", qUtf8Printable(url), qUtf8Printable(errorCodeToString(m_reply->error())));
        emit downloadFailed(m_downloadRequest.url(), errorCodeToString(m_reply->error()));
        this->deleteLater();
    }
    else {
        // Check if the server ask us to redirect somewhere else
        const QVariant redirection = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
        if (redirection.isValid()) {
            // We should redirect
            handleRedirection(redirection.toUrl());
        }
        else {
            // Success
            QByteArray replyData = m_reply->readAll();
            if (m_reply->rawHeader("Content-Encoding") == "gzip") {
                // decompress gzip reply
                replyData = Utils::Gzip::decompress(replyData);
            }

            if (m_downloadRequest.saveToFile()) {
                QString filePath;
                if (saveToFile(replyData, filePath))
                    emit downloadFinished(m_downloadRequest.url(), filePath);
                else
                    emit downloadFailed(m_downloadRequest.url(), tr("I/O Error"));
            }
            else {
                emit downloadFinished(m_downloadRequest.url(), replyData);
            }

            this->deleteLater();
        }
    }
}
Пример #10
0
static void deleteChildGroups(HKEY parentHandle)
{
    QStringList childGroups = childKeysOrGroups(parentHandle, QSettingsPrivate::ChildGroups);

    for (int i = 0; i < childGroups.size(); ++i) {
        QString group = childGroups.at(i);

        // delete subgroups in group
        HKEY childGroupHandle = openKey(parentHandle, registryPermissions, group);
        if (childGroupHandle == 0)
            continue;
        deleteChildGroups(childGroupHandle);
        RegCloseKey(childGroupHandle);

        // delete group itself
        LONG res = RegDeleteKey(parentHandle, reinterpret_cast<const wchar_t *>(group.utf16()));
        if (res != ERROR_SUCCESS) {
            qWarning("QSettings: RegDeleteKey failed on subkey \"%s\": %s",
                      group.toLatin1().data(), errorCodeToString(res).toLatin1().data());
            return;
        }
    }
}
Пример #11
0
cl::Program* KernelManager::buildProgram(const std::string& fileName, const std::string& header /*= ""*/, const std::string& defines /*= ""*/, bool& wasBuilt) {
    wasBuilt = false;
    std::string absoluteFileName = fileName;
    if (!filesystem::fileExists(absoluteFileName)) {
        // Search in include directories added by modules
        const std::vector<std::string> openclSearchPaths = OpenCL::getPtr()->getCommonIncludeDirectories();

        for (size_t i=0; i<openclSearchPaths.size(); i++) {
            if (filesystem::fileExists(openclSearchPaths[i]+"/"+fileName)) {
                absoluteFileName = openclSearchPaths[i]+"/"+fileName;
                break;
            }
        }
    }

    std::pair <ProgramMap::iterator, ProgramMap::iterator> range = programs_.equal_range(absoluteFileName);

    for (ProgramMap::iterator it = range.first; it != range.second; ++it) {
        if (it->second.defines == defines) {
            return it->second.program;
        }
    }

    cl::Program* program = new cl::Program();

    try {
        *program = cl::Program(OpenCL::buildProgram(absoluteFileName, header, defines));

        try {
            std::vector<cl::Kernel> kernels;
            program->createKernels(&kernels);

            for (std::vector<cl::Kernel>::iterator kernelIt = kernels.begin(); kernelIt != kernels.end(); ++kernelIt) {
                kernels_.insert(std::pair<cl::Program*, cl::Kernel*>(program, new cl::Kernel(*kernelIt)));
            }
        } catch (cl::Error& err) {
            LogError(absoluteFileName << " Failed to create kernels, Error:" << err.what() << "(" << err.err() << "), " << errorCodeToString(
                         err.err()) << std::endl);
        }
    } catch (cl::Error&) {
    }

    ProgramIdentifier uniqueProgram{ program, header, defines };
    programs_.insert(std::pair<std::string, ProgramIdentifier>(absoluteFileName, uniqueProgram));
    startFileObservation(absoluteFileName);
    wasBuilt = true;
    return program;
}
Пример #12
0
void KernelManager::fileChanged(const std::string& fileName) {
    std::pair <ProgramMap::iterator, ProgramMap::iterator> programRange = programs_.equal_range(fileName);

    for (ProgramMap::iterator programIt = programRange.first; programIt != programRange.second; ++programIt) {
        cl::Program* program = programIt->second.program;
        // Get all kernels associated with the program
        std::pair <KernelMap::iterator, KernelMap::iterator> kernelRange = kernels_.equal_range(program);
        std::vector<std::string> kernelNames;

        for (KernelMap::iterator kernelIt = kernelRange.first; kernelIt != kernelRange.second; ++kernelIt) {
            std::string thisKernelName;

            try {
                kernelIt->second->getInfo(CL_KERNEL_FUNCTION_NAME, &thisKernelName);
            } catch (cl::Error&) {
            }

            kernelNames.push_back(thisKernelName);
        }

        try {
            LogInfo(fileName + " building program with defines: " + programIt->second.defines);
            *program = OpenCL::buildProgram(fileName, programIt->second.header, programIt->second.defines);
            LogInfo(fileName + " finished building program");
            std::vector<cl::Kernel> newKernels;

            try {
                LogInfo(fileName + " creating kernels");
                program->createKernels(&newKernels);
            } catch (cl::Error& err) {
                LogError(fileName << " Failed to create kernels, error:" << err.what() << "(" << err.err() << "), " << errorCodeToString(
                             err.err()) << std::endl);
                throw err;
            }

            // Find corresponding old kernel for each newly compiled kernel.
            // Add kernel if it was not found
            for (std::vector<cl::Kernel>::iterator newKernelIt = newKernels.begin(); newKernelIt != newKernels.end(); ++newKernelIt) {
                std::string newKernelName;
                newKernelIt->getInfo(CL_KERNEL_FUNCTION_NAME, &newKernelName);
                std::vector<std::string>::iterator kernelNameIt = std::find(kernelNames.begin(), kernelNames.end(), newKernelName);

                if (kernelNameIt != kernelNames.end()) {
                    size_t index = kernelNameIt - kernelNames.begin();
                    KernelMap::iterator oldKernelIt(kernelRange.first);

                    for (size_t j = 0; j < index; ++j, ++oldKernelIt) {};

                    *(oldKernelIt->second) = *newKernelIt;
                    // Notify that kernel has been recompiled
                    std::pair<KernelOwnerMap::iterator, KernelOwnerMap::iterator> kernelOwnerRange = kernelOwners_.equal_range(oldKernelIt->second);
                    for (KernelOwnerMap::iterator kernelOwnerIt = kernelOwnerRange.first; kernelOwnerIt != kernelOwnerRange.second; ++kernelOwnerIt) {
                        kernelOwnerIt->second->notifyObserversKernelCompiled(&(*newKernelIt));
                    }
                } else {
                    // New kernel, no need to notify KernelOwner since there cannot be any
                    kernels_.insert(std::pair<cl::Program*, cl::Kernel*>(program, new cl::Kernel(*newKernelIt)));
                }

            }

            InviwoApplication::getPtr()->playSound(InviwoApplication::Message::Ok);

        } catch (cl::Error& err) {
            LogError(fileName << " Failed to create kernels, error:" << err.what() << "(" << err.err() << "), " << errorCodeToString(
                         err.err()) << std::endl);
            InviwoApplication::getPtr()->playSound(InviwoApplication::Message::Error);
        }
    }
}
Пример #13
0
void OpenCL::setDevice(cl::Device device, bool glSharing) {
    try {
        // Check if we are setting the same device
        if (gpuDevice_() == device()) {
            std::vector<cl_context_properties> sharingProperties = getGLSharingContextProperties();
            std::vector<cl_context_properties> contextProperties = gpuContext_.getInfo<CL_CONTEXT_PROPERTIES>();
            bool sharingEnabled = (std::find(contextProperties.begin(), contextProperties.end(),
                                             *sharingProperties.begin()) != contextProperties.end());

            if (sharingEnabled == glSharing) {
                // The device and sharing properties are the same.
                // No need to update the device
                return;
            }
        }

        gpuDevice_ = device;
        cl::Platform platform = device.getInfo<CL_DEVICE_PLATFORM>();
        std::vector<cl_context_properties> properties;

        if (glSharing)
            properties = getGLSharingContextProperties();

        cl_context_properties platformProperties[] = {CL_CONTEXT_PLATFORM, (cl_context_properties)platform(), 0};
        properties.insert(properties.end(), platformProperties, platformProperties+ sizeof(platformProperties)/sizeof(cl_context_properties));

        try
        {
            gpuContext_ = cl::Context(gpuDevice_, &properties[0]);
        } catch (cl::Error&)
        {
            LogInfo("ERROR: Unable to create OpenCL context. Trying to create without openGL sharing... ");
            properties.clear();
            properties.insert(properties.end(), platformProperties, platformProperties+ sizeof(platformProperties)/sizeof(cl_context_properties));
            gpuContext_ = cl::Context(gpuDevice_, &properties[0]);
            LogInfo("Succeeded creating OpenCL without OpenGL sharing. ");
        }

        cl_command_queue_properties queueProperties = 0;
        cl_command_queue_properties supportedQueueProperties;
        gpuDevice_.getInfo(CL_DEVICE_QUEUE_PROPERTIES, &supportedQueueProperties);
#if IVW_PROFILING

        if (supportedQueueProperties & CL_QUEUE_PROFILING_ENABLE)
            queueProperties |= CL_QUEUE_PROFILING_ENABLE;

#endif
        synchronosGPUQueue_ = cl::CommandQueue(gpuContext_, gpuDevice_, queueProperties);

        if (supportedQueueProperties & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE)
            queueProperties |= CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE;

        asyncGPUQueue_ = cl::CommandQueue(gpuContext_, gpuDevice_, queueProperties);
        STRING_CLASS deviceExtensions = gpuDevice_.getInfo<CL_DEVICE_EXTENSIONS>();
        size_t foundAt = deviceExtensions.find_first_of("cl_khr_gl_event");

        if (foundAt != std::string::npos) {
            // Efficient cl/gl synchronization possible
        }
    } catch (cl::Error& err) {
        LogError("Faile to set OpenCL device. " << err.what() << "(" << err.err() << "), " << errorCodeToString(err.err()) << std::endl);
    }
}
Пример #14
0
bool QtLockedFile::lock(LockMode mode, bool block)
{
    if (!isOpen()) {
        qWarning("QtLockedFile::lock(): file is not opened");
        return false;
    }

    if (mode == m_lock_mode)
        return true;

    if (m_lock_mode != 0)
        unlock();

    if (m_semaphore_hnd == 0) {
        QFileInfo fi(*this);
        QString sem_name = QString::fromLatin1(SEMAPHORE_PREFIX)
                           + fi.absoluteFilePath().toLower();

        m_semaphore_hnd = CreateSemaphoreW(0, SEMAPHORE_MAX, SEMAPHORE_MAX,
                                           (TCHAR*)sem_name.utf16());

        if (m_semaphore_hnd == 0) {
            qWarning("QtLockedFile::lock(): CreateSemaphore: %s",
                     errorCodeToString(GetLastError()).toLatin1().constData());
            return false;
        }
    }

    bool gotMutex = false;
    int decrement;
    if (mode == ReadLock) {
        decrement = 1;
    } else {
        decrement = SEMAPHORE_MAX;
        if (m_mutex_hnd == 0) {
            QFileInfo fi(*this);
            QString mut_name = QString::fromLatin1(MUTEX_PREFIX)
                               + fi.absoluteFilePath().toLower();

            m_mutex_hnd = CreateMutexW(NULL, FALSE, (TCHAR*)mut_name.utf16());

            if (m_mutex_hnd == 0) {
                qWarning("QtLockedFile::lock(): CreateMutex: %s",
                         errorCodeToString(GetLastError()).toLatin1().constData());
                return false;
            }
        }
        DWORD res = WaitForSingleObject(m_mutex_hnd, block ? INFINITE : 0);
        if (res == WAIT_TIMEOUT)
            return false;
        if (res == WAIT_FAILED) {
            qWarning("QtLockedFile::lock(): WaitForSingleObject (mutex): %s",
                     errorCodeToString(GetLastError()).toLatin1().constData());
            return false;
        }
        gotMutex = true;
    }

    for (int i = 0; i < decrement; ++i) {
        DWORD res = WaitForSingleObject(m_semaphore_hnd, block ? INFINITE : 0);
        if (res == WAIT_TIMEOUT) {
            if (i) {
                // A failed nonblocking rw locking. Undo changes to semaphore.
                if (ReleaseSemaphore(m_semaphore_hnd, i, NULL) == 0) {
                    qWarning("QtLockedFile::unlock(): ReleaseSemaphore: %s",
                             errorCodeToString(GetLastError()).toLatin1().constData());
                    // Fall through
                }
            }
            if (gotMutex)
                ReleaseMutex(m_mutex_hnd);
            return false;
	}
        if (res != WAIT_OBJECT_0) {
            if (gotMutex)
                ReleaseMutex(m_mutex_hnd);
            qWarning("QtLockedFile::lock(): WaitForSingleObject (semaphore): %s",
                        errorCodeToString(GetLastError()).toLatin1().constData());
            return false;
        }
    }

    m_lock_mode = mode;
    if (gotMutex)
        ReleaseMutex(m_mutex_hnd);
    return true;
}
Пример #15
0
void DownloadThread::processDlFinished(QNetworkReply* reply) {
  QString url = reply->url().toString();
  qDebug("Download finished: %s", qPrintable(url));
  // Check if the request was successful
  if (reply->error() != QNetworkReply::NoError) {
    // Failure
    qDebug("Download failure (%s), reason: %s", qPrintable(url), qPrintable(errorCodeToString(reply->error())));
    emit downloadFailure(url, errorCodeToString(reply->error()));
    reply->deleteLater();
    return;
  }
  // Check if the server ask us to redirect somewhere lese
  const QVariant redirection = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
  if (redirection.isValid()) {
    // We should redirect
    QUrl newUrl = redirection.toUrl();
    // Resolve relative urls
    if (newUrl.isRelative())
        newUrl = reply->url().resolved(newUrl);
    const QString newUrlString = newUrl.toString();
    qDebug("Redirecting from %s to %s", qPrintable(url), qPrintable(newUrlString));
    m_redirectMapping.insert(newUrlString, url);
    // redirecting with first cookies
    downloadUrl(newUrlString, m_networkManager.cookieJar()->cookiesForUrl(url));
    reply->deleteLater();
    return;
  }
  // Checking if it was redirected, restoring initial URL
  if (m_redirectMapping.contains(url)) {
    url = m_redirectMapping.take(url);
  }
  // Success
  QTemporaryFile *tmpfile = new QTemporaryFile;
  if (tmpfile->open()) {
    tmpfile->setAutoRemove(false);
    QString filePath = tmpfile->fileName();
    qDebug("Temporary filename is: %s", qPrintable(filePath));
    if (reply->isOpen() || reply->open(QIODevice::ReadOnly)) {
      QByteArray replyData = reply->readAll();
      if (reply->rawHeader("Content-Encoding") == "gzip") {
        // uncompress gzip reply
        replyData = gUncompress(reinterpret_cast<unsigned char*>(replyData.data()), replyData.length());
      }
      tmpfile->write(replyData);
      tmpfile->close();
      // XXX: tmpfile needs to be deleted on Windows before using the file
      // or it will complain that the file is used by another process.
      delete tmpfile;
      // Send finished signal
      emit downloadFinished(url, filePath);
    } else {
      delete tmpfile;
      fsutils::forceRemove(filePath);
      // Error when reading the request
      emit downloadFailure(url, tr("I/O Error"));
    }
  } else {
    delete tmpfile;
    emit downloadFailure(url, tr("I/O Error"));
  }
  // Clean up
  reply->deleteLater();
}
Пример #16
0
void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value)
{
    if (writeHandle() == 0) {
        setStatus(QSettings::AccessError);
        return;
    }

    QString rKey = escapedKey(uKey);

    HKEY handle = createOrOpenKey(writeHandle(), registryPermissions, keyPath(rKey));
    if (handle == 0) {
        setStatus(QSettings::AccessError);
        return;
    }

    DWORD type;
    QByteArray regValueBuff;

    // Determine the type
    switch (value.type()) {
        case QVariant::List:
        case QVariant::StringList: {
            // If none of the elements contains '\0', we can use REG_MULTI_SZ, the
            // native registry string list type. Otherwise we use REG_BINARY.
            type = REG_MULTI_SZ;
            QStringList l = variantListToStringList(value.toList());
            QStringList::const_iterator it = l.constBegin();
            for (; it != l.constEnd(); ++it) {
                if ((*it).length() == 0 || stringContainsNullChar(*it)) {
                    type = REG_BINARY;
                    break;
                }
            }

            if (type == REG_BINARY) {
                QString s = variantToString(value);
                regValueBuff = QByteArray((const char*)s.utf16(), s.length() * 2);
            } else {
                QStringList::const_iterator it = l.constBegin();
                for (; it != l.constEnd(); ++it) {
                    const QString &s = *it;
                    regValueBuff += QByteArray((const char*)s.utf16(), (s.length() + 1) * 2);
                }
                regValueBuff.append((char)0);
                regValueBuff.append((char)0);
            }
            break;
        }

        case QVariant::Int:
        case QVariant::UInt: {
            type = REG_DWORD;
            qint32 i = value.toInt();
            regValueBuff = QByteArray((const char*)&i, sizeof(qint32));
            break;
        }

        case QVariant::LongLong:
        case QVariant::ULongLong: {
            type = REG_QWORD;
            qint64 i = value.toLongLong();
            regValueBuff = QByteArray((const char*)&i, sizeof(qint64));
            break;
        }

        case QVariant::ByteArray:
            // fallthrough intended

        default: {
            // If the string does not contain '\0', we can use REG_SZ, the native registry
            // string type. Otherwise we use REG_BINARY.
            QString s = variantToString(value);
            type = stringContainsNullChar(s) ? REG_BINARY : REG_SZ;
            if (type == REG_BINARY) {
                regValueBuff = QByteArray((const char*)s.utf16(), s.length() * 2);
            } else {
                regValueBuff = QByteArray((const char*)s.utf16(), (s.length() + 1) * 2);
            }
            break;
        }
    }

    // set the value
    LONG res = RegSetValueEx(handle, reinterpret_cast<const wchar_t *>(keyName(rKey).utf16()), 0, type,
                             reinterpret_cast<const unsigned char*>(regValueBuff.constData()),
                             regValueBuff.size());

    if (res == ERROR_SUCCESS) {
        deleteWriteHandleOnExit = false;
    } else {
        qWarning("QSettings: failed to set subkey \"%s\": %s",
                rKey.toLatin1().data(), errorCodeToString(res).toLatin1().data());
        setStatus(QSettings::AccessError);
    }

    RegCloseKey(handle);
}
Пример #17
0
void OpenCL::initialize(bool glSharing) {
    try {
        std::vector<cl::Platform> platforms;
        cl::Platform::get(&platforms);

        if (platforms.size() == 0) {
            LogError("No OpenCL platforms found" << std::endl);
            return;
        }

        cl::Platform platform;
        cl::Device device;
        getBestGPUDeviceOnSystem(device, platform);
        setDevice(device, glSharing);
    } catch (cl::Error& err) {
        LogError("ERROR: Failed to initialize OpenCL. " << err.what() << "(" << err.err() << "), " << errorCodeToString(err.err()) << std::endl);
    }
}