void GUtils::Trace(cppstring msg, gchar * psFile, int nLine) { int nLen = 0; if (psFile != NULL) { #ifdef _UNICODE nLen = wcslen(psFile); #else nLen = strlen(psFile); #endif } if ((nLen > 0) && (nLine != -1) ) { // Only print File and Line if we have something.. cppsstream ss; ss << psFile << GSTD_S("(") << nLine << GSTD_S(") : ") << msg << kOSNewlineString; OSTrace(ss.str().c_str()); } else OSTrace(msg.c_str()); GSTD_LOG(msg); }
GSkipDevice::GSkipDevice(GPortRef *pPortRef) : TBaseClass(pPortRef) { m_flashRec.signature = 0;//flash rec is ignored until this = VALID_FLASH_SIGNATURE if (!OSInitialize()) GUtils::Trace(GSTD_S("Error - GSkipDevice constructor, OSInitialize() returned false.")); }
int GPortRef::DecodeFromStream(cppistream * pInStream) { // REVISIT - use GXMLUtils to extract the element int nResult = kResponse_Error; if (pInStream != NULL) { // Get the text from the in-stream up until the next ">"... cppstring sText; std::getline(*pInStream, sText, GSTD_S('>')); if (sText.length() > 0) { sText += GSTD_S('>'); nResult = DecodeFromString(sText); } } return nResult; }
void GPortRef::EncodeToStream(cppostream * pOutStream) { // We use a single XML tag to encode the port ref to the stream. // The tag is self-terminating; all fields are attributes. // Note that the DECODE method does not require all fields to be // present and does not care about their order. // REVISIT - use GXMLUtils to just build an element an write it. if (pOutStream != NULL) { *pOutStream << GSTD_S("<") << k_sPortRefCode << GSTD_S(" "); *pOutStream << k_sPortTypeCode << GSTD_S("=\"") << GetPortType() << GSTD_S("\" "); *pOutStream << k_sLocationCode << GSTD_S("=\"") << GetLocation() << GSTD_S("\" "); *pOutStream << k_sDisplayNameCode << GSTD_S("=\"") << GetDisplayName() << GSTD_S("\" "); *pOutStream << "/>"; } }
bool GSkipBaseDevice::OSInitialize(void) { bool bResult = false; SetOSData(NULL); UInt32 nLocationID = strtoul(GetPortRefPtr()->GetDisplayName().c_str(), NULL, 0); VST_USBSpec * pSpec = NULL; VST_GetUSBSpecByLocation(GetPortRefPtr()->GetUSBVendorID(), GetPortRefPtr()->GetUSBProductID(), nLocationID, true, &pSpec); if (pSpec != NULL) { TUSBBulkDevice usbDevice = VST_MakeUSBBulkDeviceFromSpec(pSpec); if (usbDevice == NULL) { // If another app (including Classic) has the device we // can simply retry a few times. The driver should be able to get a lock // on the device at some point. int nTry = 0; while ((usbDevice == NULL) && (nTry < 4)) { usbDevice = VST_MakeUSBBulkDeviceFromSpec(pSpec); nTry++; } } delete pSpec; if (usbDevice != NULL) { SetOSData(usbDevice); bResult = true; } else GSTD_TRACE(GSTD_S("GSkipBaseDevice::OSInitialize -- Couldn't create USB device.")); } return bResult; }
int GPortRef::DecodeFromString(const cppstring & sInString) { int nResult = kResponse_Error; cppstring::size_type nSearchStartPos = 0; cppstring::size_type nCurrentPos = 0; cppstring::size_type nNextPos = 0; cppstring::size_type nTestPos = 0; // ensure that we have a GPortRef tag... nSearchStartPos = sInString.find(k_sPortRefCode, 0); if (nSearchStartPos != cppstring::npos) nSearchStartPos += k_sPortRefCode.length(); if (nSearchStartPos >= sInString.length()) nSearchStartPos = cppstring::npos; if (nSearchStartPos != cppstring::npos) nTestPos = sInString.find_last_of('>'); if (nTestPos != cppstring::npos) { cppstring sSubStr; // decode port-type nCurrentPos = sInString.find(k_sPortTypeCode, nSearchStartPos); nCurrentPos += k_sPortTypeCode.length(); if (nCurrentPos < sInString.length()) nCurrentPos = sInString.find('\"', nCurrentPos); else nCurrentPos = cppstring::npos; if (nCurrentPos != cppstring::npos) nNextPos = nCurrentPos + 1; if (nNextPos != cppstring::npos) nNextPos = sInString.find('\"', nNextPos); if ( nCurrentPos != cppstring::npos && nNextPos != cppstring::npos && nCurrentPos < nNextPos) sSubStr = sInString.substr(nCurrentPos + 1, (nNextPos - nCurrentPos - 1)); if (sSubStr.length() > 0) m_ePortType = (EPortType) GTextUtils::CPPStringToLong(sSubStr.c_str()); sSubStr = GSTD_S(""); // decode location nCurrentPos = sInString.find(k_sLocationCode, nSearchStartPos); nCurrentPos += k_sLocationCode.length(); if (nCurrentPos < sInString.length()) nCurrentPos = sInString.find('\"', nCurrentPos); else nCurrentPos = cppstring::npos; if (nCurrentPos != cppstring::npos) nNextPos = nCurrentPos + 1; if (nNextPos != cppstring::npos) nNextPos = sInString.find('\"', nNextPos); if ( nCurrentPos != cppstring::npos && nNextPos != cppstring::npos && nCurrentPos < nNextPos) sSubStr = sInString.substr(nCurrentPos + 1, (nNextPos - nCurrentPos - 1)); if (sSubStr.length() > 0) m_sLocation = sSubStr; sSubStr = GSTD_S(""); // decode display-name nCurrentPos = sInString.find(k_sDisplayNameCode, nSearchStartPos); nCurrentPos += k_sDisplayNameCode.length(); if (nCurrentPos < sInString.length()) nCurrentPos = sInString.find('\"', nCurrentPos); else nCurrentPos = cppstring::npos; if (nCurrentPos != cppstring::npos) nNextPos = nCurrentPos + 1; if (nNextPos != cppstring::npos) nNextPos = sInString.find('\"', nNextPos); if (nCurrentPos != cppstring::npos && nNextPos != cppstring::npos && nCurrentPos < nNextPos) sSubStr = sInString.substr(nCurrentPos + 1, (nNextPos - nCurrentPos - 1)); if (sSubStr.length() > 0) m_sDisplayName = sSubStr; sSubStr = GSTD_S(""); } return nResult; }
/* short GTextUtils::AdjustTextSizeByAppPref(short nOrigSize, bool bApplyNewSize, void * pOSData) { // This routine adjusts a text size based on application // preference settings; the nOrigSize is considered the // correct "medium" size. // If the text size is "large", we increase smaller fonts slightly; // If bApplyNewSize is true, GTextUtils::OSApplyTextSize() will be called. short nNewSize = nOrigSize; #ifndef OPUS_DDK if (GetAppBrain()->IsLargeText()) { switch(nOrigSize) { // we do not enlarge fonts that are larger than 14pt case 14: case 13: nNewSize = 16; break; case 12: case 11: nNewSize = 14; break; case 10: case 9: nNewSize = 12; break; case 8: case 7: nNewSize += 2; break; default: if (nOrigSize <= 6) nNewSize = 8; } } // apply the size change to the current port: // this is the real OS-specific part... if (bApplyNewSize) GTextUtils::OSApplyTextSize(nNewSize, pOSData); #endif // !OPUS_DDK return nNewSize; } EFloatStyle GTextUtils::GetFloatStyle(bool bPrecisionDecimal) { // return a float style based on bPrecisionDecimal EFloatStyle eStyle = kFloatStyle_fixedPrecision; if (!bPrecisionDecimal) eStyle = kFloatStyle_fixedSigFigs; return eStyle; } cppstring GTextUtils::TranslatePathToFile(cppstring sPath) { // Write OS before fiel path so we can convert separators properly when we read GSTD_ASSERT(GetAppBrain() != NULL); if (GetAppBrain()->GetThisOSType() == kOSType_Windows) sPath = GSTD_S("W") + sPath; else sPath = GSTD_S("M") + sPath; return sPath; } cppstring GTextUtils::TranslatePathFromFile(cppstring sPath) { // Convert all separator characters from the proper OS if (sPath.size() > 1) { GSTD_ASSERT(GetAppBrain() != NULL); if ((GetAppBrain()->GetThisOSType() == kOSType_Windows) && (sPath[0] == 'M')) sPath = GTextUtils::StringReplace(sPath, kMacPathSeparatorString, kWinPathSeparatorString); if ((GetAppBrain()->GetThisOSType() != kOSType_Windows) && (sPath[0] == 'W')) sPath = GTextUtils::StringReplace(sPath, kWinPathSeparatorString, kMacPathSeparatorString); sPath = sPath.substr(1); } return sPath; } real GTextUtils::GetVersionFromBaseName(cppstring sFileName, // actual filename with real numbers cppstring sBaseName) // base file name (with '*' instead of numbers) { // pulls out the version number from the filename using the basename as template, e.g. basename might be base*.hex real fValue = 0; // Strip off paths and extenstions so as not to confuse the issue sFileName = GTextUtils::StripPathAndExtension(sFileName); sBaseName = GTextUtils::StripPathAndExtension(sBaseName); // Make a string that starts with the actual number cppstring sNumber = sFileName.substr(sBaseName.find('*')); // now extract the numbers, will stop when we reach an non number fValue = GTextUtils::CPPStringToLong(sNumber); // Divide number by 100000 so that non decimal number (as store din filename) will get converted properly fValue /= 100000.0; return fValue; } unsigned short GTextUtils::GetValueFromCharacterEscape(cppstring sCharEscape) { // sCharEscape should be a standard XML/HTML escape sequence in one of two formats: // &#N; or &#xN; // In the first case, nnn is a base-10 integer; in the second case, a hexadecimal integer. // The method simply converts the value to an integer correctly according to base (presence of the "x" // indicated hexadecimal). // REQUIREMENT: remove whitespace before calling this method unsigned short nChar = 0; const gchar * k_sSpace = GSTD_S(" "); if ((sCharEscape.length() >= 4) && (sCharEscape[0] == GSTD_S('&')) && (sCharEscape[1] == GSTD_S('#'))) { long nBase = 10; sCharEscape[0] = GSTD_S(' '); sCharEscape[1] = GSTD_S(' '); if (sCharEscape[2] == GSTD_S('x')) sCharEscape[1] = GSTD_S('0'); #ifdef USE_WIDE_CHARS nChar = (unsigned short) wcstoul(sCharEscape.c_str(), NULL, 0); #else nChar = (unsigned short) strtoul(sCharEscape.c_str(), NULL, 0); #endif } return nChar; } cppstring GTextUtils::EncodeCharacterEscape(unsigned short nUTF8Char) { cppsstream ss; ss << "&x" << hex << nUTF8Char << ";"; return ss.str(); } */ cppstring::cppstring(gchar c) { cppstring s = GSTD_S(" "); s[0] = c; *this = s; }
GUSBDirectTempDevice::GUSBDirectTempDevice(GPortRef *pPortRef) : TBaseClass(pPortRef) { if (!OSInitialize()) GUtils::Trace(GSTD_S("Error - GUSBDirectTempDevice constructor, OSInitialize() returned false.")); }