/** * Parent signal handler */ void PSigHander(int signo) { if (SIGHUP == signo) return; _DBG("[Signal] Parent Received signal %d", signo); flag = 1; closeMessage(); kill(child_pid, SIGKILL); }
NMEAMessageSEA::NMEAMessageSEA(const uint8_t *seaTalkMessage, uint8_t seaTalkMessageLength) { memcpy(&_seaTalkMessage, seaTalkMessage, seaTalkMessageLength); _seaTalkMessageLength = seaTalkMessageLength; sprintf(_message, "$STSEA,"); uint8_t headerLength = 7; // Convert binary to ascii hex for (int i = 0; i < seaTalkMessageLength; i++) { sprintf(&(_message[headerLength + 2 * i]), "%02X", seaTalkMessage[i]); } closeMessage(_message); }
MainTab::MainTab(QWidget *parent) : QTabWidget(parent), weightModel(new WeightModel(this)), cylindersModel(CylindersModel::instance()), editMode(NONE) { ui.setupUi(this); memset(&multiEditEquipmentPlaceholder, 0, sizeof(multiEditEquipmentPlaceholder)); ui.cylinders->setModel(cylindersModel); ui.weights->setModel(weightModel); closeMessage(); QAction *action = new QAction(tr("Save"), this); connect(action, SIGNAL(triggered(bool)), this, SLOT(acceptChanges())); addMessageAction(action); action = new QAction(tr("Cancel"), this); connect(action, SIGNAL(triggered(bool)), this, SLOT(rejectChanges())); addMessageAction(action); if (qApp->style()->objectName() == "oxygen") setDocumentMode(true); else setDocumentMode(false); // we start out with the fields read-only; once things are // filled from a dive, they are made writeable setEnabled(false); ui.location->installEventFilter(this); ui.coordinates->installEventFilter(this); ui.divemaster->installEventFilter(this); ui.buddy->installEventFilter(this); ui.suit->installEventFilter(this); ui.notes->viewport()->installEventFilter(this); ui.rating->installEventFilter(this); ui.visibility->installEventFilter(this); ui.airtemp->installEventFilter(this); ui.watertemp->installEventFilter(this); ui.dateTimeEdit->installEventFilter(this); ui.tagWidget->installEventFilter(this); QList<QObject *> statisticsTabWidgets = ui.statisticsTab->children(); Q_FOREACH(QObject* obj, statisticsTabWidgets) { QLabel* label = qobject_cast<QLabel *>(obj); if (label) label->setAlignment(Qt::AlignHCenter); }
NMEAMessageDBT::NMEAMessageDBT(float depth) : BaseNMEAMessage() { sprintf(_message, "$STDBT,%.1f,f,,M,,F", depth); closeMessage(_message); }
NMEAMessageWind::NMEAMessageWind(float windAngle, float windSpeed) : BaseNMEAMessage() { sprintf(_message, "$WIMWV,%.1f,R,%.1f,N,A", windAngle, windSpeed); closeMessage(_message); }
NMEAMessageHDM::NMEAMessageHDM(float heading) : BaseNMEAMessage() { sprintf(_message, "$STHDM,%.1f,M", heading); closeMessage(_message); }
NMEAMessageVHW::NMEAMessageVHW(float knots) : BaseNMEAMessage() { sprintf(_message, "$STVHW,,T,,M,%.1f,N,,K", knots); closeMessage(_message); }
MainTab::MainTab(QWidget *parent) : QTabWidget(parent), weightModel(new WeightModel(this)), cylindersModel(new CylindersModel(this)), editMode(NONE), copyPaste(false), currentTrip(0) { ui.setupUi(this); extraWidgets << new TabDiveInformation(); ui.tabWidget->addTab(extraWidgets.last(), tr("Information")); extraWidgets << new TabDiveStatistics(); ui.tabWidget->addTab(extraWidgets.last(), tr("Statistics")); extraWidgets << new TabDivePhotos(); ui.tabWidget->addTab(extraWidgets.last(), tr("Photos")); extraWidgets << new TabDiveExtraInfo(); ui.tabWidget->addTab(extraWidgets.last(), tr("Extra Info")); ui.dateEdit->setDisplayFormat(prefs.date_format); memset(&displayed_dive, 0, sizeof(displayed_dive)); memset(&displayedTrip, 0, sizeof(displayedTrip)); // This makes sure we only delete the models // after the destructor of the tables, // this is needed to save the column sizes. cylindersModel->setParent(ui.cylinders); weightModel->setParent(ui.weights); ui.cylinders->setModel(cylindersModel); ui.weights->setModel(weightModel); closeMessage(); connect(ui.editDiveSiteButton, SIGNAL(clicked()), MainWindow::instance(), SIGNAL(startDiveSiteEdit())); connect(ui.location, &DiveLocationLineEdit::entered, MapWidget::instance(), &MapWidget::centerOnIndex); connect(ui.location, &DiveLocationLineEdit::currentChanged, MapWidget::instance(), &MapWidget::centerOnIndex); QAction *action = new QAction(tr("Apply changes"), this); connect(action, SIGNAL(triggered(bool)), this, SLOT(acceptChanges())); addMessageAction(action); action = new QAction(tr("Discard changes"), this); connect(action, SIGNAL(triggered(bool)), this, SLOT(rejectChanges())); addMessageAction(action); QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this); connect(closeKey, SIGNAL(activated()), this, SLOT(escDetected())); if (qApp->style()->objectName() == "oxygen") setDocumentMode(true); else setDocumentMode(false); // we start out with the fields read-only; once things are // filled from a dive, they are made writeable setEnabled(false); ui.cylinders->setTitle(tr("Cylinders")); ui.cylinders->setBtnToolTip(tr("Add cylinder")); connect(ui.cylinders, SIGNAL(addButtonClicked()), this, SLOT(addCylinder_clicked())); ui.weights->setTitle(tr("Weights")); ui.weights->setBtnToolTip(tr("Add weight system")); connect(ui.weights, SIGNAL(addButtonClicked()), this, SLOT(addWeight_clicked())); // This needs to be the same order as enum dive_comp_type in dive.h! ui.DiveType->insertItems(0, QStringList() << tr("OC") << tr("CCR") << tr("pSCR") << tr("Freedive")); connect(ui.DiveType, SIGNAL(currentIndexChanged(int)), this, SLOT(divetype_Changed(int))); connect(ui.cylinders->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editCylinderWidget(QModelIndex))); connect(ui.weights->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editWeightWidget(QModelIndex))); ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this)); ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::USE, new TankUseDelegate(this)); ui.weights->view()->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate(this)); ui.cylinders->view()->setColumnHidden(CylindersModel::DEPTH, true); completers.buddy = new QCompleter(&buddyModel, ui.buddy); completers.divemaster = new QCompleter(&diveMasterModel, ui.divemaster); completers.suit = new QCompleter(&suitModel, ui.suit); completers.tags = new QCompleter(&tagModel, ui.tagWidget); completers.buddy->setCaseSensitivity(Qt::CaseInsensitive); completers.divemaster->setCaseSensitivity(Qt::CaseInsensitive); completers.suit->setCaseSensitivity(Qt::CaseInsensitive); completers.tags->setCaseSensitivity(Qt::CaseInsensitive); ui.buddy->setCompleter(completers.buddy); ui.divemaster->setCompleter(completers.divemaster); ui.suit->setCompleter(completers.suit); ui.tagWidget->setCompleter(completers.tags); ui.diveNotesMessage->hide(); ui.depth->hide(); ui.depthLabel->hide(); ui.duration->hide(); ui.durationLabel->hide(); setMinimumHeight(0); setMinimumWidth(0); // Current display of things on Gnome3 looks like shit, so // let`s fix that. if (isGnome3Session()) { QPalette p; p.setColor(QPalette::Window, QColor(Qt::white)); ui.scrollArea->viewport()->setPalette(p); ui.scrollArea_2->viewport()->setPalette(p); // GroupBoxes in Gnome3 looks like I'v drawn them... static const QString gnomeCss( "QGroupBox {" " background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1," " stop: 0 #E0E0E0, stop: 1 #FFFFFF);" " border: 2px solid gray;" " border-radius: 5px;" " margin-top: 1ex;" "}" "QGroupBox::title {" " subcontrol-origin: margin;" " subcontrol-position: top center;" " padding: 0 3px;" " background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1," " stop: 0 #E0E0E0, stop: 1 #FFFFFF);" "}"); Q_FOREACH (QGroupBox *box, findChildren<QGroupBox *>()) { box->setStyleSheet(gnomeCss); } }
/** * Parent watch child status */ int Watching() { pid_t w; int status; openlog("pm_manager", LOG_PID, LOG_LOCAL0); do { child_pid = fork(); if (child_pid == -1) { exit(EXIT_FAILURE); } if (child_pid == 0) { /** * Child process */ signal(SIGINT, CSigHander); signal(SIGTERM, CSigHander); signal(SIGPIPE, SIG_IGN); return 0; } /** * Parent process */ signal(SIGINT, PSigHander); signal(SIGTERM, PSigHander); signal(SIGHUP, PSigHander); signal(SIGPIPE, SIG_IGN); w = waitpid(child_pid, &status, WUNTRACED | WCONTINUED); closeMessage(); if (w == -1) { perror("waitpid"); exit(EXIT_FAILURE); } if (WIFEXITED(status)) { _DBG("[Process] child exited, status=%d\n", WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { _DBG("[Process] child killed by signal %d\n", WTERMSIG(status)); } else if (WIFSTOPPED(status)) { _DBG("[Process] child stopped by signal %d\n", WSTOPSIG(status)); } else if (WIFCONTINUED(status)) { _DBG("[Process] continued\n"); } sleep(3); } while (SIGTERM != WTERMSIG(status) && !flag); closelog(); exit(EXIT_SUCCESS); return 1; }
void ConnectionManager::closeConnection( ClientConnectionPtr connection ) { std::set< std::string > gameToCloseList; // find all the game related to this connection for ( GameMap::iterator itGame = games.begin(); itGame != games.end(); ) { // get the current game Game* game = itGame->second; // check the contains status if ( game->contains( connection ) == true ) { // remove the connection from the game if ( game->remove( connection ) == true ) { // if the connection was the provider, close the game gameToCloseList.insert( game->getId() ); delete game; itGame = games.erase( itGame ); continue; } else if ( game->getClients().size() == 0 ) { // if there is no more players gameToCloseList.insert( game->getId() ); delete game; itGame = games.erase( itGame ); continue; } } // go to the next game itGame++; } // check if there is some game to close if ( gameToCloseList.size() > 0 ) { // create the close message std::string closeMessage( GAME_MESSAGE + " " + CLOSE_MESSAGE + " " ); size_t i = 0; for ( std::set< std::string >::const_iterator it = gameToCloseList.begin(); it != gameToCloseList.end(); it++ ) { closeMessage += *it; if ( i++ < gameToCloseList.size() - 1 ) { closeMessage += "|"; } } closeMessage += " Client close its connection and end the game" ; // and send it to everyone for ( ClientList::const_iterator itClient = connections.begin(); itClient != connections.end(); itClient++ ) { (*itClient)->sendMessage( closeMessage ); } } // remove the connection from the client aggregat for ( ClientAggregat::iterator itAgg = consumerByGame.begin(); itAgg != consumerByGame.end(); ) { for ( ClientList::iterator itClient = itAgg->second.begin(); itClient != itAgg->second.end(); itClient++ ) { // check the client if ( *itClient == connection ) { // remove it itAgg->second.erase( itClient ); // and break as there is only one occurence of client per game break; } } // check if there is still some client for the game if ( itAgg->second.size() == 0 ) { itAgg = consumerByGame.erase( itAgg ); continue; } // and next game itAgg++; } // remove the connection from the provider aggregat for ( ClientAggregat::iterator itAgg = providerByGame.begin(); itAgg != providerByGame.end(); ) { for ( ClientList::iterator itClient = itAgg->second.begin(); itClient != itAgg->second.end(); itClient++ ) { // check the client if ( *itClient == connection ) { // remove it itAgg->second.erase( itClient ); // and break as there is only one occurence of client per game break; } } // check if there is still some client for the game if ( itAgg->second.size() == 0 ) { itAgg = providerByGame.erase( itAgg ); continue; } // and next game itAgg++; } // remove the connections from the list connections.erase( connection ); dumpCurrentState(); }