std::string Path::toUTF8() const { #ifdef OSX CFRange myRange = CFRangeMake(0, CFStringGetLength(_myString)); CFIndex myBufferSize = 0; std::string myResult; CFIndex myCharCount = CFStringGetBytes(_myString, myRange, kCFStringEncodingUTF8, '?', FALSE, 0, 0, &myBufferSize); if (myCharCount) { myResult.resize(myBufferSize); CFIndex myExCharCount = CFStringGetBytes(_myString, myRange, kCFStringEncodingUTF8, '?', FALSE, (UInt8*)&(*(myResult.begin())), myBufferSize, &myBufferSize); ASSURE_WITH(AssurePolicy::Throw, myExCharCount == myCharCount); } return myResult; #elif _WIN32 if (_myLocaleChars == 0) { return std::string(); } // convert from active codepage to WideChars AC_SIZE_TYPE myWCharSize = MultiByteToWideChar(CP_ACP, getMultibyteToWideCharFlags(), _myLocaleChars, -1, 0, 0); if (myWCharSize == 0) { throw UnicodeException(errorDescription(lastError()), PLUS_FILE_LINE); } LPWSTR myWChars = new WCHAR[myWCharSize]; MultiByteToWideChar(CP_ACP, getMultibyteToWideCharFlags(), _myLocaleChars, -1, myWChars, myWCharSize); // convert from WideChars to UTF8 AC_SIZE_TYPE myUTF8Size = WideCharToMultiByte(CP_UTF8, 0, myWChars, -1, 0, 0, 0, 0); if (myUTF8Size == 0) { throw UnicodeException(errorDescription(lastError()), PLUS_FILE_LINE); } char * myUTF8Chars = new char[myUTF8Size]; WideCharToMultiByte(CP_UTF8, 0, myWChars, -1, myUTF8Chars, myUTF8Size, 0, 0); std::string myUTF8String(myUTF8Chars); delete [] myWChars; delete [] myUTF8Chars; return myUTF8String; #else if (_myLocaleChars == 0) { return std::string(); } gchar * myUTF = g_filename_to_utf8(_myLocaleChars, -1, 0, 0, 0); if ( ! myUTF) { throw UnicodeException(std::string("Failed to convert filename '") + _myLocaleChars + "' to UTF8.", PLUS_FILE_LINE); } std::string myUTF8String(myUTF); g_free(myUTF); return myUTF8String; #endif }
int Maestro::throwIfError(int code) { if (code < 0) { // code is an error, throw T* err = new T(errorDescription(code)); throw err; } return code; }
void Path::assign(const char * theString, StringEncoding theEncoding) { free(); switch (theEncoding) { case UTF8: #ifdef OSX _myString = CFStringCreateWithCString(NULL, theString, kCFStringEncodingUTF8); #elif _WIN32 { // convert from UTF8 to WideChars AC_SIZE_TYPE myWCharSize = MultiByteToWideChar(CP_UTF8, getMultibyteToWideCharFlags(), theString, -1, 0, 0); if (myWCharSize == 0) { throw UnicodeException(errorDescription(lastError()), PLUS_FILE_LINE); } LPWSTR myWChars = new WCHAR[myWCharSize]; MultiByteToWideChar(CP_UTF8, getMultibyteToWideCharFlags(), theString, -1, myWChars, myWCharSize); // convert from WideChars to current codepage AC_SIZE_TYPE myLocaleSize = WideCharToMultiByte(CP_ACP, 0, myWChars, -1, 0, 0, 0, 0); if (myLocaleSize == 0) { throw UnicodeException(errorDescription(lastError()), PLUS_FILE_LINE); } _myLocaleChars = static_cast<char *>(malloc(myLocaleSize)); WideCharToMultiByte(CP_ACP, 0, myWChars, -1, _myLocaleChars, myLocaleSize, 0, 0); delete [] myWChars; } #else _myLocaleChars = g_filename_from_utf8(theString, -1, 0, 0, 0); #endif break; case Locale: #ifdef OSX _myString = CFStringCreateWithCString(NULL, theString, CFStringGetSystemEncoding()); #elif _WIN32 _myLocaleChars = _strdup(theString); #else _myLocaleChars = g_strdup(theString); #endif break; } }
std::string &Formatter::format( const Message &message ) { _buffer.clear(); if (!message.group().empty()) { _buffer.append( "[" ); _buffer.append( message.group() ); if (!message.category().empty()) { _buffer.append( "::" ); _buffer.append( message.category() ); } _buffer.append( "] " ); } _buffer.append( errorDescription( message.level()) ); _buffer.append( message.message() ); _buffer.append( "\n" ); return _buffer; }
static void proxyAutoConfigurationResultCallback(void *context, CFArrayRef proxies, CFErrorRef error) { // We only expect a single result callback per invocation. Stop our runloop to unblock our caller. CFRunLoopStop(CFRunLoopGetCurrent()); Vector<ProxyServer>* proxyServers = (Vector<ProxyServer>*)context; if (!proxies) { ASSERT(error); RetainPtr<CFStringRef> errorDescriptionCF(AdoptCF, CFErrorCopyDescription(error)); String errorDescription(errorDescriptionCF.get()); LOG(Network, "Failed to process proxy auto-configuration file with error: %s", errorDescription.utf8().data()); return; } processProxyServers(*proxyServers, proxies, 0); }
void Plugin::Init (ICoreProxy_ptr) { const auto& path = Util::GetSysPath (Util::SysPath::Share, "dlniwe/desc", "device.xml"); if (path.isEmpty ()) { qWarning () << Q_FUNC_INFO << "cannot find device description XML file."; return; } XSD_.reset (new Util::XmlSettingsDialog); XSD_->RegisterObject (&XmlSettingsManager::Instance (), "dlniwesettings.xml"); HU::HDeviceConfiguration devConf; devConf.setPathToDeviceDescription (path); HAV::HAvDeviceModelCreator avCreator; HAV::HMediaServerDeviceConfiguration msConfig; auto fsSource = new HAV::HFileSystemDataSource ({}); HAV::HContentDirectoryServiceConfiguration cdsConfig; cdsConfig.setDataSource (fsSource, true); msConfig.setContentDirectoryConfiguration (cdsConfig); avCreator.setMediaServerConfiguration (msConfig); HU::HDeviceHostConfiguration hostConf (devConf); hostConf.setDeviceModelCreator (avCreator); auto host = new HU::HDeviceHost (); if (!host->init (hostConf)) qWarning () << Q_FUNC_INFO << host->errorDescription (); auto pathsMgr = new FSPathsManager (fsSource); XSD_->SetDataSource ("RootPathsView", pathsMgr->GetModel ()); }
/** * This method looks for any naif errors that might have occurred. It * then compares the error to a list of known naif errors and converts * the error into an iException. * * @param resetNaif True if the NAIF error status should be reset (naif calls valid) */ void NaifStatus::CheckErrors(bool resetNaif) { if(!initialized) { SpiceChar returnAct[32] = "RETURN"; SpiceChar printAct[32] = "NONE"; erract_c ( "SET", sizeof(returnAct), returnAct); // Reset action to return errprt_c ( "SET", sizeof(printAct), printAct); // ... and print nothing initialized = true; } // Do nothing if NAIF didn't fail //getmsg_c("", 0, NULL); if(!failed_c()) return; // This method has been documented with the information provided // from the NAIF documentation at: // naif/cspice61/packages/cspice/doc/html/req/error.html // This message is a character string containing a very terse, usually // abbreviated, description of the problem. The message is a character // string of length not more than 25 characters. It always has the form: // SPICE(...) // Short error messages used in CSPICE are CONSTANT, since they are // intended to be used in code. That is, they don't contain any data which // varies with the specific instance of the error they indicate. // Because of the brief format of the short error messages, it is practical // to use them in a test to determine which type of error has occurred. const int SHORT_DESC_LEN = 26; SpiceChar naifShort[SHORT_DESC_LEN]; getmsg_c("SHORT", SHORT_DESC_LEN, naifShort); // This message may be up to 1840 characters long. The CSPICE error handling // mechanism makes no use of its contents. Its purpose is to provide human-readable // information about errors. Long error messages generated by CSPICE routines often // contain data relevant to the specific error they describe. const int LONG_DESC_LEN = 1841; SpiceChar naifLong[LONG_DESC_LEN]; getmsg_c("LONG", LONG_DESC_LEN, naifLong); // Search for known naif errors... iString errMsg; Pvl error; PvlGroup errorDescription("ErrorDescription"); errorDescription.AddKeyword(PvlKeyword("ShortMessage", naifShort)); errorDescription.AddKeyword(PvlKeyword("LongMessage", naifLong)); error.AddGroup(errorDescription); PvlTranslationManager trans(error, "$base/translations/NaifErrors.trn"); try { errMsg = trans.Translate("ShortMessage"); } catch(iException &e) { e.Clear(); errMsg = "An unknown NAIF error has been encountered."; } try { errMsg += " " + trans.Translate("LongMessage"); } catch(iException &e) { e.Clear(); } // Now process the error if(resetNaif) { reset_c(); } errMsg += " The short explanation "; errMsg += "provided by NAIF is [" + iString(naifShort) + "]. "; errMsg += "The Naif error is [" + iString(naifLong) + "]"; throw iException::Message(iException::Spice, errMsg, _FILEINFO_); }
void Scanner::scan(const ScanArguments &arguments, QString &error) const { struct RAROpenArchiveDataEx archiveData; memset(&archiveData, 0, sizeof(struct RAROpenArchiveDataEx)); archiveData.ArcName = const_cast<char *>(m_filePath.data()); archiveData.OpenMode = RAR_OM_LIST; if (void *archive = RAROpenArchiveEx(&archiveData)) { QMap<QString, SnapshotItem *> parents; IFileContainer::Holder container; struct RARHeaderDataEx fileInfo; SnapshotItem *parent; SnapshotItem *entry; QString fileName; Location fileNameLocation; const wchar_t *path; wchar_t *sep; int res; while ((res = RARReadHeaderEx(archive, &fileInfo)) == 0 && !arguments.aborted) { path = fileInfo.FileNameW; if ((sep = wcschr(const_cast<wchar_t *>(path), L'/')) != NULL) { (*sep) = 0; SnapshotItem *&p = parents[fileName = QString::fromWCharArray(path)]; (*sep) = L'/'; if (p == NULL) { fileNameLocation = Info::location(fileName); arguments.snapshot.insert(fileNameLocation, p = parent = new SnapshotItem(m_container, fileNameLocation, fileInfo, NULL)); } else parent = p; path = (++sep); while ((sep = wcschr(const_cast<wchar_t *>(path), L'/')) != NULL) { (*sep) = 0; if (entry = parent->find(fileName = QString::fromWCharArray(path))) parent = entry; else { parent->insert(fileName, entry = new SnapshotItem(m_container, Info::location(fileName), fileInfo, parent)); parent = entry; } (*sep) = L'/'; path = (++sep); } if (!(fileName = QString::fromWCharArray(path)).isEmpty() && parent->find(fileName) == NULL) { parent->insert(fileName, new SnapshotItem(m_container, Info::location(fileName), fileInfo, parent)); } } else { SnapshotItem *&p = parents[fileName = QString::fromWCharArray(path)]; if (p == NULL) { fileNameLocation = Info::location(fileName); arguments.snapshot.insert(fileNameLocation, p = new SnapshotItem(m_container, fileNameLocation, fileInfo, NULL)); } } RARProcessFile(archive, RAR_SKIP, NULL, NULL); } if (!arguments.aborted) if (res == ERAR_END_ARCHIVE) for (Snapshot::const_iterator i = arguments.snapshot.begin(), end = arguments.snapshot.end(); i != end; ++i) static_cast<SnapshotItem *>((*i).second)->populateInfo(); else error = errorDescription(res); RARCloseArchive(archive); } }
void WMTouchPlugin::onTouch(HWND hWnd, WPARAM wParam, LPARAM lParam) { BOOL bHandled = FALSE; UINT cInputs = LOWORD(wParam); PTOUCHINPUT pInputs = new TOUCHINPUT[cInputs]; if (GetTouchInputInfo((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT))){ AC_DEBUG << "found " << cInputs << " Cursors!"; for (UINT i=0; i < cInputs; i++){ const TOUCHINPUT & ti = pInputs[i]; // create a y60 event for each InputInfo GenericEventPtr myEvent(new GenericEvent("onWMTouch", _myEventSchemaDocument, _myEventValueFactory)); NodePtr myNode = myEvent->getNode(); asl::Vector2f myPosition = product(Vector2f(static_cast<float>(ti.x), static_cast<float>(ti.y)), 0.01f); asl::Vector2f myCalibratedRelativePosition = asl::Vector2f(0.0, 0.0); float myWidth = _calibrationPositionTopRight[0] - _calibrationPositionBottomLeft[0]; float myHeight = _calibrationPositionTopRight[1] - _calibrationPositionBottomLeft[1]; if (myWidth != 0) { myCalibratedRelativePosition[0] = (myPosition[0] - _calibrationPositionBottomLeft[0]) / myWidth; } if (myHeight != 0) { myCalibratedRelativePosition[1] = (myPosition[1] - _calibrationPositionBottomLeft[1]) / myHeight; } myNode->appendAttribute<int>("id", ti.dwID); myNode->appendAttribute<Vector2f>("position", myPosition); myNode->appendAttribute<Vector2f>("calibrated_relative_position", myCalibratedRelativePosition); if (ti.dwMask & TOUCHINPUTMASKF_CONTACTAREA) { myNode->appendAttribute<Vector2f>("contactarea", product(Vector2f(static_cast<float>(ti.cxContact), static_cast<float>(ti.cyContact)), 0.01f)); } myNode->appendAttribute<bool>("inrange", (ti.dwFlags & TOUCHEVENTF_INRANGE) != 0); myNode->appendAttribute<bool>("primary", (ti.dwFlags & TOUCHEVENTF_PRIMARY) != 0); myNode->appendAttribute<bool>("nocoalesce", (ti.dwFlags & TOUCHEVENTF_NOCOALESCE) != 0); myNode->appendAttribute<bool>("palm", (ti.dwFlags & TOUCHEVENTF_PALM) != 0); // Note: we seem to be getting duplicate events, probably due to the way we are hooking the msg queue. // So we filter the events here. Only queue a DOWN event if the cursor wasn't down yet, // and only queue an UP or MOVE event if the cursor was down. if ((ti.dwFlags & TOUCHEVENTF_DOWN) != 0 && _downCursors.find(ti.dwID) == _downCursors.end()) { myNode->appendAttribute<DOMString>("type", "down"); _queuedEvents.push_back(myEvent); _downCursors.insert(ti.dwID); } else if ((ti.dwFlags & TOUCHEVENTF_UP) != 0 && _downCursors.find(ti.dwID) != _downCursors.end()) { myNode->appendAttribute<DOMString>("type", "up"); _queuedEvents.push_back(myEvent); _downCursors.erase(ti.dwID); } else if ((ti.dwFlags & TOUCHEVENTF_MOVE) != 0 && _downCursors.find(ti.dwID) != _downCursors.end()) { _queuedEvents.push_back(myEvent); myNode->appendAttribute<DOMString>("type", "move"); } } bHandled = TRUE; }else{ /* handle the error here */ AC_ERROR << errorDescription(lastError()); } // clean up delete [] pInputs; if (bHandled){ // if you handled the message, close the touch input handle and return CloseTouchInputHandle((HTOUCHINPUT)lParam); return; } };
bool DkUpnpDeviceHost::startDevicehost(QString pathToConfig) { qDebug() << "pathToConfig:" << pathToConfig; qDebug() << "starting DeviceHost"; QFile f(pathToConfig); if (!f.exists()) { qDebug() << "DkUpnpDeviceHost: config file not found"; return false; } QUuid uuid = QUuid::createUuid(); QString uuidString = uuid.toString(); uuidString.replace("{",""); uuidString.replace("}",""); QString newXMLpath = QDir::tempPath() + QDir::separator() + uuidString + ".xml"; QByteArray fileData; f.open(QIODevice::ReadOnly); //f.seek(0); fileData = f.readAll(); f.close(); QString fileText(fileData); fileText.replace("insert-new-uuid-here", uuidString); #ifdef WIN32 fileText.replace("nomacs-service.xml", QDir::temp().dirName()+"/nomacs-service.xml"); #else fileText.replace("nomacs-service.xml", "/nomacs-service.xml"); #endif // WIN32 QFile newDescriptorFile(newXMLpath); newDescriptorFile.open(QIODevice::WriteOnly); newDescriptorFile.write(fileText.toUtf8()); qDebug() << "writing file:" << newXMLpath; newDescriptorFile.close(); QFileInfo fileInfo = QFileInfo(f); QFile serviceXML(fileInfo.absolutePath() + QDir::separator() + "nomacs-service.xml"); if (!serviceXML.open(QIODevice::ReadOnly)) qDebug() << "nomacs-service.xml file does not exist"; // copy the resource file to the user tmp folder QString newServiceXMLPath = QDir::tempPath()+ QDir::separator() + "nomacs-service.xml"; QFile tmpServiceXmlFile(newServiceXMLPath); tmpServiceXmlFile.open(QIODevice::WriteOnly); tmpServiceXmlFile.write(serviceXML.readAll()); tmpServiceXmlFile.close(); serviceXML.close(); //if(!QFile::exists(newServiceXMLPath)) { // if (!serviceXML.copy(newServiceXMLPath)) // qDebug() << "unable to copy nomacs-service.xml to " << newServiceXMLPath << ", perhaps files already exists"; //} QFile newServiceXMLFile(QDir::tempPath()+ QDir::separator() + "nomacs-service.xml"); serviceXML.close(); DkUpnpDeviceModelCreator creator; Herqq::Upnp::HDeviceHostConfiguration hostConfig; hostConfig.setDeviceModelCreator(creator); Herqq::Upnp::HDeviceConfiguration config; //config.setPathToDeviceDescription(pathToConfig); config.setPathToDeviceDescription(newXMLpath); hostConfig.add(config); bool retVal = init(hostConfig); if (!retVal) { qDebug() << "error while initializing device host:\n" << errorDescription(); } if(!newDescriptorFile.remove()) qDebug() << "unable to remove upnp device.xml file"; // this->serviceXMLPath = newServiceXMLPath; if (!tmpServiceXmlFile.remove()) qDebug() << tmpServiceXmlFile.errorString(); //qDebug() << "newServiceXMLPath" << newServiceXMLPath; //if(!QFile::remove(newServiceXMLPath)) //qDebug() << "unable to remove upnp service.xml file"; return retVal; }