void CLog::fatal(const string & logName, const string & message) { logMessage(LOG_FATAL_LEVEL, logName, message); }
static int construct_ScreenScreen (void) { #ifdef HAVE_SHMGET { key_t keys[2]; int keyCount = 0; /* The original, static key. */ keys[keyCount++] = 0xBACD072F; /* The new, dynamically generated, per user key. */ { int project = 'b'; const char *path = getenv("HOME"); if (!path || !*path) path = "/"; logMessage(LOG_DEBUG, "Shared memory file system object: %s", path); if ((keys[keyCount] = ftok(path, project)) != -1) { keyCount++; } else { logMessage(LOG_WARNING, "Per user shared memory key not generated: %s", strerror(errno)); } } while (keyCount > 0) { shmKey = keys[--keyCount]; logMessage(LOG_DEBUG, "Trying shared memory key: 0X%" PRIX_KEY_T, shmKey); if ((shmIdentifier = shmget(shmKey, shmSize, shmMode)) != -1) { if ((shmAddress = shmat(shmIdentifier, NULL, 0)) != (unsigned char *)-1) { logMessage(LOG_INFO, "Screen image shared memory key: 0X%" PRIX_KEY_T, shmKey); return 1; } else { logMessage(LOG_WARNING, "Cannot attach shared memory segment 0X%" PRIX_KEY_T ": %s", shmKey, strerror(errno)); } } else { logMessage(LOG_WARNING, "Cannot access shared memory segment 0X%" PRIX_KEY_T ": %s", shmKey, strerror(errno)); } } shmIdentifier = -1; } #endif /* HAVE_SHMGET */ #ifdef HAVE_SHM_OPEN { if ((shmFileDescriptor = shm_open(shmPath, O_RDONLY, shmMode)) != -1) { if ((shmAddress = mmap(0, shmSize, PROT_READ, MAP_SHARED, shmFileDescriptor, 0)) != MAP_FAILED) { return 1; } else { logSystemError("mmap"); } close(shmFileDescriptor); shmFileDescriptor = -1; } else { logSystemError("shm_open"); } } #endif /* HAVE_SHM_OPEN */ return 0; }
int smsa_vread( SMSA_VIRTUAL_ADDRESS addr, uint32_t len, unsigned char *buf ) { /* First check if the length is 0 */ // Write nothing and return if so if(len == 0) { return 0; } /* Initialize variables */ int i = 0; int err = 0; int read_bytes = 0; uint32_t offset; SMSA_DRUM_ID drum; SMSA_BLOCK_ID block; SMSA_BLOCK_ID block_orig; unsigned char *smsa_vread_buffer = NULL; drum = find_drum(addr); block = find_block(addr); block_orig = block; offset = addr & 0xff; seek_if_i_must(drum, block); // Loop to iterate through blocks do { /* Bounds checking */ // Check if drum is in bounds if( (drum > SMSA_DISK_ARRAY_SIZE) || (drum < 0) ) { logMessage( LOG_ERROR_LEVEL, "The drum is out of bounds [%d]\n", drum ); return -1; } // Check if block is in bounds if( (block > SMSA_MAX_BLOCK_ID) || (block < 0) ) { logMessage( LOG_ERROR_LEVEL, "The block is out of bounds [%d]\n", block ); return -1; } /* Is it the original block? */ // Yes - begin reading from offset // No - begin reading from beginning if( block == block_orig ) { i = offset; } else { i = 0; } /* Is it last block in the drum? */ if( block == SMSA_BLOCK_SIZE) { // Seek to the beginning of next drum block=0; curBlock = 0; drum++; seek_if_i_must(drum, block); } /* Is it in the cache? */ logMessage(LOG_INFO_LEVEL, "Asking cache at: drum[%d]\tblock[%d]\n", drum, block); smsa_vread_buffer = smsa_get_cache_line(drum, block); // If yes if(smsa_vread_buffer != NULL) { // Read into buf do { buf[read_bytes] = smsa_vread_buffer[i]; read_bytes++; i++; } while( (i<SMSA_BLOCK_SIZE) && (read_bytes<len) ); // seek next block block++; curBlock++; smsa_operation( SEEK_BLOCK, NULL ); } // If no else { // Allocate temp buffer smsa_vread_buffer = (unsigned char *) malloc(SMSA_BLOCK_SIZE * sizeof(unsigned char)); // Read from disk smsa_operation( DISK_READ, smsa_vread_buffer ); // Put into buf bit by bit do { buf[read_bytes] = smsa_vread_buffer[i]; read_bytes++; i++; } while( (i<SMSA_BLOCK_SIZE) && (read_bytes<len) ); // Add temp buffer into cache line logMessage(LOG_INFO_LEVEL, "Finding a place to put the cache entry...\n"); err = smsa_put_cache_line(drum, block, smsa_vread_buffer); block++; curBlock++; } if(err) { logMessage(LOG_ERROR_LEVEL, "Something bad happened in the cache :/\n"); return -1; } } while(read_bytes<len); return 0; }
void ConfigDialog::doScalarFieldLog(int state) { logMessage("PostprocessorView::doScalarFieldLog()"); txtScalarFieldRangeBase->setEnabled(chkScalarFieldRangeLog->isChecked()); }
ColorButton::~ColorButton() { logMessage("ColorButton::~ColorButton()"); }
void ConfigDialog::load() { logMessage("ConfigDialog::load()"); // gui style cmbGUIStyle->setCurrentIndex(cmbGUIStyle->findText(Util::config()->guiStyle)); if (cmbGUIStyle->currentIndex() == -1 && cmbGUIStyle->count() > 0) cmbGUIStyle->setCurrentIndex(0); // language cmbLanguage->setCurrentIndex(cmbLanguage->findText(Util::config()->language)); if (cmbLanguage->currentIndex() == -1 && cmbLanguage->count() > 0) cmbLanguage->setCurrentIndex(0); // default physic field cmbDefaultPhysicField->setCurrentIndex(cmbDefaultPhysicField->findData(Util::config()->defaultPhysicField)); // collaboration server txtCollaborationServerURL->setText(Util::config()->collaborationServerURL); // check version chkCheckVersion->setChecked(Util::config()->checkVersion); // show convergence chart chkShowConvergenceChart->setChecked(Util::config()->showConvergenceChart); // logs chkEnabledApplicationLog->setChecked(Util::config()->enabledApplicationLog); chkEnabledProgressLog->setChecked(Util::config()->enabledProgressLog); // show result in line edit value widget chkLineEditValueShowResult->setChecked(Util::config()->lineEditValueShowResult); // geometry txtMeshAngleSegmentsCount->setValue(Util::config()->angleSegmentsCount); txtGeometryNodeSize->setValue(Util::config()->nodeSize); txtGeometryEdgeWidth->setValue(Util::config()->edgeWidth); txtGeometryLabelSize->setValue(Util::config()->labelSize); chkMeshCurvilinearElements->setChecked(Util::config()->curvilinearElements); chkZoomToMouse->setChecked(Util::config()->zoomToMouse); // delete files chkDeleteTriangleMeshFiles->setChecked(Util::config()->deleteTriangleMeshFiles); chkDeleteHermes2DMeshFile->setChecked(Util::config()->deleteHermes2DMeshFile); // save problem with solution if (Util::config()->showExperimentalFeatures) chkSaveWithSolution->setChecked(Util::config()->saveProblemWithSolution); // colors colorBackground->setColor(Util::config()->colorBackground); colorGrid->setColor(Util::config()->colorGrid); colorCross->setColor(Util::config()->colorCross); colorNodes->setColor(Util::config()->colorNodes); colorEdges->setColor(Util::config()->colorEdges); colorLabels->setColor(Util::config()->colorLabels); colorContours->setColor(Util::config()->colorContours); colorVectors->setColor(Util::config()->colorVectors); colorInitialMesh->setColor(Util::config()->colorInitialMesh); colorSolutionMesh->setColor(Util::config()->colorSolutionMesh); colorHighlighted->setColor(Util::config()->colorHighlighted); colorSelected->setColor(Util::config()->colorSelected); // scalar field chkScalarFieldRangeLog->setChecked(Util::config()->scalarRangeLog); doScalarFieldLog(chkScalarFieldRangeLog->checkState()); txtScalarFieldRangeBase->setText(QString::number(Util::config()->scalarRangeBase)); txtScalarDecimalPlace->setValue(Util::config()->scalarDecimalPlace); // 3d chkView3DLighting->setChecked(Util::config()->scalarView3DLighting); txtView3DAngle->setValue(Util::config()->scalarView3DAngle); chkView3DBackground->setChecked(Util::config()->scalarView3DBackground); txtView3DHeight->setValue(Util::config()->scalarView3DHeight); // deform shape chkDeformScalar->setChecked(Util::config()->deformScalar); chkDeformContour->setChecked(Util::config()->deformContour); chkDeformVector->setChecked(Util::config()->deformVector); // adaptivity txtMaxDOFs->setValue(Util::config()->maxDofs); //chkIsoOnly->setChecked(Util::config()->isoOnly); txtConvExp->setValue(Util::config()->convExp); txtThreshold->setValue(Util::config()->threshold); cmbStrategy->setCurrentIndex(cmbStrategy->findData(Util::config()->strategy)); cmbMeshRegularity->setCurrentIndex(cmbMeshRegularity->findData(Util::config()->meshRegularity)); cmbProjNormType->setCurrentIndex(cmbProjNormType->findData(Util::config()->projNormType)); // command argument txtArgumentTriangle->setText(Util::config()->commandTriangle); txtArgumentFFmpeg->setText(Util::config()->commandFFmpeg); // experimental features chkExperimentalFeatures->setChecked(Util::config()->showExperimentalFeatures); // global script txtGlobalScript->setPlainText(Util::config()->globalScript); }
QWidget *ConfigDialog::createColorsWidget() { logMessage("ConfigDialog::createColorsWidget()"); QWidget *colorsWidget = new QWidget(this); // colors colorBackground = new ColorButton(this); colorGrid = new ColorButton(this); colorCross = new ColorButton(this); colorNodes = new ColorButton(this); colorEdges = new ColorButton(this); colorLabels = new ColorButton(this); colorContours = new ColorButton(this); colorVectors = new ColorButton(this); colorInitialMesh = new ColorButton(this); colorSolutionMesh = new ColorButton(this); colorHighlighted = new ColorButton(this); colorSelected = new ColorButton(this); QGridLayout *layoutColors = new QGridLayout(); layoutColors->addWidget(new QLabel(tr("Background:")), 0, 0); layoutColors->addWidget(new QLabel(tr("Grid:")), 1, 0); layoutColors->addWidget(new QLabel(tr("Cross:")), 2, 0); layoutColors->addWidget(new QLabel(tr("Nodes:")), 3, 0); layoutColors->addWidget(new QLabel(tr("Edges:")), 4, 0); layoutColors->addWidget(new QLabel(tr("Labels:")), 5, 0); layoutColors->addWidget(new QLabel(tr("Contours:")), 6, 0); layoutColors->addWidget(new QLabel(tr("Vectors:")), 7, 0); layoutColors->addWidget(new QLabel(tr("Initial mesh:")), 8, 0); layoutColors->addWidget(new QLabel(tr("Solution mesh:")), 9, 0); layoutColors->addWidget(new QLabel(tr("Highlighted elements:")), 10, 0); layoutColors->addWidget(new QLabel(tr("Selected elements:")), 11, 0); layoutColors->addWidget(colorBackground, 0, 1); layoutColors->addWidget(colorGrid, 1, 1); layoutColors->addWidget(colorCross, 2, 1); layoutColors->addWidget(colorNodes, 3, 1); layoutColors->addWidget(colorEdges, 4, 1); layoutColors->addWidget(colorLabels, 5, 1); layoutColors->addWidget(colorContours, 6, 1); layoutColors->addWidget(colorVectors, 7, 1); layoutColors->addWidget(colorInitialMesh, 8, 1); layoutColors->addWidget(colorSolutionMesh, 9, 1); layoutColors->addWidget(colorHighlighted, 10, 1); layoutColors->addWidget(colorSelected, 11, 1); // default QPushButton *btnDefault = new QPushButton(tr("Default")); connect(btnDefault, SIGNAL(clicked()), this, SLOT(doColorsDefault())); QGroupBox *grpColor = new QGroupBox(tr("Colors")); grpColor->setLayout(layoutColors); QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(grpColor); layout->addStretch(); layout->addWidget(btnDefault, 0, Qt::AlignLeft); colorsWidget->setLayout(layout); return colorsWidget; }
void SceneTransformDialog::createControls() { logMessage("SceneTransformDialog::createControls()"); // translate txtTranslateX = new ValueLineEdit(); txtTranslateY = new ValueLineEdit(); lstTranslateX = new QLabel(); lstTranslateY = new QLabel(); QGridLayout *layoutTranslate = new QGridLayout(); layoutTranslate->addWidget(lstTranslateX, 0, 0); layoutTranslate->addWidget(txtTranslateX, 0, 1); layoutTranslate->addWidget(lstTranslateY, 1, 0); layoutTranslate->addWidget(txtTranslateY, 1, 1); layoutTranslate->addWidget(new QLabel(""), 2, 0); widTranslate = new QWidget(); widTranslate->setLayout(layoutTranslate); // rotate txtRotateBasePointX = new ValueLineEdit(); txtRotateBasePointY = new ValueLineEdit(); txtRotateAngle = new ValueLineEdit(); lstRotateBasePointX = new QLabel(); lstRotateBasePointY = new QLabel(); QGridLayout *layoutRotate = new QGridLayout(); layoutRotate->addWidget(lstRotateBasePointX, 0, 0); layoutRotate->addWidget(txtRotateBasePointX, 0, 1); layoutRotate->addWidget(lstRotateBasePointY, 1, 0); layoutRotate->addWidget(txtRotateBasePointY, 1, 1); layoutRotate->addWidget(new QLabel(tr("Angle:")), 2, 0); layoutRotate->addWidget(txtRotateAngle, 2, 1); widRotate = new QWidget(); widRotate->setLayout(layoutRotate); // scale txtScaleBasePointX = new ValueLineEdit(); txtScaleBasePointY = new ValueLineEdit(); txtScaleFactor = new ValueLineEdit(); lstScaleBasePointX = new QLabel(); lstScaleBasePointY = new QLabel(); QGridLayout *layoutScale = new QGridLayout(); layoutScale->addWidget(lstScaleBasePointX, 0, 0); layoutScale->addWidget(txtScaleBasePointX, 0, 1); layoutScale->addWidget(lstScaleBasePointY, 1, 0); layoutScale->addWidget(txtScaleBasePointY, 1, 1); layoutScale->addWidget(new QLabel(tr("Scaling factor:")), 2, 0); layoutScale->addWidget(txtScaleFactor, 2, 1); widScale = new QWidget(); widScale->setLayout(layoutScale); // copy chkCopy = new QCheckBox(tr("Copy objects")); // dialog buttons QPushButton *btnApply = new QPushButton(tr("Apply")); btnApply->setDefault(true); connect(btnApply, SIGNAL(clicked()), this, SLOT(doTransform())); QPushButton *btnClose = new QPushButton(tr("Close")); connect(btnClose, SIGNAL(clicked()), this, SLOT(doClose())); QHBoxLayout *layoutButtonBox = new QHBoxLayout(); layoutButtonBox->addStretch(); layoutButtonBox->addWidget(btnApply); layoutButtonBox->addWidget(btnClose); // tab widget tabWidget = new QTabWidget(); tabWidget->addTab(widTranslate, icon(""), tr("Translate")); tabWidget->addTab(widRotate, icon(""), tr("Rotate")); tabWidget->addTab(widScale, icon(""), tr("Scale")); QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(tabWidget); layout->addWidget(chkCopy); layout->addStretch(); layout->addLayout(layoutButtonBox); setLayout(layout); }
static void doSyslogd(void) { struct sockaddr_un sunx; socklen_t addrLength; int sock_fd; fd_set fds; /* Set up signal handlers. */ signal(SIGINT, quit_signal); signal(SIGTERM, quit_signal); signal(SIGQUIT, quit_signal); signal(SIGHUP, SIG_IGN); signal(SIGCHLD, SIG_IGN); #ifdef SIGCLD signal(SIGCLD, SIG_IGN); #endif signal(SIGALRM, domark); alarm(MarkInterval); /* Create the syslog file so realpath() can work. */ if (realpath(_PATH_LOG, lfile) != NULL) { unlink(lfile); } memset(&sunx, 0, sizeof(sunx)); sunx.sun_family = AF_UNIX; strncpy(sunx.sun_path, lfile, sizeof(sunx.sun_path)); if ((sock_fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) { bb_perror_msg_and_die("Couldn't get file descriptor for socket " _PATH_LOG); } addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path); if (bind(sock_fd, (struct sockaddr *) &sunx, addrLength) < 0) { bb_perror_msg_and_die("Could not connect to socket " _PATH_LOG); } if (chmod(lfile, 0666) < 0) { bb_perror_msg_and_die("Could not set permission on " _PATH_LOG); } #ifdef CONFIG_FEATURE_IPC_SYSLOG if (circular_logging == TRUE) { ipcsyslog_init(); } #endif #ifdef CONFIG_FEATURE_REMOTE_LOG if (doRemoteLog == TRUE) { init_RemoteLog(); } #endif logMessage(LOG_SYSLOG | LOG_INFO, "syslogd started: " BB_BANNER); for (;;) { FD_ZERO(&fds); FD_SET(sock_fd, &fds); if (select(sock_fd + 1, &fds, NULL, NULL, NULL) < 0) { if (errno == EINTR) { /* alarm may have happened. */ continue; } bb_perror_msg_and_die("select error"); } if (FD_ISSET(sock_fd, &fds)) { int i; RESERVE_CONFIG_BUFFER(tmpbuf, MAXLINE + 1); memset(tmpbuf, '\0', MAXLINE + 1); if ((i = recv(sock_fd, tmpbuf, MAXLINE, 0)) > 0) { serveConnection(tmpbuf, i); } else { bb_perror_msg_and_die("UNIX socket error"); } RELEASE_CONFIG_BUFFER(tmpbuf); } /* FD_ISSET() */ } /* for main loop */ }
static void logClose(){ logMessage("Closing log file"); fclose(logfp); }
void SceneTransformDialog::doClose() { logMessage("SceneTransformDialog::doClose()"); close(); }
/* Write add local timestamp to chat message before writing to disk */ void PrivateChat::logMessage(const QString& user, const QString& speaker, const QString& _l) { logMessage(user, _TIMES, speaker, _l); }
void PrivateChat::slotSend(const QString& line_) { QString line = line_; if (line.isEmpty()) return; if(line.startsWith("//")) { line = line.mid(1); } else if(line[0] == '/') { QStringList s; QString cmd(""); if(line.length() > 1) { s = line.mid(1).split(' ', QString::KeepEmptyParts); cmd = s[0].toLower(); s.pop_front(); } if(cmd == "me") { museeq->sayPrivate(user(), line); mChatPanel->append(QString::null, line); } else if(cmd == "ip" ) { if (s.empty()) museeq->mainwin()->showIPDialog(user()); else museeq->mainwin()->showIPDialog(s.join(" ")); } else if((cmd == "c" || cmd == "chat") && s.empty()) museeq->mainwin()->changeCMode(); else if(cmd == "pm" || cmd == "private") { if(! s.empty()) museeq->mainwin()->showPrivateChat(s.join(" ")); else museeq->mainwin()->changePMode(); } else if(cmd == "transfers" || cmd == "transfer") museeq->mainwin()->changeTMode(); else if(cmd == "clear") mChatPanel->clear(); else if(cmd == "s" || cmd == "search") { if(! s.empty()) museeq->mainwin()->startSearch(s.join(" ")); else museeq->mainwin()->changeSMode(); } else if(cmd == "u" || cmd == "userinfo") { if(! s.empty()) museeq->mainwin()->showUserInfo(s.join(" ")); else museeq->mainwin()->showUserInfo(user()); } else if(cmd == "b" || cmd == "browse") { if(! s.empty()) museeq->mainwin()->showBrowser(s.join(" ")); else museeq->mainwin()->showBrowser(user()); } else if(cmd == "commands") museeq->mainwin()->displayCommandsDialog(); else if(cmd == "about") museeq->mainwin()->displayAboutDialog(); else if(cmd == "help") museeq->mainwin()->displayHelpDialog(); else if(cmd == "ban" && s.empty()) museeq->addBanned(user(), ""); else if(cmd == "unban" && s.empty()) museeq->removeBanned(user()); else if(cmd == "ignore" && s.empty()) museeq->addIgnored(user(), ""); else if(cmd == "unignore" && s.empty()) museeq->removeIgnored(user()); else if(cmd == "buddy" && s.empty()) museeq->addBuddy(user(), ""); else if(cmd == "unbuddy" && s.empty()) museeq->removeBuddy(user()); else if(cmd == "trust" && s.empty()) museeq->addTrusted(user(), ""); else if(cmd == "distrust" && s.empty()) museeq->removeTrusted(user()); else if(cmd == "slap" && s.empty()) { museeq->sayPrivate(user(), "/me slaps "+user()+" around with a large trout"); mChatPanel->append(QString::null, "/me slaps "+user()+" around with a large trout"); } else if((cmd == "j" || cmd == "join") && ! s.empty()) museeq->joinRoom(s.join(" ")); else if((cmd == "jp" || cmd == "joinpriv") && ! s.empty()) // Private room museeq->joinRoom(s.join(" "), true); else if(cmd == "settings") museeq->mainwin()->changeSettings(); else if(cmd == "log") museeq->mainwin()->toggleLog(); else if(cmd == "ticker" || cmd == "tickers" || cmd == "t") museeq->mainwin()->toggleTickers(); else if(cmd == "colors" || cmd == "fonts" || cmd == "f") museeq->mainwin()->changeColors(); else if(cmd == "p" || cmd== "part" || cmd == "l" || cmd == "leave") { if(! s.empty()) museeq->leaveRoom(s.join(" ")); } else mChatPanel->entry()->setText(line); return; } museeq->sayPrivate(user(), line); QStringList lines = line.split("\n"); QStringList::iterator it, end = lines.end(); for(it = lines.begin(); it != end; ++it) { logMessage(user(), museeq->nickname(), *it); mChatPanel->append(QString::null, *it); } }
NResponse & NTcpServerSocketMusicServices::getTitle(const NClientSession & session, NResponse & response) { bool ok; int start = session.url().queryItemValue("start").toInt(); if (!ok) start = 0; int limit = session.url().queryItemValue("limit").toInt(&ok); if (!ok) limit = 25; QString dir = session.url().queryItemValue("dir"); QString sort = session.url().queryItemValue("sort"); QString search = session.url().queryItemValue("search"); QStringList searches = search.split("+", QString::SkipEmptyParts); searches = NConvert_n::fromUTF8PercentEncoding(searches); QString album; if(session.url().hasQueryItem("album")) // Cos of NULL test { album = session.url().queryItemValue("album"); if (album.isNull()) album = ""; album = NConvert_n::fromUTF8PercentEncoding(album); } QString artist; if(session.url().hasQueryItem("artist"))// Cos of NULL test { artist = session.url().queryItemValue("artist"); if (artist.isNull()) artist = ""; artist = NConvert_n::fromUTF8PercentEncoding(artist); } QString genre; if(session.url().hasQueryItem("genre"))// Cos of NULL test { genre = session.url().queryItemValue("genre"); if (genre.isNull()) genre = ""; genre = NConvert_n::fromUTF8PercentEncoding(genre); } int year = session.url().queryItemValue("year").toInt(&ok); if (!ok) year = -1; const NTcpServerAuthSession authSession = getAuthServices().getSession(session.sessionId()); logMessage(session.socket()->peerAddress().toString(), QString("%1 is looking for music search:\"%2\"; album:\"%3\"; artist:\"%4\";"\ "genre:\"%5\"; year:\"%6\"; start:\"%7\"; "\ "limit:\"%8\"; sort:\"%9\"; dir:\"%10\""). arg(authSession.login()). // 1 arg(NConvert_n::fromUTF8PercentEncoding(search)).// 2 arg(album).// 3 arg(artist).// 4 arg(genre).// 5 arg(year).// 6 arg(start).// 7 arg(limit).// 8 arg(sort).// 9 arg(dir));// 10 int totalCount = NMDB.getTitleListCount(searches, album, artist, genre, year); QScriptEngine se; QScriptValue svRoot = se.newObject(); QScriptValue svData = se.newArray(totalCount); svRoot.setProperty(RSP_DATA, svData); bool succeed = NMDB.getTitleList(se, svData, searches, album, artist, genre, year, start, limit, sort, dir); setJsonRootReponse(svRoot, totalCount, succeed); response.setData(NJson::serializeToQByteArray(svRoot)); return response; }
QWidget *ConfigDialog::createMainWidget() { logMessage("ConfigDialog::createMainWidget()"); QWidget *mainWidget = new QWidget(this); // general cmbGUIStyle = new QComboBox(mainWidget); cmbGUIStyle->addItems(QStyleFactory::keys()); cmbGUIStyle->addItem("Manhattan"); cmbLanguage = new QComboBox(mainWidget); cmbLanguage->addItems(availableLanguages()); cmbDefaultPhysicField = new QComboBox(); fillComboBoxPhysicField(cmbDefaultPhysicField); QGridLayout *layoutGeneral = new QGridLayout(); layoutGeneral->addWidget(new QLabel(tr("UI:")), 0, 0); layoutGeneral->addWidget(cmbGUIStyle, 0, 1); layoutGeneral->addWidget(new QLabel(tr("Language:")), 1, 0); layoutGeneral->addWidget(cmbLanguage, 1, 1); layoutGeneral->addWidget(new QLabel(tr("Default physic field:")), 2, 0); layoutGeneral->addWidget(cmbDefaultPhysicField, 2, 1); QGroupBox *grpGeneral = new QGroupBox(tr("General")); grpGeneral->setLayout(layoutGeneral); // collaboration txtCollaborationServerURL = new SLineEditDouble(); QVBoxLayout *layoutCollaboration = new QVBoxLayout(); layoutCollaboration->addWidget(new QLabel(tr("Collaboration server URL:"))); layoutCollaboration->addWidget(txtCollaborationServerURL); QGroupBox *grpCollaboration = new QGroupBox(tr("Collaboration")); grpCollaboration->setLayout(layoutCollaboration); // logs chkEnabledApplicationLog = new QCheckBox(tr("Enabled application log")); chkEnabledProgressLog = new QCheckBox(tr("Enabled progress log")); cmdClearApplicationLog = new QPushButton(mainWidget); cmdClearApplicationLog->setText(tr("Clear application log")); connect(cmdClearApplicationLog, SIGNAL(clicked()), this, SLOT(doClearApplicationLog())); cmdClearCommandHistory = new QPushButton(mainWidget); cmdClearCommandHistory->setText(tr("Clear command history")); connect(cmdClearCommandHistory, SIGNAL(clicked()), this, SLOT(doClearCommandHistory())); QGridLayout *layoutClearButtons = new QGridLayout(); layoutClearButtons->addWidget(cmdClearApplicationLog, 0, 0); layoutClearButtons->addWidget(cmdClearCommandHistory, 0, 1); QVBoxLayout *layoutLogs = new QVBoxLayout(); layoutLogs->addWidget(chkEnabledProgressLog); layoutLogs->addWidget(chkEnabledApplicationLog); layoutLogs->addLayout(layoutClearButtons); QGroupBox *grpLogs = new QGroupBox(tr("Logs")); grpLogs->setLayout(layoutLogs); // other chkLineEditValueShowResult = new QCheckBox(tr("Show value result in line edit input")); chkCheckVersion = new QCheckBox(tr("Check new version during startup.")); chkExperimentalFeatures = new QCheckBox(tr("Enable experimental features")); chkExperimentalFeatures->setToolTip(tr("Warning: Agros2D should be unstable!")); QVBoxLayout *layoutOther = new QVBoxLayout(); layoutOther->addWidget(chkLineEditValueShowResult); layoutOther->addWidget(chkCheckVersion); layoutOther->addWidget(chkExperimentalFeatures); QGroupBox *grpOther = new QGroupBox(tr("Other")); grpOther->setLayout(layoutOther); // layout QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(grpGeneral); layout->addWidget(grpCollaboration); layout->addWidget(grpLogs); layout->addWidget(grpOther); layout->addStretch(); mainWidget->setLayout(layout); return mainWidget; }
void testFinished() { stopTest(); startTestButton.setEnabled (true); logMessage (newLine + "*** Tests finished ***"); }
QWidget *ConfigDialog::createViewWidget() { logMessage("ConfigDialog::createViewWidget()"); // geometry txtGeometryNodeSize = new SLineEditDouble(); // txtGeometryNodeSize->setMaximumWidth(60); txtGeometryEdgeWidth = new SLineEditDouble(); // txtGeometryEdgeWidth->setMaximumWidth(60); txtGeometryLabelSize = new SLineEditDouble(); // txtGeometryLabelSize->setMaximumWidth(60); QGridLayout *layoutGeometry = new QGridLayout(); layoutGeometry->addWidget(new QLabel(tr("Node size:")), 0, 0); layoutGeometry->addWidget(txtGeometryNodeSize, 0, 1); layoutGeometry->addWidget(new QLabel(tr("Edge width:")), 1, 0); layoutGeometry->addWidget(txtGeometryEdgeWidth, 1, 1); layoutGeometry->addWidget(new QLabel(tr("Label size:")), 2, 0); layoutGeometry->addWidget(txtGeometryLabelSize, 2, 1); QGroupBox *grpGeometry = new QGroupBox(tr("Geometry")); grpGeometry->setLayout(layoutGeometry); // others; chkZoomToMouse = new QCheckBox(tr("Zoom to mouse pointer")); QVBoxLayout *layoutOther = new QVBoxLayout(); layoutOther->addWidget(chkZoomToMouse); QGroupBox *grpOther = new QGroupBox(tr("Other")); grpOther->setLayout(layoutOther); // layout general QVBoxLayout *layoutGeneral = new QVBoxLayout(); layoutGeneral->addWidget(grpGeometry); layoutGeneral->addWidget(grpOther); layoutGeneral->addStretch(); QWidget *widgetGeneral = new QWidget(this); widgetGeneral->setLayout(layoutGeneral); // scalar view log scale chkScalarFieldRangeLog = new QCheckBox(tr("Log. scale")); txtScalarFieldRangeBase = new QLineEdit("10"); connect(chkScalarFieldRangeLog, SIGNAL(stateChanged(int)), this, SLOT(doScalarFieldLog(int))); txtScalarDecimalPlace = new QSpinBox(this); txtScalarDecimalPlace->setMinimum(1); txtScalarDecimalPlace->setMaximum(10); QGridLayout *layoutScalarField = new QGridLayout(); layoutScalarField->addWidget(new QLabel(tr("Base:")), 0, 0); layoutScalarField->addWidget(txtScalarFieldRangeBase, 0, 1); layoutScalarField->addWidget(chkScalarFieldRangeLog, 0, 2); layoutScalarField->addWidget(new QLabel(tr("Decimal places:")), 1, 0); layoutScalarField->addWidget(txtScalarDecimalPlace, 1, 1); QGroupBox *grpScalarField = new QGroupBox(tr("Scalar view")); grpScalarField->setLayout(layoutScalarField); // layout 3d chkView3DLighting = new QCheckBox(tr("Ligthing"), this); txtView3DAngle = new QDoubleSpinBox(this); txtView3DAngle->setDecimals(1); txtView3DAngle->setSingleStep(1); txtView3DAngle->setMinimum(30); txtView3DAngle->setMaximum(360); chkView3DBackground = new QCheckBox(tr("Gradient background"), this); txtView3DHeight = new QDoubleSpinBox(this); txtView3DHeight->setDecimals(1); txtView3DHeight->setSingleStep(0.1); txtView3DHeight->setMinimum(0.2); txtView3DHeight->setMaximum(10.0); QGridLayout *layout3D = new QGridLayout(); layout3D->addWidget(new QLabel(tr("Angle:")), 0, 1); layout3D->addWidget(txtView3DAngle, 0, 2); layout3D->addWidget(chkView3DLighting, 0, 3); layout3D->addWidget(new QLabel(tr("Height:")), 1, 1); layout3D->addWidget(txtView3DHeight, 1, 2); layout3D->addWidget(chkView3DBackground, 1, 3); QGroupBox *grp3D = new QGroupBox(tr("3D")); grp3D->setLayout(layout3D); // layout deform shape chkDeformScalar = new QCheckBox(tr("Scalar field"), this); chkDeformContour = new QCheckBox(tr("Contours"), this); chkDeformVector = new QCheckBox(tr("Vector field"), this); QGridLayout *layoutDeformShape = new QGridLayout(); layoutDeformShape->addWidget(chkDeformScalar, 0, 0); layoutDeformShape->addWidget(chkDeformContour, 0, 1); layoutDeformShape->addWidget(chkDeformVector, 0, 2); QGroupBox *grpDeformShape = new QGroupBox(tr("Deform shape")); grpDeformShape->setLayout(layoutDeformShape); // layout postprocessor QVBoxLayout *layoutPostprocessor = new QVBoxLayout(); layoutPostprocessor->addWidget(grpScalarField); layoutPostprocessor->addWidget(grp3D); layoutPostprocessor->addWidget(grpDeformShape); layoutPostprocessor->addStretch(); QWidget *widgetPostprocessor = new QWidget(this); widgetPostprocessor->setLayout(layoutPostprocessor); QTabWidget *tabType = new QTabWidget(this); tabType->addTab(widgetGeneral, icon(""), tr("General")); tabType->addTab(widgetPostprocessor, icon(""), tr("Postprocessor")); return tabType; }
void Widget::tcpProcessData(QByteArray data, QTcpSocket* socket) { if (tcpReceivedDatas->contains("commfunction=login&") && tcpReceivedDatas->contains("&version=")) // Login request { QString postData = QString(*tcpReceivedDatas); *tcpReceivedDatas = tcpReceivedDatas->right(postData.size()-postData.indexOf("version=")-8-4); // 4 : size of version number (ie:version=1344) logMessage("TCP: Login request received :"); QFile file(QString(NETDATAPATH)+"/loginHeader.bin"); QFile fileServersList(SERVERSLISTFILEPATH); QFile fileBadPassword(QString(NETDATAPATH)+"/loginWrongPassword.bin"); QFile fileAlready(QString(NETDATAPATH)+"/loginAlreadyConnected.bin"); QFile fileMaxRegistration(QString(NETDATAPATH)+"/loginMaxRegistered.bin"); QFile fileMaxConnected(QString(NETDATAPATH)+"/loginMaxConnected.bin"); if (!file.open(QIODevice::ReadOnly) || !fileBadPassword.open(QIODevice::ReadOnly) || !fileAlready.open(QIODevice::ReadOnly) || !fileMaxRegistration.open(QIODevice::ReadOnly) || !fileMaxConnected.open(QIODevice::ReadOnly) || !fileServersList.open(QIODevice::ReadOnly)) { logStatusMessage("Error reading login data files"); stopServer(); } else { bool ok=true; postData = postData.right(postData.size()-postData.indexOf("username="******"passhash=")-9); QString passhash = postData; passhash.truncate(postData.indexOf('&')); logMessage(QString("IP : ")+socket->peerAddress().toString()); logMessage(QString("Username : "******"Passhash : ")+passhash); // Add player to the players list Player player = Player::findPlayer(tcpPlayers, username); if (player.name != username) // Not found, create a new player { // Check max registered number if (tcpPlayers.size() >= maxRegistered) { logMessage("TCP: Registration failed, too much players registered"); socket->write(fileMaxRegistration.readAll()); ok = false; } else { logMessage("TCP: Creating user in database"); Player newPlayer; newPlayer.name = username; newPlayer.passhash = passhash; newPlayer.IP = socket->peerAddress().toString(); newPlayer.connected = false; // The connection checks are done by the game servers tcpPlayers << newPlayer; if (!Player::savePlayers(tcpPlayers)) ok = false; } } else // Found, compare passhashes, check if already connected { if (player.passhash != passhash) // Bad password { logMessage("TCP: Login failed, wrong password"); socket->write(fileBadPassword.readAll()); ok=false; } /* else if (newPlayer.connected) // Already connected { logMessage("TCP: Login failed, player already connected"); socket->write(fileAlready.readAll()); ok=false; } */ else // Good password { /* // Check too many connected int n=0; for (int i=0;i<tcpPlayers.size();i++) if (tcpPlayers[i].connected) n++; if (n>=maxConnected) { logMessage("TCP: Login failed, too much players connected"); socket->write(fileMaxConnected.readAll()); ok=false; } else */ { player.reset(); player.IP = socket->peerAddress().toString(); player.lastPingTime = timestampNow(); player.connected = true; } } } if (ok) // Send servers list { QByteArray customData = file.readAll(); QByteArray data1 = QByteArray::fromHex("0D0A61757468726573706F6E73653A0A747275650A"); QByteArray sesskey = QCryptographicHash::hash(QString(passhash + saltPassword).toLatin1(), QCryptographicHash::Md5).toHex(); sesskey += passhash; QByteArray data2 = QByteArray::fromHex("0A310A"); QByteArray serversList; QByteArray line; do { line = fileServersList.readLine().trimmed(); serversList+=line; serversList+=0x0A; } while (!line.isEmpty()); serversList = serversList.trimmed(); QByteArray data3 = QByteArray::fromHex("0D0A300D0A0D0A"); int dataSize = data1.size() + sesskey.size() + data2.size() + serversList.size() - 2; QString dataSizeStr = QString().setNum(dataSize, 16); customData += dataSizeStr; customData += data1; customData += sesskey; customData += data2; customData += serversList; customData += data3; logMessage("TCP: Login successful, sending servers list"); socket->write(customData); } } } else if (data.contains("commfunction=removesession")) { logMessage("TCP: Session closed by client"); } else // Unknown request, erase tcp buffer { // Display data logMessage("TCP: Unknow request received : "); logMessage(QString(data.data())); } // Delete the processed message from the buffer *tcpReceivedDatas = tcpReceivedDatas->right(tcpReceivedDatas->size() - tcpReceivedDatas->indexOf(data) - data.size()); }
QWidget *ConfigDialog::createSolverWidget() { logMessage("ConfigDialog::createSolverWidget()"); // general chkDeleteTriangleMeshFiles = new QCheckBox(tr("Delete files with initial mesh (Triangle)")); chkDeleteHermes2DMeshFile = new QCheckBox(tr("Delete files with solution mesh (Hermes2D)")); if (Util::config()->showExperimentalFeatures) chkSaveWithSolution = new QCheckBox(tr("Save problem with solution")); chkShowConvergenceChart = new QCheckBox(tr("Show convergence chart after solving")); QVBoxLayout *layoutSolver = new QVBoxLayout(); layoutSolver->addWidget(chkDeleteTriangleMeshFiles); layoutSolver->addWidget(chkDeleteHermes2DMeshFile); if (Util::config()->showExperimentalFeatures) layoutSolver->addWidget(chkSaveWithSolution); layoutSolver->addWidget(chkShowConvergenceChart); QGroupBox *grpSolver = new QGroupBox(tr("Solver")); grpSolver->setLayout(layoutSolver); txtMeshAngleSegmentsCount = new QSpinBox(this); txtMeshAngleSegmentsCount->setMinimum(2); txtMeshAngleSegmentsCount->setMaximum(20); chkMeshCurvilinearElements = new QCheckBox(tr("Curvilinear elements")); QGridLayout *layoutMesh = new QGridLayout(); layoutMesh->addWidget(new QLabel(tr("Angle segments count:")), 0, 0); layoutMesh->addWidget(txtMeshAngleSegmentsCount, 0, 1); layoutMesh->addWidget(chkMeshCurvilinearElements, 1, 0, 1, 2); QGroupBox *grpMesh = new QGroupBox(tr("Mesh")); grpMesh->setLayout(layoutMesh); QVBoxLayout *layoutGeneral = new QVBoxLayout(); layoutGeneral->addWidget(grpSolver); layoutGeneral->addWidget(grpMesh); layoutGeneral->addStretch(); QWidget *solverGeneralWidget = new QWidget(this); solverGeneralWidget->setLayout(layoutGeneral); // adaptivity lblMaxDofs = new QLabel(tr("Maximum number of DOFs:")); txtMaxDOFs = new QSpinBox(this); txtMaxDOFs->setMinimum(1e2); txtMaxDOFs->setMaximum(1e9); txtMaxDOFs->setSingleStep(1e2); /* chkIsoOnly = new QCheckBox(tr("Isotropic refinement")); lblIsoOnly = new QLabel(tr("<table>" "<tr><td><b>true</b></td><td>isotropic refinement</td></tr>" "<tr><td><b>false</b></td><td>anisotropic refinement</td></tr>" "</table>")); */ txtConvExp = new SLineEditDouble(); lblConvExp = new QLabel(tr("<b></b>default value is 1.0, this parameter influences<br/>the selection of candidates in hp-adaptivity")); txtThreshold = new SLineEditDouble(); lblThreshold = new QLabel(tr("<b></b>quantitative parameter of the adapt(...) function<br/>with different meanings for various adaptive strategies")); cmbStrategy = new QComboBox(); cmbStrategy->addItem(tr("0"), 0); cmbStrategy->addItem(tr("1"), 1); cmbStrategy->addItem(tr("2"), 2); lblStrategy = new QLabel(tr("<table>" "<tr><td><b>0</b></td><td>refine elements until sqrt(<b>threshold</b>)<br/>times total error is processed.<br/>If more elements have similar errors,<br/>refine all to keep the mesh symmetric</td></tr>" "<tr><td><b>1</b></td><td>refine all elements<br/>whose error is larger than <b>threshold</b><br/>times maximum element error</td></tr>" "<tr><td><b>2</b></td><td>refine all elements<br/>whose error is larger than <b>threshold</b></td></tr>" "</table>")); cmbMeshRegularity = new QComboBox(); cmbMeshRegularity->addItem(tr("arbitrary level hang. nodes"), -1); cmbMeshRegularity->addItem(tr("at most one-level hang. nodes"), 1); cmbMeshRegularity->addItem(tr("at most two-level hang. nodes"), 2); cmbMeshRegularity->addItem(tr("at most three-level hang. nodes"), 3); cmbMeshRegularity->addItem(tr("at most four-level hang. nodes"), 4); cmbMeshRegularity->addItem(tr("at most five-level hang. nodes"), 5); cmbProjNormType = new QComboBox(); cmbProjNormType->addItem(errorNormString(HERMES_H1_NORM), HERMES_H1_NORM); cmbProjNormType->addItem(errorNormString(HERMES_L2_NORM), HERMES_L2_NORM); cmbProjNormType->addItem(errorNormString(HERMES_H1_SEMINORM), HERMES_H1_SEMINORM); // default QPushButton *btnAdaptivityDefault = new QPushButton(tr("Default")); connect(btnAdaptivityDefault, SIGNAL(clicked()), this, SLOT(doAdaptivityDefault())); QGridLayout *layoutAdaptivitySettings = new QGridLayout(); layoutAdaptivitySettings->addWidget(lblMaxDofs, 0, 0); layoutAdaptivitySettings->addWidget(txtMaxDOFs, 0, 1, 1, 2); layoutAdaptivitySettings->addWidget(new QLabel(tr("Conv. exp.:")), 2, 0); layoutAdaptivitySettings->addWidget(txtConvExp, 2, 1); layoutAdaptivitySettings->addWidget(lblConvExp, 3, 0, 1, 2); layoutAdaptivitySettings->addWidget(new QLabel(tr("Strategy:")), 4, 0); layoutAdaptivitySettings->addWidget(cmbStrategy, 4, 1); layoutAdaptivitySettings->addWidget(lblStrategy, 5, 0, 1, 2); layoutAdaptivitySettings->addWidget(new QLabel(tr("Threshold:")), 6, 0); layoutAdaptivitySettings->addWidget(txtThreshold, 6, 1); layoutAdaptivitySettings->addWidget(lblThreshold, 7, 0, 1, 2); layoutAdaptivitySettings->addWidget(new QLabel(tr("Mesh regularity:")), 8, 0); layoutAdaptivitySettings->addWidget(cmbMeshRegularity, 8, 1); layoutAdaptivitySettings->addWidget(new QLabel(tr("Norm:")), 9, 0); layoutAdaptivitySettings->addWidget(cmbProjNormType, 9, 1); QVBoxLayout *layoutAdaptivity = new QVBoxLayout(); layoutAdaptivity->addLayout(layoutAdaptivitySettings); layoutAdaptivity->addStretch(); layoutAdaptivity->addWidget(btnAdaptivityDefault, 0, Qt::AlignLeft); QWidget *solverAdaptivityWidget = new QWidget(this); solverAdaptivityWidget->setLayout(layoutAdaptivity); // commands txtArgumentTriangle = new QLineEdit(""); txtArgumentFFmpeg = new QLineEdit(""); // default QPushButton *btnCommandsDefault = new QPushButton(tr("Default")); connect(btnCommandsDefault, SIGNAL(clicked()), this, SLOT(doCommandsDefault())); QVBoxLayout *layoutCommands = new QVBoxLayout(); layoutCommands->addWidget(new QLabel(tr("Triangle"))); layoutCommands->addWidget(txtArgumentTriangle); layoutCommands->addWidget(new QLabel(tr("FFmpeg"))); layoutCommands->addWidget(txtArgumentFFmpeg); layoutCommands->addStretch(); layoutCommands->addWidget(btnCommandsDefault, 0, Qt::AlignLeft); QWidget *solverCommandsWidget = new QWidget(this); solverCommandsWidget->setLayout(layoutCommands); QTabWidget *solverWidget = new QTabWidget(this); solverWidget->addTab(solverGeneralWidget, icon(""), tr("General")); solverWidget->addTab(solverAdaptivityWidget, icon(""), tr("Adaptivity")); solverWidget->addTab(solverCommandsWidget, icon(""), tr("Commands")); return solverWidget; }
void Widget::tcpProcessPendingDatagrams() { // On détermine quel client envoie le message (recherche du QTcpSocket du client) QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender()); if (socket == 0) // Si par hasard on n'a pas trouvé le client à l'origine du signal, on arrête la méthode return; unsigned nTries = 0; // Acquire data while(socket->state()==QAbstractSocket::ConnectedState && nTries<3) // Exit if disconnected, too much retries, malformed HTTP request, or after all requests are processed { // TODO: Give up after three tries reading the same message tcpReceivedDatas->append(socket->readAll()); nTries++; if (!tcpReceivedDatas->startsWith("POST") && !tcpReceivedDatas->startsWith("GET")) // Not HTTP, clear the buffer { logMessage("TCP: Received non-HTTP request"); tcpReceivedDatas->clear(); socket->close(); return; } else if (tcpReceivedDatas->contains("Content-Length:")) // POST or GET request, wait for Content-Length header { QByteArray contentLength = *tcpReceivedDatas; contentLength = contentLength.right(contentLength.size() - contentLength.indexOf("Content-Length:") - 15); QList<QByteArray> lengthList = contentLength.trimmed().split('\n'); if (lengthList.size()>1) // We want a number on this line and a next line to be sure we've got the full number { bool isNumeric; int length = lengthList[0].trimmed().toInt(&isNumeric); if (!isNumeric) // We've got something but it's not a number { logMessage("TCP: Content-Length must be a decimal number"); tcpReceivedDatas->clear(); socket->close(); return; } // Detect and send data files if we need to // TODO: Process and send all the requested data QByteArray data = *tcpReceivedDatas; int i1=0; do { i1 = data.indexOf("GET"); if (i1 != -1) { int i2 = data.indexOf("HTTP")-1; QString path = data.mid(i1 + 4, i2-i1-4); logMessage("Received GET:"+path); QFile head(QString(NETDATAPATH)+"/test.bin"); QFile res("gameFiles"+path); head.open(QIODevice::ReadOnly); res.open(QIODevice::ReadOnly); socket->write(head.readAll()); socket->write(QString("Content-Length: "+QString().setNum(res.size())+"\n\n").toLatin1()); socket->write(res.readAll()); head.close(); res.close(); logMessage("Sent ("+QString().setNum(res.size())+" bytes)"); data = removeHTTPHeader(data, "POST "); data = removeHTTPHeader(data, "GET "); } } while (i1 != -1); // Get the HTML data/payload data = removeHTTPHeader(data, "POST "); data = removeHTTPHeader(data, "GET "); data = removeHTTPHeader(data, "User-Agent:"); data = removeHTTPHeader(data, "Host:"); data = removeHTTPHeader(data, "Accept:"); data = removeHTTPHeader(data, "Content-Length:"); data = removeHTTPHeader(data, "Content-Type:"); data = removeHTTPHeader(data, "Server:"); data = removeHTTPHeader(data, "Date:"); data = removeHTTPHeader(data, "Transfert-Encoding:"); data = removeHTTPHeader(data, "Connection:"); data = removeHTTPHeader(data, "Vary:"); data = removeHTTPHeader(data, "X-Powered-By:"); data = removeHTTPHeader(data, "accept-encoding:"); data = removeHTTPHeader(data, "if-modified-since:"); if (data.size() >= length) // Wait until we have all the data { data.truncate(length); // Process data, if the buffer is not empty, keep reading tcpProcessData(data, socket); if (tcpReceivedDatas->isEmpty()) return; nTries=0; } } } } }
void ConfigDialog::doCurrentItemChanged(QListWidgetItem *current, QListWidgetItem *previous) { logMessage("ConfigDialog::doCurrentItemChanged()"); pages->setCurrentIndex(lstView->row(current)); }
ssize_t usbControlTransfer ( UsbDevice *device, uint8_t direction, uint8_t recipient, uint8_t type, uint8_t request, uint16_t value, uint16_t index, void *buffer, uint16_t length, int timeout ) { UsbDeviceExtension *devx = device->extension; UsbSetupPacket setup; setup.bRequestType = direction | recipient | type; setup.bRequest = request; putLittleEndian16(&setup.wValue, value); putLittleEndian16(&setup.wIndex, index); putLittleEndian16(&setup.wLength, length); switch (direction) { case UsbControlDirection_Input: { size_t size = sizeof(setup); ssize_t count; if ((count = write(devx->data, &setup, size)) == -1) { logSystemError("USB control request"); } else if (count != size) { logMessage(LOG_ERR, "USB truncated control request: %d < %d", count, size); errno = EIO; } else if ((count = read(devx->data, buffer, length)) == -1) { logSystemError("USB control read"); } else { return count; } break; } case UsbControlDirection_Output: { unsigned char packet[sizeof(setup) + length]; size_t size = 0; ssize_t count; memcpy(&packet[size], &setup, sizeof(setup)); size += sizeof(setup); memcpy(&packet[size], buffer, length); size += length; if ((count = write(devx->data, packet, size)) == -1) { logSystemError("USB control write"); } else if (count != size) { logMessage(LOG_ERR, "USB truncated control write: %d < %d", count, size); errno = EIO; } else { return size; } break; } default: logMessage(LOG_ERR, "USB unsupported control direction: %02X", direction); errno = ENOSYS; break; } return -1; }
void ConfigDialog::doReject() { logMessage("ConfigDialog::ConfigDialog()"); reject(); }
int usbAllocateEndpointExtension (UsbEndpoint *endpoint) { UsbDevice *device = endpoint->device; UsbDeviceExtension *devx = device->extension; UsbEndpointExtension *eptx; if ((eptx = malloc(sizeof(*eptx)))) { if ((eptx->requests = newQueue(NULL, NULL))) { int flags; { char name[0X80]; int length = 0; if (devx->configuration != 1) { int count; sprintf(&name[length], "cfg%d%n", devx->configuration, &count); length += count; } { int count; sprintf(&name[length], "if%d%n", devx->interface, &count); length += count; } if (devx->alternative != 0) { int count; sprintf(&name[length], ".%d%n", devx->alternative, &count); length += count; } { const UsbEndpointDescriptor *descriptor = endpoint->descriptor; UsbEndpointDirection direction = USB_ENDPOINT_DIRECTION(descriptor); const char *prefix; switch (direction) { case UsbEndpointDirection_Input: prefix = "in"; flags = O_RDONLY; break; case UsbEndpointDirection_Output: prefix = "out"; flags = O_WRONLY; break; default: logMessage(LOG_ERR, "USB unsupported endpoint direction: %02X", direction); goto nameError; } { int count; sprintf(&name[length], "%s%d%n", prefix, USB_ENDPOINT_NUMBER(descriptor), &count); length += count; } } eptx->name = strdup(name); } if (eptx->name) { if (usbOpenEndpointFiles(devx->path, eptx->name, &eptx->data, &eptx->status, flags)) { endpoint->extension = eptx; return 1; } free(eptx->name); } nameError: deallocateQueue(eptx->requests); } free(eptx); } return 0; }
static int insertKey_ScreenScreen (ScreenKey key) { const unsigned char flags = getAuxiliaryData()[1]; wchar_t character = key & SCR_KEY_CHAR_MASK; char buffer[3]; char *sequence; logMessage(LOG_DEBUG, "insert key: %04X", key); setKeyModifiers(&key, 0); if (isSpecialKey(key)) { #define KEY(key,string) case (key): sequence = (string); break #define CURSOR_KEY(key,string1,string2) KEY((key), ((flags & 0X01)? (string1): (string2))) switch (character) { KEY(SCR_KEY_ENTER, "\r"); KEY(SCR_KEY_TAB, "\t"); KEY(SCR_KEY_BACKSPACE, "\x7f"); KEY(SCR_KEY_ESCAPE, "\x1b"); CURSOR_KEY(SCR_KEY_CURSOR_LEFT , "\x1bOD", "\x1b[D"); CURSOR_KEY(SCR_KEY_CURSOR_RIGHT, "\x1bOC", "\x1b[C"); CURSOR_KEY(SCR_KEY_CURSOR_UP , "\x1bOA", "\x1b[A"); CURSOR_KEY(SCR_KEY_CURSOR_DOWN , "\x1bOB", "\x1b[B"); KEY(SCR_KEY_PAGE_UP, "\x1b[5~"); KEY(SCR_KEY_PAGE_DOWN, "\x1b[6~"); KEY(SCR_KEY_HOME, "\x1b[1~"); KEY(SCR_KEY_END, "\x1b[4~"); KEY(SCR_KEY_INSERT, "\x1b[2~"); KEY(SCR_KEY_DELETE, "\x1b[3~"); KEY(SCR_KEY_FUNCTION+0, "\x1bOP"); KEY(SCR_KEY_FUNCTION+1, "\x1bOQ"); KEY(SCR_KEY_FUNCTION+2, "\x1bOR"); KEY(SCR_KEY_FUNCTION+3, "\x1bOS"); KEY(SCR_KEY_FUNCTION+4, "\x1b[15~"); KEY(SCR_KEY_FUNCTION+5, "\x1b[17~"); KEY(SCR_KEY_FUNCTION+6, "\x1b[18~"); KEY(SCR_KEY_FUNCTION+7, "\x1b[19~"); KEY(SCR_KEY_FUNCTION+8, "\x1b[20~"); KEY(SCR_KEY_FUNCTION+9, "\x1b[21~"); KEY(SCR_KEY_FUNCTION+10, "\x1b[23~"); KEY(SCR_KEY_FUNCTION+11, "\x1b[24~"); KEY(SCR_KEY_FUNCTION+12, "\x1b[25~"); KEY(SCR_KEY_FUNCTION+13, "\x1b[26~"); KEY(SCR_KEY_FUNCTION+14, "\x1b[28~"); KEY(SCR_KEY_FUNCTION+15, "\x1b[29~"); KEY(SCR_KEY_FUNCTION+16, "\x1b[31~"); KEY(SCR_KEY_FUNCTION+17, "\x1b[32~"); KEY(SCR_KEY_FUNCTION+18, "\x1b[33~"); KEY(SCR_KEY_FUNCTION+19, "\x1b[34~"); default: logMessage(LOG_WARNING, "unsuported key: %04X", key); return 0; } #undef CURSOR_KEY #undef KEY } else { int byte = convertWcharToChar(character); if (byte == EOF) { logMessage(LOG_WARNING, "character not supported in local character set: 0X%04X", key); } sequence = buffer + sizeof(buffer); *--sequence = 0; *--sequence = byte; if (key & SCR_KEY_ALT_LEFT) *--sequence = 0X1B; } return doScreenCommand("stuff", sequence, NULL); }
void ConfigDialog::save() { logMessage("ConfigDialog::save()"); // gui style Util::config()->guiStyle = cmbGUIStyle->currentText(); setGUIStyle(cmbGUIStyle->currentText()); // language if (Util::config()->language != cmbLanguage->currentText()) QMessageBox::warning(QApplication::activeWindow(), tr("Language change"), tr("Interface language has been changed. You must restart the application.")); Util::config()->language = cmbLanguage->currentText(); // default physic field Util::config()->defaultPhysicField = (PhysicField) cmbDefaultPhysicField->itemData(cmbDefaultPhysicField->currentIndex()).toInt(); // collaboration server QString collaborationServerUrl = txtCollaborationServerURL->text(); if (!collaborationServerUrl.startsWith("http://")) collaborationServerUrl = QString("http://%1").arg(collaborationServerUrl); if (!collaborationServerUrl.endsWith("/")) collaborationServerUrl = QString("%1/").arg(collaborationServerUrl); Util::config()->collaborationServerURL = collaborationServerUrl; // check version Util::config()->checkVersion = chkCheckVersion->isChecked(); // show convergence chart Util::config()->showConvergenceChart = chkShowConvergenceChart->isChecked(); // logs Util::config()->enabledApplicationLog = chkEnabledApplicationLog->isChecked(); Util::config()->enabledProgressLog = chkEnabledProgressLog->isChecked(); // show result in line edit value widget Util::config()->lineEditValueShowResult = chkLineEditValueShowResult->isChecked(); // geometry Util::config()->nodeSize = txtGeometryNodeSize->value(); Util::config()->edgeWidth = txtGeometryEdgeWidth->value(); Util::config()->labelSize = txtGeometryLabelSize->value(); Util::config()->zoomToMouse = chkZoomToMouse->isChecked(); // mesh Util::config()->angleSegmentsCount = txtMeshAngleSegmentsCount->value(); Util::config()->curvilinearElements = chkMeshCurvilinearElements->isChecked(); // delete files Util::config()->deleteTriangleMeshFiles = chkDeleteTriangleMeshFiles->isChecked(); Util::config()->deleteHermes2DMeshFile = chkDeleteHermes2DMeshFile->isChecked(); // save problem with solution if (Util::config()->showExperimentalFeatures) Util::config()->saveProblemWithSolution = chkSaveWithSolution->isChecked(); // color Util::config()->colorBackground = colorBackground->color(); Util::config()->colorGrid = colorGrid->color(); Util::config()->colorCross = colorCross->color(); Util::config()->colorNodes = colorNodes->color(); Util::config()->colorEdges = colorEdges->color(); Util::config()->colorLabels = colorLabels->color(); Util::config()->colorContours = colorContours->color(); Util::config()->colorVectors = colorVectors->color(); Util::config()->colorInitialMesh = colorInitialMesh->color(); Util::config()->colorSolutionMesh = colorSolutionMesh->color(); Util::config()->colorHighlighted = colorHighlighted->color(); Util::config()->colorSelected = colorSelected->color(); // scalar view Util::config()->scalarRangeLog = chkScalarFieldRangeLog->isChecked(); Util::config()->scalarRangeBase = txtScalarFieldRangeBase->text().toDouble(); Util::config()->scalarDecimalPlace = txtScalarDecimalPlace->value(); // 3d Util::config()->scalarView3DLighting = chkView3DLighting->isChecked(); Util::config()->scalarView3DAngle = txtView3DAngle->value(); Util::config()->scalarView3DBackground = chkView3DBackground->isChecked(); Util::config()->scalarView3DHeight = txtView3DHeight->value(); // deform shape Util::config()->deformScalar = chkDeformScalar->isChecked(); Util::config()->deformContour = chkDeformContour->isChecked(); Util::config()->deformVector = chkDeformVector->isChecked(); // adaptivity Util::config()->maxDofs = txtMaxDOFs->value(); //Util::config()->isoOnly = chkIsoOnly->isChecked(); Util::config()->convExp = txtConvExp->value(); Util::config()->threshold = txtThreshold->value(); Util::config()->strategy = cmbStrategy->itemData(cmbStrategy->currentIndex()).toInt(); Util::config()->meshRegularity = cmbMeshRegularity->itemData(cmbMeshRegularity->currentIndex()).toInt(); Util::config()->projNormType = (ProjNormType) cmbProjNormType->itemData(cmbProjNormType->currentIndex()).toInt(); // command argument Util::config()->commandTriangle = txtArgumentTriangle->text(); Util::config()->commandFFmpeg = txtArgumentFFmpeg->text(); // experimental features Util::config()->showExperimentalFeatures = chkExperimentalFeatures->isChecked(); // global script Util::config()->globalScript = txtGlobalScript->toPlainText(); // save Util::config()->save(); }
int smsa_vwrite( SMSA_VIRTUAL_ADDRESS addr, uint32_t len, unsigned char *buf ) { // First check if the length is 0 // Write nothing and return if so if(len == 0) { return 0; } /* Initialize variables */ int i; int err = 0; int read_bytes = 0; uint32_t offset; SMSA_DRUM_ID drum; SMSA_BLOCK_ID block; SMSA_BLOCK_ID block_orig; unsigned char *smsa_vwrite_buffer = NULL; drum = find_drum(addr); block = find_block(addr); block_orig = block; offset = addr & 0xff; seek_if_i_must(drum, block); // Loop to iterate through blocks do { /* Bounds Check */ // Check if drum is in bounds if( (drum > SMSA_DISK_ARRAY_SIZE) || (drum < 0) ) { logMessage( LOG_ERROR_LEVEL, "The drum is out of bounds [%d]\n", drum ); return -1; } // Check if block is in bounds if( (block > SMSA_MAX_BLOCK_ID) || (block < 0) ) { logMessage( LOG_ERROR_LEVEL, "The block is out of bounds [%d]\n", block ); return -1; } // Check if original block if( block == block_orig ) { i = offset; } else { i = 0; } // If last block if( (block == SMSA_BLOCK_SIZE) ) { block = 0; curBlock = 0; drum++; seek_if_i_must(drum, block); } /* Is it in the cache? */ logMessage(LOG_INFO_LEVEL, "Asking cache at: drum[%d]\tblock[%d]\n", drum, block); smsa_vwrite_buffer = smsa_get_cache_line(drum, block); // If Yes if(smsa_vwrite_buffer != NULL) { do { smsa_vwrite_buffer[i] = buf[read_bytes]; read_bytes++; i++; } while( (i<SMSA_BLOCK_SIZE) && (read_bytes<len) ); block++; curBlock++; /* smsa_operation( SEEK_BLOCK, NULL ); */ } // If No else { smsa_vwrite_buffer = (unsigned char *) malloc(SMSA_BLOCK_SIZE * sizeof(unsigned char)); // Read from disk smsa_operation( DISK_READ, smsa_vwrite_buffer); // Loop to write into buffer do { smsa_vwrite_buffer[i] = buf[read_bytes]; read_bytes++; i++; } while( (i<SMSA_BLOCK_SIZE) && (read_bytes<len) ); // Put into cache logMessage(LOG_INFO_LEVEL, "Finding a place to put the cache entry...\n"); err = smsa_put_cache_line(drum, block, smsa_vwrite_buffer); block++; curBlock++; } if(err) { logMessage(LOG_ERROR_LEVEL, "Something bad happened in the cache :/\n"); return -1; } // Write to disk smsa_operation( SEEK_PREVIOUS_BLOCK, NULL ); /* if(block == 0) { */ /* smsa_put_cache_line(drum-1, 255, smsa_vwrite_buffer); */ /* } else { */ /* smsa_put_cache_line(drum, block-1, smsa_vwrite_buffer); */ /* } */ smsa_operation( DISK_WRITE, smsa_vwrite_buffer ); } while(read_bytes<len); return 0; }
void ConfigDialog::createControls() { logMessage("ConfigDialog::createControls()"); lstView = new QListWidget(this); pages = new QStackedWidget(this); panMain = createMainWidget(); panView = createViewWidget(); panSolver = createSolverWidget(); panColors = createColorsWidget(); panGlobalScriptWidget = createGlobalScriptWidget(); // List View lstView->setCurrentRow(0); lstView->setViewMode(QListView::IconMode); lstView->setResizeMode(QListView::Adjust); lstView->setMovement(QListView::Static); lstView->setFlow(QListView::TopToBottom); lstView->setIconSize(QSize(60, 60)); lstView->setMinimumWidth(135); lstView->setMaximumWidth(135); lstView->setMinimumHeight((45+fontMetrics().height()*4)*5); connect(lstView, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)), this, SLOT(doCurrentItemChanged(QListWidgetItem *, QListWidgetItem *))); QSize sizeItem(131, 85); // listView items QListWidgetItem *itemMain = new QListWidgetItem(icon("options-main"), tr("Main"), lstView); itemMain->setTextAlignment(Qt::AlignHCenter); itemMain->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); itemMain->setSizeHint(sizeItem); QListWidgetItem *itemView = new QListWidgetItem(icon("options-view"), tr("View"), lstView); itemView->setTextAlignment(Qt::AlignHCenter); itemView->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); itemView->setSizeHint(sizeItem); QListWidgetItem *itemSolver = new QListWidgetItem(icon("options-solver"), tr("Solver"), lstView); itemSolver->setTextAlignment(Qt::AlignHCenter); itemSolver->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); itemSolver->setSizeHint(sizeItem); QListWidgetItem *itemColors = new QListWidgetItem(icon("options-colors"), tr("Colors"), lstView); itemColors->setTextAlignment(Qt::AlignHCenter); itemColors->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); itemColors->setSizeHint(sizeItem); QListWidgetItem *itemGlobalScript = new QListWidgetItem(icon("options-python"), tr("Python"), lstView); itemGlobalScript->setTextAlignment(Qt::AlignHCenter); itemGlobalScript->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); itemGlobalScript->setSizeHint(sizeItem); pages->addWidget(panMain); pages->addWidget(panView); pages->addWidget(panSolver); pages->addWidget(panColors); pages->addWidget(panGlobalScriptWidget); QHBoxLayout *layoutHorizontal = new QHBoxLayout(); layoutHorizontal->addWidget(lstView); layoutHorizontal->addWidget(pages); // dialog buttons QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(buttonBox, SIGNAL(accepted()), this, SLOT(doAccept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(doReject())); QVBoxLayout *layout = new QVBoxLayout(); layout->addLayout(layoutHorizontal); // layout->addStretch(); layout->addWidget(buttonBox); setLayout(layout); }
void shutDownSchedulingServer() { logMessage("Shutting down JVM...\n"); shutDownJVM(); }
void CLog::error(const string & logName, const string & message) { logMessage(LOG_ERROR_LEVEL, logName, message); }