static void parseFile(ParserInterface *parser, Entry *root,EntryNav *rootNav,FileDef *fd,const char *fn, bool sameTu,QStrList &filesInSameTu) { static bool clangAssistedParsing = FALSE; QCString fileName=fn; QCString extension; int ei = fileName.findRev('.'); if (ei!=-1) { extension=fileName.right(fileName.length()-ei); } else { extension = ".no_extension"; } QFileInfo fi(fileName); BufStr preBuf(fi.size()+4096); if (true && parser->needsPreprocessing(extension)) { BufStr inBuf(fi.size()+4096); readInputFile(fileName,inBuf); // preprocessFile(fileName,inBuf,preBuf); } else // no preprocessing { readInputFile(fileName,preBuf); } if (preBuf.data() && preBuf.curPos()>0 && *(preBuf.data()+preBuf.curPos()-1)!='\n') { preBuf.addChar('\n'); // add extra newline to help parser } BufStr convBuf(preBuf.curPos()+1024); // convert multi-line C++ comments to C style comments convertCppComments(&preBuf,&convBuf,fileName); convBuf.addChar('\0'); // use language parse to parse the file parser->parseInput(fileName,convBuf.data(),root,sameTu,filesInSameTu); // store the Entry tree in a file and create an index to // navigate/load entries //printf("root->createNavigationIndex for %s\n",fd->name().data()); root->createNavigationIndex(rootNav,g_storage,fd); }
TVerdict CDataReadyCancelNotificationStep::doTestStepL() /** * @return - TVerdict code * Override of base class pure virtual * Our implementation only gets called if the base class doTestStepPreambleL() did * not leave. That being the case, the current test result value will be EPass. */ { if (TestStepResult()==EPass) { _LIT8(KTestOutBuf,"test message"); HBufC* InBuf = HBufC::NewLC(KTestOutBuf().Length() / 2); TPtr ptr = InBuf->Des(); TPtr8 inBuf(ptr.Collapse()); TBuf<50> msg; _LIT(KOperReading, "Data available request canceled in port <%d>"); _LIT(KOperWriting, "Written port <%d>"); TRequestStatus status; for(TInt i = 0; i < KSupportedPorts; i++) { if(IsEven(i)) { iPortList[i].port.Write(status, KTestOutBuf); msg.Format(KOperWriting, i); User::WaitForRequest(status); TestErrorCodeL(status.Int(), msg); } else { iPortList[i].port.NotifyDataAvailableCancel(); msg.Format(KOperReading, i); } } CleanupStack::PopAndDestroy(); SetTestStepResult(EPass); } return TestStepResult(); }
Transfer * ResponseProtocol::parse( const QByteArray & wire, uint & bytes ) { m_bytes = 0; m_collatingFields.clear(); //m_din = new QDataStream( wire, IO_ReadOnly ); QBuffer inBuf( wire ); inBuf.open( IO_ReadOnly); m_din.setDevice( &inBuf ); m_din.setByteOrder( QDataStream::LittleEndian ); // check that this begins with a HTTP (is a response) Q_UINT32 val; m_din >> val; m_bytes += sizeof( Q_UINT32 ); Q_ASSERT( qstrncmp( (const char *)&val, "HTTP", strlen( "HTTP" ) ) == 0 ); // read rest of HTTP header and look for a 301 redirect. QCString headerFirst; if ( !readGroupWiseLine( headerFirst ) ) return 0; // pull out the HTTP return code int firstSpace = headerFirst.find( ' ' ); QString rtnField = headerFirst.mid( firstSpace, headerFirst.find( ' ', firstSpace + 1 ) ); bool ok = true; int rtnCode; int packetState = -1; rtnCode = rtnField.toInt( &ok ); debug( "CoreProtocol::readResponse() got HTTP return code " ); // read rest of header QStringList headerRest; QCString line; while ( line != "\r\n" ) { if ( !readGroupWiseLine( line ) ) { m_din.unsetDevice(); return 0; } headerRest.append( line ); debug( QString( "- read header line - (%1) : %2" ).arg( line.length() ).arg( line.data() ) ); } debug( "ResponseProtocol::readResponse() header finished" ); // if it's a redirect, set flag if ( ok && rtnCode == 301 ) { debug( "- server redirect " ); packetState = ServerRedirect; m_din.unsetDevice(); return 0; } // other header processing ( 500! ) if ( ok && rtnCode == 500 ) { debug( QString( "- server error %1" ).arg( rtnCode ) ); packetState = ServerError; m_din.unsetDevice(); return 0; } if ( ok && rtnCode == 404 ) { debug( QString( "- server error %1" ).arg( rtnCode ) ); packetState = ServerError; m_din.unsetDevice(); return 0; } if ( m_din.atEnd() ) { debug( "- no fields" ); packetState = ProtocolError; m_din.unsetDevice(); return 0; } // read fields if ( !readFields( -1 ) ) { m_din.unsetDevice(); return 0; } // find transaction id field and create Response object if nonzero int tId = 0; int resultCode = 0; Field::FieldListIterator it; Field::FieldListIterator end = m_collatingFields.end(); it = m_collatingFields.find( NM_A_SZ_TRANSACTION_ID ); if ( it != end ) { Field::SingleField * sf = dynamic_cast<Field::SingleField*>( *it ); if ( sf ) { tId = sf->value().toInt(); debug( QString( "ResponseProtocol::readResponse() - transaction ID is %1" ).arg( tId ) ); m_collatingFields.remove( it ); delete sf; } } it = m_collatingFields.find( NM_A_SZ_RESULT_CODE ); if ( it != end ) { Field::SingleField * sf = dynamic_cast<Field::SingleField*>( *it ); if ( sf ) { resultCode = sf->value().toInt(); debug( QString( "ResponseProtocol::readResponse() - result code is %1" ).arg( resultCode ) ); m_collatingFields.remove( it ); delete sf; } } // append to inQueue if ( tId ) { debug( QString( "ResponseProtocol::readResponse() - setting state Available, got %1 fields in base array" ).arg(m_collatingFields.count() ) ); packetState = Available; bytes = m_bytes; m_din.unsetDevice(); return new Response( tId, resultCode, m_collatingFields ); } else { debug( "- WARNING - NO TRANSACTION ID FOUND!" ); m_state = ProtocolError; m_din.unsetDevice(); m_collatingFields.purge(); return 0; } }
void MainWindow::OnMenuCrawlTimer(wxTimerEvent & event) { // our crawl timer has triggered, time to gets goin' static const std::string clStr("\r"); static const std::string eolStr("\n"); // wake up the device. DRUID::SerialUIUserPtr serial_user = connection->serialUser(); serial_user->send(eolStr); // PLATFORM_SLEEP(1); if(connection->ping(3, false)) { DRUID4ARDUINO_DEBUG2("Device seems to be alive on ", serial_port); //= ; std::string inBuf(serial_user->incomingBuffer()); std::string name; std::string::iterator findIter = std::search(inBuf.begin(), inBuf.end(), clStr.begin(), clStr.end()); if (findIter == inBuf.end()) { findIter = std::search(inBuf.begin(), inBuf.end(), eolStr.begin(), eolStr.end()); } if (findIter != inBuf.end()) { // copy the newly arrived message to last_message name.reserve(findIter - inBuf.begin()); std::copy(inBuf.begin(), findIter, std::back_inserter(name)); } else { name = inBuf; } prog_name = DRUID_STDSTRING_TOWX(name); resetStatusBar(); } else { wxString errMsg(wxT("No response to ping for 3 seconds on ")); errMsg += DRUID_STDSTRING_TOWX(serial_port); SetStatusText(errMsg); } // parse the menu if (serial_user->isConnected()) { resetSUIWindows(); if (topLevelMenu) { // clear out the window menu and its callbacks for (unsigned int elementId=MAINWINDOW_DYNAMICMENU_ELEMENTID_START; elementId < menu_id_counter; elementId++) { this->Disconnect(elementId, wxEVT_COMMAND_MENU_SELECTED); } for (unsigned int i=0; i < topLevelMenu->size(); i++) { // TODO: must we destroy the returned wxMenuItem? deviceMenu->Remove(deviceMenu->FindItemByPosition(0)); } } parser.setControlStrings(serial_user->enterProgramMode()); executing_request = true; topLevelMenu = parser.crawl(serial_user); if (topLevelMenu) { // ok, we have our menu structure parser.dumpMenus(); buildAllDeviceMenus(topLevelMenu); } else { // TODO:FIXME return error currentlyEnabledSUIWindown()->setError(wxT("Parser could not crawl menus\r\nEnsure a valid SerialUI device is connected.")); SetStatusText(wxT("Parser could not crawl menus")); } serial_user->clear(); executing_request = false; pingTimer->Start(200, false); } else { SetStatusText(wxT("Serial connection failure")); } }
bool ossimCodecFactory::encodeJpeg( ossim_uint32 quality, const ossimRefPtr<ossimImageData>& in, std::vector<ossim_uint8>& out ) const { bool result = false; if ( in.valid() && (in->getDataObjectStatus() != OSSIM_NULL) ) { if ( in->getScalarType() == OSSIM_UINT8 ) { // Open a memory stream up to put the jpeg image in memory: std::stringstream jpegStreamBuf; //--- // Initialize JPEG compression library: // NOTE: JDIMENSION is an "unsigned int" //--- struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; cinfo.err = jpeg_std_error( &jerr ); jpeg_create_compress(&cinfo); // Define a custom stream destination manager for jpeglib to write compressed block: jpeg_cpp_stream_dest(&cinfo, jpegStreamBuf); /* Setting the parameters of the output file here */ cinfo.image_width = in->getWidth(); cinfo.image_height = in->getHeight(); // Bands must be one or three for this writer. const ossim_uint32 INPUT_BANDS = in->getNumberOfBands(); if ( (INPUT_BANDS == 1) || (INPUT_BANDS == 3) ) { cinfo.input_components = INPUT_BANDS; } else { if ( INPUT_BANDS < 3 ) { cinfo.input_components = 1; // Use first band. } else { cinfo.input_components = 3; // Use the first 3 bands. } } // colorspace of input image if ( cinfo.input_components == 3) { cinfo.in_color_space = JCS_RGB; } else { cinfo.in_color_space = JCS_GRAYSCALE; } // Default compression parameters, we shouldn't be worried about these. jpeg_set_defaults( &cinfo ); jpeg_set_quality(&cinfo, quality, TRUE); //limit to baseline-JPEG values // Now do the compression... jpeg_start_compress( &cinfo, TRUE ); // Line buffer: ossim_uint32 buf_size = cinfo.input_components*cinfo.image_width; std::vector<ossim_uint8> buf(buf_size); // Compress the tile on line at a time: JSAMPROW row_pointer[1]; // Pointer to a single row. row_pointer[0] = (JSAMPLE*)&buf.front(); // Get pointers to the input data: std::vector<const ossim_uint8*> inBuf(cinfo.input_components); for ( ossim_int32 band = 0; band < cinfo.input_components; ++band ) { inBuf[band] = in->getUcharBuf(band); } ossim_uint32 inIdx = 0; for (ossim_uint32 line=0; line< cinfo.image_height; ++line) { // Convert from band sequential to band interleaved by pixel. ossim_uint32 outIdx = 0; for ( ossim_uint32 p = 0; p < cinfo.image_width; ++p ) { for ( ossim_int32 band = 0; band < cinfo.input_components; ++band ) { buf[outIdx++] = inBuf[band][inIdx]; } ++inIdx; } // Write it... jpeg_write_scanlines( &cinfo, row_pointer, 1 ); } // Similar to read file, clean up after we're done compressing. jpeg_finish_compress( &cinfo ); jpeg_destroy_compress( &cinfo ); // Copy the memory stream to output vector. out.resize(jpegStreamBuf.str().size()); jpegStreamBuf.seekg(0, std::ios_base::beg); jpegStreamBuf.read((char*)&out.front(), jpegStreamBuf.str().size()); result = true; } else // Scalar type check... { ossimNotify(ossimNotifyLevel_WARN) << "ossimCodecFactory::encodeJpeg ERROR:" << "\nPassing non-eight bit data to eight bit encoder!" << std::endl; } } // Matches: if ( in.valid() ... ) return result; }