// Using 32-bit background server correspondence to achieve the same result void openMovSettingsPopup(TPropertyGroup *props, bool unused) { QLocalSocket socket; if (!tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), 3000, t32bitsrv::srvCmdline(), "_main")) return; // Send the appropriate commands to the server tipc::Stream stream(&socket); tipc::Message msg; // We'll communicate through temporary files. stream << (msg << QString("$tmpfile_request") << QString("openMovSets")); QString res(tipc::readMessage(stream, msg)); QString fp; msg >> fp; assert(res == "ok" && !fp.isEmpty()); TFilePath tfp(fp.toStdWString()); { // Save the input props to the temporary file TOStream os(tfp); props->saveData(os); } // Invoke the settings popup stream << (msg << tipc::clr << QString("$openMovSettingsPopup") << fp); res = tipc::readMessageNB(stream, msg, -1, QEventLoop::ExcludeUserInputEvents); assert(res == "ok"); #ifdef MACOSX // Bring this application back to front ProcessSerialNumber psn = {0, kCurrentProcess}; SetFrontProcess(&psn); #endif // MACOSX props->clear(); { // Save the input props to the temporary file TIStream is(tfp); props->loadData(is); } // Release the temporary file stream << (msg << tipc::clr << QString("$tmpfile_release") << QString("openMovSets")); res = tipc::readMessage(stream, msg); assert(res == "ok"); }
int Test::Run() { LOG_INFO("Running TraceFileParser test"); // Test instrumentation packets, divided into several // bursts of data { lct::TraceFileParser tfp(*this); uint8_t buf1[] = { 0x70, 0x01, 0x41, 0x02, 0x42 }; tfp.Feed(buf1, sizeof(buf1)); uint8_t buf2[] = { 0x43 }; tfp.Feed(buf2, sizeof(buf2)); uint8_t buf3[] = { 0x00, 0x00, 0x00, 0x00, 0x00 }; tfp.Feed(buf3, sizeof(buf3)); uint8_t buf4[] = { 0x00, 0x00, 0x80 }; tfp.Feed(buf4, sizeof(buf4)); } // Test time stamps { lct::TraceFileParser tfp(*this); uint8_t buf1[] = { 0xc0, 0x00, 0xc0, 0x81, 0x07, 0xd0, 0xff }; tfp.Feed(buf1, sizeof(buf1)); uint8_t buf2[] = { 0xff, 0xff, 0x00, 0x10 }; tfp.Feed(buf2, sizeof(buf2)); } return 0; }
Tiio::MovWriterProperties::MovWriterProperties() { QLocalSocket socket; tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1, t32bitsrv::srvCmdline()); tipc::Stream stream(&socket); tipc::Message msg; // Retrieve a temporary file to pass the data QString fp; { stream << (msg << QString("$tmpfile_request") << QString("MovWriterProps")); if (tipc::readMessage(stream, msg) != "ok") goto err; msg >> fp; assert(!fp.isEmpty()); } // Make the server write the data to the file { stream << (msg << tipc::clr << QString("$defaultMovProps") << fp); if (tipc::readMessage(stream, msg) != "ok") goto err; // Load the data TFilePath tfp(fp.toStdWString()); TIStream is(tfp); loadData(is); } // Release the temporary file { stream << (msg << tipc::clr << QString("$tmpfile_release") << QString("MovWriterProps")); if (tipc::readMessage(stream, msg) != "ok") goto err; } return; err: throw TException("Server error"); }
void Histogram_gui::changeCurve(const QString & s) { std::map<float,int>::iterator itr; int total = histogram_->rawDataSize(); int i = 0; QwtText tfp("Probability"); tfp.setFont(plot_->axisFont(QwtPlot::yLeft)); QwtText tff("Frequency"); tff.setFont(plot_->axisFont(QwtPlot::yLeft)); QColor blueColor(Qt::blue); const QPen pen(blueColor); std::pair<double*,double*> curve = histogram_->plotting_data(); if (!curve.first) { appli_message("No data present"); return; } if (s == "cdf") { std::map<float, int> freqCount = histogram_->frequency(); _cdfCurve->setAxis(QwtPlot::xBottom, QwtPlot::yLeft); plot_->setAxisTitle(QwtPlot::yLeft, tfp); plot_->enableAxis(QwtPlot::yRight,false); curve_grid_->enableY(true); curve_grid_->setYAxis(QwtPlot::yLeft); plot_->enableAxis(QwtPlot::yLeft); curve_id_->setStyle(QwtPlotCurve::NoCurve); _cdfCurve->setStyle(QwtPlotCurve::Lines); double * x = new double[freqCount.size()+1]; double * y = new double[freqCount.size()+1]; y[0] = 0; for (itr = freqCount.begin(); itr != freqCount.end(); ++itr,++i) { x[i+1] = itr->first; y[i+1] = y[i]+(double)(itr->second)/(double)(total); } x[0] = x[1]; _cdfCurve->setPen(pen); _cdfCurve->setData( x, y, freqCount.size()+1 ); refresh_plot( _cdfCurve, std::make_pair( x,y ), freqCount.size()+1 ); refresh_stats(); delete []x; delete []y; } else if (s == "pdf") { //_cdfCurve->detach(); plot_->enableAxis(QwtPlot::yRight, false); plot_->setAxisTitle(QwtPlot::yLeft, tff); plot_->enableAxis(QwtPlot::xBottom); curve_id_->setAxis(QwtPlot::xBottom, QwtPlot::yLeft); curve_grid_->setYAxis(QwtPlot::yLeft); curve_grid_->enableY(true); curve_grid_->setXAxis(QwtPlot::xBottom); curve_grid_->enableX(true); _cdfCurve->setStyle(QwtPlotCurve::NoCurve); curve_id_->setStyle(QwtPlotCurve::Histogram); int size = histogram_->bins()+1; double* x = new double[size+1]; double* y = new double[size+1]; for( int i =0 ; i < size ; i++ ) { x[i+1] = curve.first[i]; y[i+1] = curve.second[i]; } x[0] = x[1]; y[0] = 0.0; refresh_plot( std::make_pair( x,y ), size+1 ); refresh_stats(); delete []x; delete []y; } else { std::map<float, int> freqCount = histogram_->frequency(); _cdfCurve->setAxis(QwtPlot::xBottom, QwtPlot::yRight); plot_->enableAxis(QwtPlot::yRight, true); plot_->enableAxis(QwtPlot::yLeft, true); curve_grid_->setYAxis(QwtPlot::yLeft); plot_->setAxisTitle(QwtPlot::yLeft, tff); plot_->setAxisTitle(QwtPlot::yRight, tfp); _cdfCurve->setStyle(QwtPlotCurve::Lines); curve_id_->setStyle(QwtPlotCurve::Histogram); double * x = new double[freqCount.size()+1]; double * y = new double[freqCount.size()+1]; y[0] = 0; for (itr = freqCount.begin(); itr != freqCount.end(); ++itr,++i) { x[i+1] = itr->first; y[i+1] = y[i]+(double)(itr->second)/(double)(total); } x[0] = x[1]; _cdfCurve->setPen(pen); _cdfCurve->setData( x, y, freqCount.size()+1 ); refresh_plot( _cdfCurve, std::make_pair( x,y ), freqCount.size()+1 ); //refresh_stats(); int size = histogram_->bins()+1; double* x1 = new double[size+1]; double* y1 = new double[size+1]; for( int i =0 ; i < size ; i++ ) { x1[i+1] = curve.first[i]; y1[i+1] = curve.second[i]; } x1[0] = x1[1]; y1[0] = 0.0; refresh_plot( std::make_pair( x1,y1 ), size+1 ); refresh_stats(); delete []x1; delete []y1; delete []x; delete []y; } //plot_->replot(); }
void MDFNFILE::Open(const char *path, const FileExtensionSpecStruct *known_ext, const char *purpose) { unzFile tz = NULL; try { // // Try opening it as a zip file first // if((tz = unzOpen(path))) { char tempu[1024]; int errcode; if((errcode = unzGoToFirstFile(tz)) != UNZ_OK) { throw MDFN_Error(0, _("Could not seek to first file in ZIP archive: %s"), unzErrorString(errcode)); } if(known_ext) { bool FileFound = FALSE; while(!FileFound) { size_t tempu_strlen; const FileExtensionSpecStruct *ext_search = known_ext; if((errcode = unzGetCurrentFileInfo(tz, 0, tempu, 1024, 0, 0, 0, 0)) != UNZ_OK) { throw MDFN_Error(0, _("Could not get file information in ZIP archive: %s"), unzErrorString(errcode)); } tempu[1023] = 0; tempu_strlen = strlen(tempu); while(ext_search->extension && !FileFound) { size_t ttmeow = strlen(ext_search->extension); if(tempu_strlen >= ttmeow) { if(!strcasecmp(tempu + tempu_strlen - ttmeow, ext_search->extension)) FileFound = TRUE; } ext_search++; } if(FileFound) break; if((errcode = unzGoToNextFile(tz)) != UNZ_OK) { if(errcode != UNZ_END_OF_LIST_OF_FILE) { throw MDFN_Error(0, _("Error seeking to next file in ZIP archive: %s"), unzErrorString(errcode)); } if((errcode = unzGoToFirstFile(tz)) != UNZ_OK) { throw MDFN_Error(0, _("Could not seek to first file in ZIP archive: %s"), unzErrorString(errcode)); } break; } } // end to while(!FileFound) } // end to if(ext) if((errcode = unzOpenCurrentFile(tz)) != UNZ_OK) { throw MDFN_Error(0, _("Could not open file in ZIP archive: %s"), unzErrorString(errcode)); } { unz_file_info ufo; unzGetCurrentFileInfo((unzFile)tz, &ufo, 0, 0, 0, 0, 0, 0); if(ufo.uncompressed_size > MaxROMImageSize) throw MDFN_Error(0, _("ROM image is too large; maximum size allowed is %llu bytes."), (unsigned long long)MaxROMImageSize); str.reset(new MemoryStream(ufo.uncompressed_size, true)); unzReadCurrentFile((unzFile)tz, str->map(), str->size()); } // Don't use MDFN_GetFilePathComponents() here. { char* ld = strrchr(tempu, '.'); f_ext = std::string(ld ? ld : ""); f_fbase = std::string(tempu, ld ? (ld - tempu) : strlen(tempu)); } } else // If it's not a zip file, handle it as...another type of file! { std::unique_ptr<Stream> tfp(new FileStream(path, FileStream::MODE_READ)); // We'll clean up f_ext to remove the leading period, and convert to lowercase, after // the plain vs gzip file handling code below(since gzip handling path will want to strip off an extra extension). MDFN_GetFilePathComponents(path, NULL, &f_fbase, &f_ext); uint8 gzmagic[3] = { 0 }; if(tfp->read(gzmagic, 3, false) != 3 || gzmagic[0] != 0x1F || gzmagic[1] != 0x8b || gzmagic[2] != 0x08) { tfp->seek(0, SEEK_SET); if(tfp->size() > MaxROMImageSize) throw MDFN_Error(0, _("ROM image is too large; maximum size allowed is %llu bytes."), (unsigned long long)MaxROMImageSize); str = std::move(tfp); } else /* Probably gzip */ { delete tfp.release(); str.reset(new MemoryStream(new GZFileStream(path, GZFileStream::MODE::READ), MaxROMImageSize)); MDFN_GetFilePathComponents(f_fbase, NULL, &f_fbase, &f_ext); } // End gzip handling } // End normal and gzip file handling else to zip // Remove leading period in file extension. if(f_ext.size() > 0 && f_ext[0] == '.') f_ext = f_ext.substr(1); // Convert file extension A-Z chars to lowercase, a-z for(auto& c : f_ext) if(c >= 'A' && c <= 'Z') c = 'a' + (c - 'A'); //printf("|%s| --- |%s|\n", f_fbase.c_str(), f_ext.c_str()); } catch(...) { if(tz != NULL) { unzCloseCurrentFile(tz); unzClose(tz); } Close(); throw; } if(tz != NULL) { unzCloseCurrentFile(tz); unzClose(tz); } }