void ServerConfigDialog::on_m_pListHotkeys_itemSelectionChanged() { bool itemsSelected = !m_pListHotkeys->selectedItems().isEmpty(); m_pButtonEditHotkey->setEnabled(itemsSelected); m_pButtonRemoveHotkey->setEnabled(itemsSelected); m_pButtonNewAction->setEnabled(itemsSelected); if (itemsSelected && serverConfig().hotkeys().size() > 0) { m_pListActions->clear(); int idx = m_pListHotkeys->row(m_pListHotkeys->selectedItems()[0]); // There's a bug somewhere around here: We get idx == 1 right after we deleted the next to last item, so idx can // only possibly be 0. GDB shows we got called indirectly from the delete line in // on_m_pButtonRemoveHotkey_clicked() above, but the delete is of course necessary and seems correct. // The while() is a generalized workaround for all that and shouldn't be required. while (idx >= 0 && idx >= serverConfig().hotkeys().size()) idx--; Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size()); const Hotkey& hotkey = serverConfig().hotkeys()[idx]; foreach(const Action& action, hotkey.actions()) m_pListActions->addItem(action.text()); }
void ServerConfigDialog::on_m_pButtonRemoveHotkey_clicked() { int idx = m_pListHotkeys->currentRow(); Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size()); serverConfig().hotkeys().removeAt(idx); m_pListActions->clear(); delete m_pListHotkeys->item(idx); }
void ServerConfigDialog::on_m_pButtonEditHotkey_clicked() { int idx = m_pListHotkeys->currentRow(); Q_ASSERT(idx >= 0 && idx < serverConfig().hotkeys().size()); Hotkey& hotkey = serverConfig().hotkeys()[idx]; HotkeyDialog dlg(this, hotkey); if (dlg.exec() == QDialog::Accepted) m_pListHotkeys->currentItem()->setText(hotkey.text()); }
QString MainWindow::configFilename() { QString filename; if (m_pRadioInternalConfig->isChecked()) { // TODO: no need to use a temporary file, since we need it to // be permenant (since it'll be used for Windows services, etc). m_pTempConfigFile = new QTemporaryFile(); if (!m_pTempConfigFile->open()) { QMessageBox::critical(this, tr("Cannot write configuration file"), tr("The temporary configuration file required to start synergy can not be written.")); return false; } serverConfig().save(*m_pTempConfigFile); filename = m_pTempConfigFile->fileName(); m_pTempConfigFile->close(); } else { if (!QFile::exists(m_pLineEditConfigFile->text())) { if (QMessageBox::warning(this, tr("Configuration filename invalid"), tr("You have not filled in a valid configuration file for the synergy server. " "Do you want to browse for the configuration file now?"), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes || !on_m_pButtonBrowseConfigFile_clicked()) return false; } filename = m_pLineEditConfigFile->text(); } return filename; }
bool WMTSConfig::initConfigData(const QString& fileName) { if (!QFile::exists(fileName)) { return false; } /// 使用ini文件加载方式, QSettings serverConfig(fileName, QSettings::IniFormat); serverConfig.setIniCodec(QTextCodec::codecForName("UTF-8")); // 加载主要的配置项 serverConfig.beginGroup(""); m_nThreadCount = serverConfig.value("ThreadCount", 4).toInt(); m_nPort = serverConfig.value("Port", "9999").toInt(); m_strRepositoryDir = serverConfig.value("ServerDir", ".\\").toString(); m_nMaxOneLayerCacheMb = serverConfig.value("MemLimit", "1024").toInt(); m_nMemStrategy = serverConfig.value("MemStrategy", "0").toUInt(); m_strPreLoadLayerName = serverConfig.value("LAYER", "").toString(); m_nBeginLv = serverConfig.value("LvBegin", 0).toInt(); m_nEndLv = serverConfig.value("LvEnd", 0).toInt(); m_nFileSysType = serverConfig.value("FileSysType").toInt(); m_nHdfsClient = serverConfig.value("hdfsClient").toUInt(); m_strHdfsServer= serverConfig.value("hdfsServer").toString(); m_nHdfsNameNodePort = serverConfig.value("hdfsNameNodePort").toInt(); return true; }
void ServerConfigDialog::on_m_pButtonNewHotkey_clicked() { Hotkey hotkey; HotkeyDialog dlg(this, hotkey); if (dlg.exec() == QDialog::Accepted) { serverConfig().hotkeys().append(hotkey); m_pListHotkeys->addItem(hotkey.text()); } }
void readServerConfig(string& serverIPAddr) { string serverConfigFile = "serverConfig.txt"; checkFileExistence(serverConfigFile); ifstream serverConfig(serverConfigFile.c_str()); // read server's IP address getline(serverConfig,serverIPAddr); serverConfig.close(); }
bool MainWindow::on_m_pActionSave_triggered() { QString fileName = QFileDialog::getSaveFileName(this, tr("Save configuration as...")); if (!fileName.isEmpty() && !serverConfig().save(fileName)) { QMessageBox::warning(this, tr("Save failed"), tr("Could not save configuration to file.")); return true; } return false; }
bool MainWindow::serverArgs(QStringList& args, QString& app) { app = appConfig().synergys(); if (!QFile::exists(app)) { if (QMessageBox::warning(this, tr("Synergy server not found"), tr("The executable for the synergy server does not exist. Do you want to browse for the synergy server now?"), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return false; app = SettingsDialog::browseForSynergys(this, appConfig().synergyProgramDir(), appConfig().synergysName()); if (app.isEmpty()) return false; appConfig().setSynergys(app); } if (m_pRadioInternalConfig->isChecked()) { m_pTempConfigFile = new QTemporaryFile(); if (!m_pTempConfigFile->open()) { QMessageBox::critical(this, tr("Cannot write configuration file"), tr("The temporary configuration file required to start synergy can not be written.")); return false; } serverConfig().save(*m_pTempConfigFile); args << "-c" << m_pTempConfigFile->fileName(); m_pTempConfigFile->close(); // the file will be removed from disk when the object is deleted; this happens in stopSynergy() } else { if (!QFile::exists(m_pLineEditConfigFile->text())) { if (QMessageBox::warning(this, tr("Configuration filename invalid"), tr("You have not filled in a valid configuration file for the synergy server. " "Do you want to browse for the configuration file now?"), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes || !on_m_pButtonBrowseConfigFile_clicked()) return false; } args << "-c" << m_pLineEditConfigFile->text(); } args << "--address" << (!appConfig().interface().isEmpty() ? appConfig().interface() : "") + ":" + QString::number(appConfig().port()); return true; }
ActionDialog::ActionDialog(QWidget* parent, ServerConfig& config, Hotkey& hotkey, Action& action) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), Ui::ActionDialogBase(), m_ServerConfig(config), m_Hotkey(hotkey), m_Action(action), m_pButtonGroupType(new QButtonGroup(this)) { setupUi(this); // work around Qt Designer's lack of a QButtonGroup; we need it to get // at the button id of the checked radio button QRadioButton* const typeButtons[] = { m_pRadioPress, m_pRadioRelease, m_pRadioPressAndRelease, m_pRadioSwitchToScreen, m_pRadioSwitchInDirection, m_pRadioLockCursorToScreen }; for (unsigned int i = 0; i < sizeof(typeButtons) / sizeof(typeButtons[0]); i++) m_pButtonGroupType->addButton(typeButtons[i], i); m_pKeySequenceWidgetHotkey->setText(m_Action.keySequence().toString()); m_pKeySequenceWidgetHotkey->setKeySequence(m_Action.keySequence()); m_pButtonGroupType->button(m_Action.type())->setChecked(true); m_pComboSwitchInDirection->setCurrentIndex(m_Action.switchDirection()); m_pComboLockCursorToScreen->setCurrentIndex(m_Action.lockCursorMode()); if (m_Action.activeOnRelease()) m_pRadioHotkeyReleased->setChecked(true); else m_pRadioHotkeyPressed->setChecked(true); m_pGroupBoxScreens->setChecked(m_Action.haveScreens()); int idx = 0; foreach(const Screen& screen, serverConfig().screens()) if (!screen.isNull()) { QListWidgetItem *pListItem = new QListWidgetItem(screen.name()); m_pListScreens->addItem(pListItem); if (m_Action.typeScreenNames().indexOf(screen.name()) != -1) m_pListScreens->setCurrentItem(pListItem); m_pComboSwitchToScreen->addItem(screen.name()); if (screen.name() == m_Action.switchScreenName()) m_pComboSwitchToScreen->setCurrentIndex(idx); idx++; } }
void MainWindow::on_m_pButtonConfigureServer_clicked() { ServerConfigDialog dlg(this, serverConfig(), appConfig().screenName()); dlg.exec(); }
void ServerConfigDialog::accept() { serverConfig().haveHeartbeat(m_pCheckBoxHeartbeat->isChecked()); serverConfig().setHeartbeat(m_pSpinBoxHeartbeat->value()); serverConfig().setRelativeMouseMoves(m_pCheckBoxRelativeMouseMoves->isChecked()); serverConfig().setScreenSaverSync(m_pCheckBoxScreenSaverSync->isChecked()); serverConfig().setWin32KeepForeground(m_pCheckBoxWin32KeepForeground->isChecked()); serverConfig().haveSwitchDelay(m_pCheckBoxSwitchDelay->isChecked()); serverConfig().setSwitchDelay(m_pSpinBoxSwitchDelay->value()); serverConfig().haveSwitchDoubleTap(m_pCheckBoxSwitchDoubleTap->isChecked()); serverConfig().setSwitchDoubleTap(m_pSpinBoxSwitchDoubleTap->value()); serverConfig().setSwitchCorner(BaseConfig::TopLeft, m_pCheckBoxCornerTopLeft->isChecked()); serverConfig().setSwitchCorner(BaseConfig::TopRight, m_pCheckBoxCornerTopRight->isChecked()); serverConfig().setSwitchCorner(BaseConfig::BottomLeft, m_pCheckBoxCornerBottomLeft->isChecked()); serverConfig().setSwitchCorner(BaseConfig::BottomRight, m_pCheckBoxCornerBottomRight->isChecked()); serverConfig().setSwitchCornerSize(m_pSpinBoxSwitchCornerSize->value()); serverConfig().setIgnoreAutoConnectClient(m_pCheckBoxIgnoreAutoConnectClient->isChecked()); // now that the dialog has been accepted, copy the new server config to the original one, // which is a reference to the one in MainWindow. setOrigServerConfig(serverConfig()); QDialog::accept(); }
ServerConfigDialog::ServerConfigDialog(QWidget* parent, ServerConfig& config, const QString& defaultScreenName) : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), Ui::ServerConfigDialogBase(), m_OrigServerConfig(config), m_ServerConfig(config), m_ScreenSetupModel(serverConfig().screens(), serverConfig().numColumns(), serverConfig().numRows()), m_Message("") { setupUi(this); m_pCheckBoxHeartbeat->setChecked(serverConfig().hasHeartbeat()); m_pSpinBoxHeartbeat->setValue(serverConfig().heartbeat()); m_pCheckBoxRelativeMouseMoves->setChecked(serverConfig().relativeMouseMoves()); m_pCheckBoxScreenSaverSync->setChecked(serverConfig().screenSaverSync()); m_pCheckBoxWin32KeepForeground->setChecked(serverConfig().win32KeepForeground()); m_pCheckBoxSwitchDelay->setChecked(serverConfig().hasSwitchDelay()); m_pSpinBoxSwitchDelay->setValue(serverConfig().switchDelay()); m_pCheckBoxSwitchDoubleTap->setChecked(serverConfig().hasSwitchDoubleTap()); m_pSpinBoxSwitchDoubleTap->setValue(serverConfig().switchDoubleTap()); m_pCheckBoxCornerTopLeft->setChecked(serverConfig().switchCorner(BaseConfig::TopLeft)); m_pCheckBoxCornerTopRight->setChecked(serverConfig().switchCorner(BaseConfig::TopRight)); m_pCheckBoxCornerBottomLeft->setChecked(serverConfig().switchCorner(BaseConfig::BottomLeft)); m_pCheckBoxCornerBottomRight->setChecked(serverConfig().switchCorner(BaseConfig::BottomRight)); m_pSpinBoxSwitchCornerSize->setValue(serverConfig().switchCornerSize()); m_pCheckBoxIgnoreAutoConnectClient->setChecked(serverConfig().ignoreAutoConnectClient()); foreach(const Hotkey& hotkey, serverConfig().hotkeys()) m_pListHotkeys->addItem(hotkey.text()); m_pScreenSetupView->setModel(&m_ScreenSetupModel); if (serverConfig().numScreens() == 0) model().screen(serverConfig().numColumns() / 2, serverConfig().numRows() / 2) = Screen(defaultScreenName); }
int main (int argc, char *argv[]) { #ifdef __linux__ if(!mlockall(MCL_CURRENT | MCL_FUTURE)) WARN("Process " << argv[0] << "could not be locked to RAM"); #endif #ifndef _WIN32 installCrashHandler(argv[0]); #endif // Bug - testing not necessary. testDataFiles also tries to open the first // argv, which is the name of exec file //if(testDataFiles(argc, argv)==false) { //std::cerr << "[error] at least one data file name seems to be bogus!" << std::endl; //exit(-1); //} try { std::cout << "[server] starting up engines, saved at " << __TIMESTAMP__ << std::endl; #ifndef _WIN32 int sig = 0; sigset_t new_mask; sigset_t old_mask; sigfillset(&new_mask); pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); #endif ServerConfiguration serverConfig("server.ini"); Server * s = ServerFactory::CreateServer(serverConfig); RequestHandler & h = s->GetRequestHandlerPtr(); QueryObjectsStorage * objects = new QueryObjectsStorage(serverConfig.GetParameter("hsgrData"), serverConfig.GetParameter("ramIndex"), serverConfig.GetParameter("fileIndex"), serverConfig.GetParameter("nodesData"), serverConfig.GetParameter("edgesData"), serverConfig.GetParameter("namesData"), serverConfig.GetParameter("timestamp") ); h.RegisterPlugin(new HelloWorldPlugin()); h.RegisterPlugin(new LocatePlugin(objects)); h.RegisterPlugin(new NearestPlugin(objects)); h.RegisterPlugin(new TimestampPlugin(objects)); h.RegisterPlugin(new ViaRoutePlugin(objects)); boost::thread t(boost::bind(&Server::Run, s)); #ifndef _WIN32 sigset_t wait_mask; pthread_sigmask(SIG_SETMASK, &old_mask, 0); sigemptyset(&wait_mask); sigaddset(&wait_mask, SIGINT); sigaddset(&wait_mask, SIGQUIT); sigaddset(&wait_mask, SIGTERM); pthread_sigmask(SIG_BLOCK, &wait_mask, 0); std::cout << "[server] running and waiting for requests" << std::endl; sigwait(&wait_mask, &sig); #else // Set console control handler to allow server to be stopped. console_ctrl_function = boost::bind(&Server::Stop, s); SetConsoleCtrlHandler(console_ctrl_handler, TRUE); std::cout << "[server] running and waiting for requests" << std::endl; s->Run(); #endif std::cout << std::endl << "[server] shutting down" << std::endl; s->Stop(); t.join(); delete s; delete objects; } catch (std::exception& e) { std::cerr << "[fatal error] exception: " << e.what() << std::endl; } #ifdef __linux__ munlockall(); #endif return 0; }
int main (int argc, char * argv[]) { #ifdef __linux__ if(!mlockall(MCL_CURRENT | MCL_FUTURE)) WARN("Process " << argv[0] << "could not be locked to RAM"); #endif #ifdef __linux__ installCrashHandler(argv[0]); #endif // Bug - testing not necessary. testDataFiles also tries to open the first // argv, which is the name of exec file //if(testDataFiles(argc, argv)==false) { //std::cerr << "[error] at least one data file name seems to be bogus!" << std::endl; //exit(-1); //} try { //std::cout << "fingerprint: " << UUID::GetInstance().GetUUID() << std::endl; std::cout << "starting up engines, compiled at " << __DATE__ << ", " __TIME__ << std::endl; #ifndef _WIN32 int sig = 0; sigset_t new_mask; sigset_t old_mask; sigfillset(&new_mask); pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask); #endif BaseConfiguration serverConfig((argc > 1 ? argv[1] : "server.ini")); OSRM routing_machine((argc > 1 ? argv[1] : "server.ini")); Server * s = ServerFactory::CreateServer(serverConfig); s->GetRequestHandlerPtr().RegisterRoutingMachine(&routing_machine); boost::thread t(boost::bind(&Server::Run, s)); #ifndef _WIN32 sigset_t wait_mask; pthread_sigmask(SIG_SETMASK, &old_mask, 0); sigemptyset(&wait_mask); sigaddset(&wait_mask, SIGINT); sigaddset(&wait_mask, SIGQUIT); sigaddset(&wait_mask, SIGTERM); pthread_sigmask(SIG_BLOCK, &wait_mask, 0); std::cout << "[server] running and waiting for requests" << std::endl; sigwait(&wait_mask, &sig); #else // Set console control handler to allow server to be stopped. console_ctrl_function = boost::bind(&Server::Stop, s); SetConsoleCtrlHandler(console_ctrl_handler, TRUE); std::cout << "[server] running and waiting for requests" << std::endl; s->Run(); #endif std::cout << "[server] initiating shutdown" << std::endl; s->Stop(); std::cout << "[server] stopping threads" << std::endl; if(!t.timed_join(boost::posix_time::seconds(2))) { // INFO("Threads did not finish within 2 seconds. Hard abort!"); } std::cout << "[server] freeing objects" << std::endl; delete s; std::cout << "[server] shutdown completed" << std::endl; } catch (std::exception& e) { std::cerr << "[fatal error] exception: " << e.what() << std::endl; } #ifdef __linux__ munlockall(); #endif return 0; }