예제 #1
0
void Client::endLogging()
{
    if (status != Logout)
        changeStatus(Logout);

    endSession();
}
예제 #2
0
int MainWindow::endSession()
{
    this->processController.stop();
    this->show();
    trayIcon->setVisible(false);
    trayIcon->hide();

    sessionTimer->stop();
    controlTimer->stop();
    refreshTimer->stop();
    disconnect(controlTimer, SIGNAL(timeout()), this, SLOT(controlStab()));
    disconnect(refreshTimer, SIGNAL(timeout()), this, SLOT(refreshTrayIconTooltip()));
    disconnect(sessionTimer, SIGNAL(timeout()), this, SLOT(endSession()));

    string name = this->processController.getActiveModeName();
    int progress = this->processController.getModeProgress(name);
    this->processController.setSessionMode(name);
    endSessionDlg = new EndSessionDialog(name, progress, this);
    connect(endSessionDlg, SIGNAL(progressChanged(string&, int)), this, SLOT(editProgress(string&, int)));
    endSessionDlg->exec();
    delete endSessionDlg;
    endSessionDlg = NULL;
    this->fillModeModel();

    return 0;
}
예제 #3
0
void Server::removeClient(Server_ProtocolHandler *client)
{
    QWriteLocker locker(&clientsLock);
    clients.removeAt(clients.indexOf(client));
    ServerInfo_User *data = client->getUserInfo();
    if (data) {
        Event_UserLeft event;
        event.set_name(data->name());
        SessionEvent *se = Server_ProtocolHandler::prepareSessionEvent(event);
        for (int i = 0; i < clients.size(); ++i)
            if (clients[i]->getAcceptsUserListChanges())
                clients[i]->sendProtocolItem(*se);
        sendIsl_SessionEvent(*se);
        delete se;

        users.remove(QString::fromStdString(data->name()));
        qDebug() << "Server::removeClient: name=" << QString::fromStdString(data->name());

        if (data->has_session_id()) {
            const qint64 sessionId = data->session_id();
            usersBySessionId.remove(sessionId);
            emit endSession(sessionId);
            qDebug() << "closed session id:" << sessionId;
        }
    }
    qDebug() << "Server::removeClient: removed" << (void *) client << ";" << clients.size() << "clients; " << users.size() << "users left";
}
예제 #4
0
void DebuggerDBG::reloadConfiguration()
{
  endSession();
  m_configuration->setLocalBaseDir(Settings::localBaseDir());
  m_configuration->setServerBaseDir(Settings::serverBaseDir());
  m_configuration->setListenPort(Settings::listenPort());
  m_configuration->setServerHost(Settings::serverHost());
}
MediaPlayerPrivateMediaFoundation::~MediaPlayerPrivateMediaFoundation()
{
    notifyDeleted();
    destroyVideoWindow();
    endSession();
    cancelCallOnMainThread(onTopologySetCallback, this);
    cancelCallOnMainThread(onCreatedMediaSourceCallback, this);
}
예제 #6
0
void SessionInfo::Functions::end::call(JSContext* cx, JS::CallArgs args) {
    auto holder = getHolder(args);
    invariant(holder);

    endSession(holder);

    args.rval().setUndefined();
}
예제 #7
0
void SVT_Fcml::endAllSessions()
{
    QMap<QString,QString>::ConstIterator i=mSession.constBegin();
    while(i != mSession.constEnd())
    {
        endSession(i.key(),i.value());
        i++;
    }
    mSession.clear();
}
예제 #8
0
void AFPSGPlayerController::clientEndSession_Implementation() const
{
	GEngine->AddOnScreenDebugMessage(-1, 40.0f, FColor::Cyan, TEXT("AFPSGPlayerController::clientEndSession_Implementation"));

	AFPSGPlayerState* myPlayerState = Cast<AFPSGPlayerState>(PlayerState);

	if (myPlayerState != NULL)
	{
		//End the session
		endSession(myPlayerState->SessionName);
	}
}
예제 #9
0
void
disconnectBrailleResource (
  BrailleDisplay *brl,
  BrailleSessionEnder *endSession
) {
  if (brl->gioEndpoint) {
    if (endSession) endSession(brl);
    drainBrailleOutput(brl, 0);
    gioDisconnectResource(brl->gioEndpoint);
    brl->gioEndpoint = NULL;
  }
}
        void SessionLocalStorage::endSession() {
            auto tid = getThreadId();

            _mutex.lock();

            auto ntid = _threadSession[tid];
            _threadSession.erase(tid);

            _mutex.unlock();

            endSession(ntid);
        }
예제 #11
0
void WbDlg::setSelfDestruct(int minutes) {
	if(minutes <= 0) {
		if(selfDestruct_) {
			delete selfDestruct_;
			selfDestruct_ = 0;
		}
		return;
	}

	if(!selfDestruct_) {
		selfDestruct_ = new QTimer(this);
		connect(selfDestruct_, SIGNAL(timeout()), SLOT(endSession()));
	}

	selfDestruct_->start(minutes * 60000);
}
예제 #12
0
/*--------------------------------------------------------------------*//*!
 * \brief Destroy a logger instance
 * \param a	qpTestLog instance
 *//*--------------------------------------------------------------------*/
void qpTestLog_destroy (qpTestLog* log)
{
	DE_ASSERT(log);

	if (log->isSessionOpen)
		endSession(log);

	if (log->writer)
		qpXmlWriter_destroy(log->writer);

	if (log->outputFile)
		fclose(log->outputFile);

	if (log->lock)
		deMutex_destroy(log->lock);

	deFree(log);
}
void GnomeSessionClient::slotRegisterClientFinished(QDBusPendingCallWatcher* watcher)
{
    QDBusPendingReply<QDBusObjectPath> reply = *watcher;
    watcher->deleteLater();
    if (!reply.isValid()) {
        UQ_WARNING << "Failed to register with GnomeSession:" << reply.error().message();
        return;
    }

    d->m_waitingForEndSession = true;
    QDBusConnection bus = QDBusConnection::sessionBus();
    d->m_clientPath = reply.value().path();

    bus.connect(SM_DBUS_SERVICE, d->m_clientPath, SM_CLIENT_DBUS_INTERFACE,
        "Stop", "", this, SLOT(stop()));
    bus.connect(SM_DBUS_SERVICE, d->m_clientPath, SM_CLIENT_DBUS_INTERFACE,
        "QueryEndSession", "u", this, SLOT(queryEndSession()));
    bus.connect(SM_DBUS_SERVICE, d->m_clientPath, SM_CLIENT_DBUS_INTERFACE,
        "EndSession", "u", this, SLOT(endSession()));
}
예제 #14
0
void WbDlg::closeEvent(QCloseEvent *e) {
	e->accept();
	if(keepOpen_) {
		int n = QMessageBox::information(this, tr("Warning"), tr("A new whiteboard message was just received.\nDo you still want to close the window?"), tr("&Yes"), tr("&No"));
		if(n != 0) {
			e->ignore();
			return;
		}
	}

	// destroy the dialog if delChats is dcClose
	if(PsiOptions::instance()->getOption("options.ui.chat.delete-contents-after").toString() == "instant")
		endSession();
	else {
		if(PsiOptions::instance()->getOption("options.ui.chat.delete-contents-after").toString() == "hour")
			setSelfDestruct(60);
		else if(PsiOptions::instance()->getOption("options.ui.chat.delete-contents-after").toString() == "day")
			setSelfDestruct(60 * 24);
	}
}
예제 #15
0
void SessionInfo::finalize(js::FreeOp* fop, JSObject* obj) {
    auto holder = getHolder(obj);

    if (holder) {
        const auto lsid = holder->lsid;

        try {
            endSession(holder);
        } catch (...) {
            auto status = exceptionToStatus();

            try {
                LOG(0) << "Failed to end session " << lsid << " due to " << status;
            } catch (...) {
                // This is here in case logging fails.
            }
        }

        getScope(fop)->trackedDelete(holder);
    }
}
예제 #16
0
void QutimOtrClosure::setPolicy(int pol)
{
    QSettings s(QSettings::defaultFormat(), QSettings::UserScope, "qutim/"+m_pluginSystem->getProfileDir().dirName(), "otr");
    if (pol!=s.value(m_item.m_protocol_name+"/"+m_item.m_account_name+"/"+m_item.m_item_name,-1).toInt())
        emit endSession(true);
    switch(pol){
    case OTRL_POLICY_NEVER:
        m_otr = m_otr_none;
        break;
    case OTRL_POLICY_MANUAL:
        m_otr = m_otr_manual;
        break;
    case OTRL_POLICY_OPPORTUNISTIC:
        m_otr = m_otr_auto;
        break;
    case OTRL_POLICY_REQUIRE_ENCRYPTION:
        m_otr = m_otr_req;
        break;
    default:
        m_otr = m_otr_system;
        break;
    }
    s.setValue(m_item.m_protocol_name+"/"+m_item.m_account_name+"/"+m_item.m_item_name,pol);
}
MediaPlayerPrivateMediaFoundation::~MediaPlayerPrivateMediaFoundation()
{
    notifyDeleted();
    destroyVideoWindow();
    endSession();
}
예제 #18
0
WbDlg::WbDlg(SxeSession* session, PsiAccount* pa) {
	groupChat_ = session->groupChat();
	pending_ = 0;
	keepOpen_ = false;
	allowEdits_ = true;

	selfDestruct_ = 0;
	setAttribute(Qt::WA_DeleteOnClose, false); // we want deferred endSession call and delete from manager

	setWindowTitle(CAP(tr("Whiteboard (%1)").arg(pa->jid().bare())));
	QVBoxLayout *vb1 = new QVBoxLayout(this);

	// first row
	le_jid_ = new QLineEdit(this);
	le_jid_->setReadOnly(true);
	le_jid_->setFocusPolicy(Qt::NoFocus);
	le_jid_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
	lb_ident_ = new AccountLabel(this);
	lb_ident_->setAccount(pa);
	lb_ident_->setShowJid(false);
	lb_ident_->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
	QHBoxLayout *hb1 = new QHBoxLayout();
	hb1->addWidget(le_jid_);
	hb1->addWidget(lb_ident_);
	vb1->addLayout(hb1);

	// mid area
	wbWidget_ = new WbWidget(session, this);
	wbWidget_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
	vb1->addWidget(wbWidget_);

	// Bottom (tool) area
	act_save_ = new IconAction(tr("Save session"), "psi/saveBoard", tr("Save the contents of the whiteboard"), 0, this );
	act_geometry_ = new IconAction(tr("Change the geometry"), "psi/whiteboard", tr("Change the geometry"), 0, this );
	act_clear_ = new IconAction(tr("End session"), "psi/clearChat", tr("Clear the whiteboard"), 0, this );
	act_end_ = new IconAction(tr("End session"), "psi/closetab", tr("End session"), 0, this );

	// Black is the default color
	QPixmap pixmap(16, 16);
	pixmap.fill(QColor(Qt::black));
	act_color_ = new QAction(QIcon(pixmap), tr("Stroke color"), this);
	pixmap.fill(QColor(Qt::lightGray));
	act_fill_ = new IconAction(tr("Fill color"), "psi/select", tr("Fill color"),0, this, 0, true);
	act_fill_->setIcon(QIcon(pixmap));
	act_fill_->setChecked(false);

	act_widths_ = new IconAction(tr("Stroke width" ), "psi/drawPaths", tr("Stroke width"), 0, this );
	act_modes_ = new IconAction(tr("Edit mode" ), "psi/select", tr("Edit mode"), 0, this );
	group_widths_ = new QActionGroup(this);
	group_modes_ = new QActionGroup(this);

	connect(act_color_, SIGNAL(triggered()), SLOT(setStrokeColor()));
	connect(act_fill_, SIGNAL(triggered(bool)), SLOT(setFillColor(bool)));
	connect(group_widths_, SIGNAL(triggered(QAction *)), SLOT(setStrokeWidth(QAction *)));
	connect(group_modes_, SIGNAL(triggered(QAction *)), SLOT(setMode(QAction *)));
	connect(act_save_, SIGNAL(triggered()), SLOT(save()));
	connect(act_geometry_, SIGNAL(triggered()), SLOT(setGeometry()));
	connect(act_clear_, SIGNAL(triggered()), wbWidget_, SLOT(clear()));
	connect(act_end_, SIGNAL(triggered()), SLOT(endSession()));

	pixmap = QPixmap(2, 2);
	pixmap.fill(QColor(Qt::black));
	QAction* widthaction = new QAction(QIcon(pixmap), tr("Thin stroke"), group_widths_);
	widthaction->setData(QVariant(1));
	widthaction->setCheckable(true);
	widthaction->trigger();
	pixmap = QPixmap(6, 6);
	pixmap.fill(QColor(Qt::black));
	widthaction = new QAction(QIcon(pixmap), tr("Medium stroke"), group_widths_);
	widthaction->setData(QVariant(3));
	widthaction->setCheckable(true);
	pixmap = QPixmap(12, 12);
	pixmap.fill(QColor(Qt::black));
	widthaction = new QAction(QIcon(pixmap), tr("Thick stroke"), group_widths_);
	widthaction->setData(QVariant(6));
	widthaction->setCheckable(true);

	IconAction* action;
	action = new IconAction(tr("Select"), "psi/select", tr("Select"), 0, group_modes_ );
	action->setData(QVariant(WbWidget::Select));
	action->setCheckable(true);
	action = new IconAction(tr( "Translate"), "psi/translate", tr("Translate"), 0, group_modes_ );
	action->setData(QVariant(WbWidget::Translate));
	action->setCheckable(true);
	action = new IconAction(tr( "Rotate"), "psi/rotate", tr("Rotate"), 0, group_modes_ );
	action->setData(QVariant(WbWidget::Rotate));
	action->setCheckable(true);
	action = new IconAction(tr( "Scale"), "psi/scale", tr("Scale"), 0, group_modes_ );
	action->setData(QVariant(WbWidget::Scale));
	action->setCheckable(true);
	action = new IconAction(tr( "Erase"), "psi/erase", tr("Erase"), 0, group_modes_ );
	action->setData(QVariant(WbWidget::Erase));
	action->setCheckable(true);
	QAction *separator = new QAction(group_modes_);
	separator->setSeparator(true);
	action = new IconAction(tr( "Scroll view"), "psi/scroll", tr("Scroll"), 0, group_modes_ );
	action->setData(QVariant(WbWidget::Scroll));
	action->setCheckable(true);
	separator = new QAction(group_modes_);
	separator->setSeparator(true);
	action = new IconAction(tr( "Draw paths"), "psi/drawPaths", tr("Draw paths"), 0, group_modes_ );
	action->setData(QVariant(WbWidget::DrawPath));
	action->setCheckable(true);
	action->trigger();
	// action = new IconAction(tr( "Draw lines"), "psi/drawLines", tr("Draw lines"), 0, group_modes_ );
	// action->setData(QVariant(WbWidget::DrawLine));
	// action->setCheckable(true);
	// action = new IconAction(tr( "Draw ellipses"), "psi/drawEllipses", tr("Draw ellipses"), 0, group_modes_ );
	// action->setData(QVariant(WbWidget::DrawEllipse));
	// action->setCheckable(true);
	// action = new IconAction(tr( "Draw circles"), "psi/drawCircles", tr("Draw circles"), 0, group_modes_ );
	// action->setData(QVariant(WbWidget::DrawCircle));
	// action->setCheckable(true);
	// action = new IconAction(tr( "Draw rectangles"), "psi/drawRectangles", tr("Draw rectangles"), 0, group_modes_ );
	// action->setData(QVariant(WbWidget::DrawRectangle));
	// action->setCheckable(true);
	// 	action = new IconAction(tr( "Add text"), "psi/addText", tr("Add text"), 0, group_modes_ );
	// 	action->setData(QVariant(WbWidget::DrawText));
	// 	action->setCheckable(true);
	action = new IconAction(tr( "Add images"), "psi/addImage", tr("Add images"), 0, group_modes_ );
	action->setData(QVariant(WbWidget::DrawImage));
	action->setCheckable(true);

	menu_widths_ = new QMenu(this);
	menu_widths_->addActions(group_widths_->actions());
	act_widths_->setMenu(menu_widths_);

	menu_modes_ = new QMenu(this);
	menu_modes_->addActions(group_modes_->actions());
	act_modes_->setMenu(menu_modes_);

	toolbar_ = new QToolBar(tr("Whiteboard toolbar"), this);
	toolbar_->setIconSize(QSize(16,16));
	toolbar_->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum));
	toolbar_->addAction(act_end_);
	toolbar_->addAction(act_clear_);
	toolbar_->addAction(act_save_);
	toolbar_->addAction(act_geometry_);
	toolbar_->addWidget(new StretchWidget(this));
	toolbar_->addAction(act_fill_);
	toolbar_->addAction(act_color_);
	QToolButton *bw = new QToolButton;
	bw->setIcon(IconsetFactory::icon("psi/drawPaths").icon());
	bw->setMenu(menu_widths_);
	bw->setPopupMode(QToolButton::InstantPopup);
	toolbar_->addWidget(bw);
	QToolButton *bm = new QToolButton;
	bm->setIcon(IconsetFactory::icon("psi/select").icon());
	bm->setMenu(menu_modes_);
	bm->setPopupMode(QToolButton::InstantPopup);
	toolbar_->addWidget(bm);
	vb1->addWidget(toolbar_);

	// Context menu
	pm_settings_ = new QMenu(this);
	connect(pm_settings_, SIGNAL(aboutToShow()), SLOT(buildMenu()));

	X11WM_CLASS("whiteboard");

	// set the Jid -> le_jid.
	le_jid_->setText(QString("%1 (session: %2)").arg(session->target().full()).arg(session->session()));
	le_jid_->setCursorPosition(0);
	le_jid_->setToolTip(session->target().full());

	// update the widget icon
#ifndef Q_OS_MAC
	setWindowIcon(IconsetFactory::icon("psi/whiteboard").icon());
#endif
	
	setWindowOpacity(double(qMax(MINIMUM_OPACITY, PsiOptions::instance()->getOption("options.ui.chat.opacity").toInt())) / 100);

	setGeometryOptionPath(geometryOption);
}
예제 #19
0
ODBCLib::CODBCSession::~CODBCSession() {
	endSession();
}
예제 #20
0
파일: sTest2.c 프로젝트: elipivo/ArmTrack
int main(void) {

	fprintf(stderr, "Reading Test Device\n");

	//make stdin non blocking
	int flags = fcntl(fileno(stdin), F_GETFL, 0);
	flags |= O_NONBLOCK;
	flags = fcntl(fileno(stdin), F_SETFL, flags);
	char userInput;

	Data data;

	if (startTestDevice(&data.TestDevice) != 1) {
		printf("Test Error: Couldn't start Test Device.\n");
		exit(1);
	}

	struct timeval last;
	struct timeval curr;
	gettimeofday(&curr, NULL); //update current time

	while(read(fileno(stdin), &userInput, 1) < 0) {

		last.tv_sec = curr.tv_sec; last.tv_usec = curr.tv_usec; //update last time
		gettimeofday(&curr, NULL); //update current time
		data.time += (curr.tv_sec - last.tv_sec) + (curr.tv_usec - last.tv_usec) * .000001; //increment by difference between last and current time

		//collect data (should take precisely 25ms)
		getTestDeviceData(&data.TestDevice);

		//print data (try to make this as fast as possible) (normal print -> new thread each cycle -> one smart thread)
		printData(&data);

		if (data.TestDevice.consecutiveErrors > 20) {
			//.5 sec of missed data
			//big error happening, try to reconnect to the IMU

			fprintf(stderr, "Test ERROR: Too many consecutive missed reads.\n");
			fprintf(stderr, "Test ERROR: Trying to reconnect to Test device.\n");

			sleep(2); //pretending restart takes time

			if (restartTestDevice(&data.TestDevice) != 1) {
				//couldn't reconnect, just end the program here

				fprintf(stderr, "Test ERROR: Couldn't reconnect to Test device.\n");
				fprintf(stderr, "Test ERROR: Ending recording session.\n");

				endSession(&data);
				return 0;
			}

			fprintf(stderr, "Test ERROR: Successfully reconnected to Test device.\n");
			fprintf(stderr, "Test ERROR: Continuing data recording.\n");
		}
	}

	endSession(&data);

	return 0;
}
예제 #21
0
void Server::setDatabaseInterface(Server_DatabaseInterface *_databaseInterface)
{
    connect(this, SIGNAL(endSession(qint64)), _databaseInterface, SLOT(endSession(qint64)));
    databaseInterfaces.insert(QThread::currentThread(), _databaseInterface);
}
예제 #22
0
DataSourceInterface::~DataSourceInterface() {
	endSession();
}
예제 #23
0
int main(void) {

	fprintf(stderr, "Beginning Structure Test\n");

	//make stdin non blocking
	int flags = fcntl(fileno(stdin), F_GETFL, 0);
	flags |= O_NONBLOCK;
	flags = fcntl(fileno(stdin), F_SETFL, flags);
	char userInput;

//	setPriority();

	fprintf(stderr, "Connecting to sensors.\n");

	startSensors();
	printf("Here 3");

	//start data collection and print threads, initialize necessary mutex's
	startThreads();

	fprintf(stderr, "Collecting data.\n");

	data.outFile = fopen("/home/pi/Desktop/ArmTrack/ArmTrackData.bin", "wb");
	data.errors = 0;
	data.reads = 0;

	struct timeval last;
	struct timeval curr;
	struct timeval temp;

	gettimeofday(&curr, NULL); //update current time

	while(read(fileno(stdin), &userInput, 1) < 0) {

		last.tv_sec = curr.tv_sec; last.tv_usec = curr.tv_usec; //update last time
		gettimeofday(&curr, NULL); //update current time
		data.time += (curr.tv_sec - last.tv_sec) + (curr.tv_usec - last.tv_usec) * .000001; //increment by difference between last and current time

		getData();

		//signal print thread
		while (data.controlValues[4] != 2) {};
		pthread_mutex_lock(&threadLocks[4]);
		data.controlValues[4] = 1;
		pthread_cond_signal(&threadSignals[4]);
		pthread_mutex_unlock(&threadLocks[4]);

		checkSensors();

		//wait for 25ms cycle length
		if (data.EMG.id == -1) {
			do {
				gettimeofday(&temp, NULL);
			} while ( (temp.tv_sec - curr.tv_sec) + (temp.tv_usec - curr.tv_usec) * .000001 < .024993);
		}

		if (data.time > 13) {
			endSession();
			return 1;
		}

	}

	endSession();
	return 1;
}
예제 #24
0
MediaPlayerPrivateMediaFoundation::~MediaPlayerPrivateMediaFoundation()
{
    destroyVideoWindow();
    endSession();
}
예제 #25
0
파일: readCyGl.c 프로젝트: elipivo/ArmTrack
int main(void) {

	fprintf(stderr, "Reading CyberGlove 2\n");

	//make stdin non blocking
	int flags = fcntl(fileno(stdin), F_GETFL, 0);
	flags |= O_NONBLOCK;
	flags = fcntl(fileno(stdin), F_SETFL, flags);
	char userInput;

	//// should only use this with programs controlled by a switch I believe
	//	//make data collection thread a time critical thread
	//	struct sched_param param;
	//	param.sched_priority = sched_get_priority_max(SCHED_RR);
	//	if (sched_setscheduler(0, SCHED_RR, &param) != 0) {
	//		fprintf(stderr, "ERROR: Data Collection Thread Priority not set.\n");
	//		fprintf(stderr, "*Remember to run as root.*\n");
	//		exit(1);
	//	}
	//
	//	//lock process in memory
	//	if (mlockall(MCL_FUTURE) != 0) {
	//		fprintf(stderr, "ERROR: Couldn't lock process in memory.\n");
	//		exit(1);
	//	}


	if (startCyGl(&data.CyGl) != 1) {
		fprintf(stderr, "readCyGl Error: Couldn't start CyberGlove.\n");
		exit(1);
	}

	pthread_mutex_init(&printLock, NULL);
	pthread_cond_init(&printSignal, NULL);
	data.print = 0;
	if (pthread_create(&printThread, NULL, printData, NULL) != 0) {
		fprintf(stderr, "Couldn't create print thread...\n");
		exit(1);
	}

	struct timeval last;
	struct timeval curr;
	struct timeval temp;

	gettimeofday(&curr, NULL); //update current time

	while(read(fileno(stdin), &userInput, 1) < 0) {

		last.tv_sec = curr.tv_sec; last.tv_usec = curr.tv_usec; //update last time
		gettimeofday(&curr, NULL); //update current time
		data.time += (curr.tv_sec - last.tv_sec) + (curr.tv_usec - last.tv_usec) * .000001; //increment by difference between last and current time

		getCyGlData(&data.CyGl, data.time);

		while (data.print != 2) {}; //wait for print thread to be ready
		pthread_mutex_lock(&printLock);
		data.print = 1;
		pthread_cond_signal(&printSignal);
		pthread_mutex_unlock(&printLock);

		if (data.CyGl.consecutiveErrors > 20) {
			//.5 sec of missed data
			//big error happening, try to reconnect to the IMU

			fprintf(stderr, "ERROR: Too many consecutive missed reads.\n");
			fprintf(stderr, "ERROR: Trying to reconnect to Cyber Glove.\n");

			if (restartCyGl(&data.CyGl) != 1) {
				//couldn't reconnect, just end the program here

				fprintf(stderr, "ERROR: Couldn't reconnect to Cyber Glove.\n");
				fprintf(stderr, "ERROR: Ending recording session.\n");

				endSession();
				return 0;
			}

			fprintf(stderr, "ERROR: Successfully reconnected to quick device.\n");
			fprintf(stderr, "ERROR: Continuing data recording.\n");

		}

		do {
			gettimeofday(&temp, NULL);
		} while ( (temp.tv_sec - curr.tv_sec) + (temp.tv_usec - curr.tv_usec) * .000001 < .024993);
	}
	endSession();
	return 1;
}
예제 #26
0
void MainWindow::collapseToTray()
{
    // getting name of the active mode to start session
    QModelIndexList list = ui.modeListView->selectionModel()->selectedIndexes();

    if (list.length() == 0) {
        QMessageBox::about(this, tr("Error"),
            tr("No mode chosen!"));
        return;
    }
    QModelIndex index = list.at(0);
    string name = index.data(ModeListItemDelegate::modeNameRole).toString().toStdString();

    // setting current session mode
    this->processController.setSessionMode(name);

    // getting time of session stand
    unsigned long sessionStand;

    if (ui.checkTillDown->isChecked()) {
        sessionStand = ULLONG_MAX;
        // tray icon refresh tooltip
        trayIcon->setToolTip("Process Control\nMode: " + QString(name.c_str()) + "\nTime left: till shutdown");
    }
    else
    {
        sessionStand = ui.timeEdit->time().msec() +
            ui.timeEdit->time().second() * MS_IN_S +
            ui.timeEdit->time().minute() * SEC_IN_MIN * MS_IN_S +
            ui.timeEdit->time().hour() * MIN_IN_HOUR * SEC_IN_MIN * MS_IN_S;
        //timer for tooltip refreshing
        connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refreshTrayIconTooltip()));
        refreshTimer->start(REFRESH_TRAY_STAB);
    }

    // message box, TODO: maybe I need separated class for that or smth.
    QMessageBox msgBox;
    msgBox.setWindowTitle(tr("Process control"));
    msgBox.setText(tr("The program will keep running in the "
        "system tray. Reboot to prematurely terminate program."));
    msgBox.setWindowIcon(QIcon(":/MainWindow/Resources/mainTray.ico"));
    msgBox.setStandardButtons(QMessageBox::Ok);
    msgBox.exec();


    this->hide();
    // preparing ...
    this->processController.start(sessionStand);

    // starting timer for control stabs - every CONTOL_STAB ms it will run function
    // for stopping restricted programs and injecting dll with restriction into browsers
    connect(controlTimer, SIGNAL(timeout()), this, SLOT(controlStab()));
    controlTimer->start(CONTROL_STAB);

    // starting end session timer
    connect(sessionTimer, SIGNAL(timeout()), this, SLOT(endSession()));
    sessionTimer->setSingleShot(true);
    sessionTimer->start(sessionStand);
    startTime->restart();

    trayIcon->setVisible(true);
    trayIcon->show();
}
예제 #27
0
/*------------------------------------------------------------------------------------------------------------------
--		FUNCTION:		WndProc
--		DATE:			September 21st, 2012
--		REVISIONS:		n/a
--		DESIGNER:		Ramzi Chennafi
--		PROGRAMMER:		Ramzi Chennafi	
--
--		INTERFACE:		LRESULT CALLBACK WndProc (HWND hwnd, UINT Message,
--                          WPARAM wParam, LPARAM lParam)				
--
--		RETURNS:		LRESULT to the system.
--
--		NOTES:
--		Deals with the main window thread. Requests writes, modification of data settings, usage information and 
--		connect/disconnect buttons. Also creates a new thread to perform read operations.
----------------------------------------------------------------------------------------------------------------------*/
LRESULT CALLBACK WndProc (HWND hwnd, UINT Message,
                          WPARAM wParam, LPARAM lParam)
{
	HMENU			menuHnd	= GetMenu(hwnd);
	
	switch (Message)
   {
		case WM_COMMAND:
		   switch (LOWORD (wParam))
			{
				case IDM_CONNECT:
					if(!io->serialOn){
						if((io->hdSerial = init(io)) != NULL){
							MessageBox (hwnd, TEXT("Client Connected"), TEXT("Dumb Terminal"), MB_OK | MB_ICONEXCLAMATION);
							io->serialOn = true;
							io->readThrd = CreateThread(NULL, 0, execRead, io, 0, &io->threadId);
							EnableMenuItem(menuHnd, IDM_CONNECT, MF_GRAYED);
							DrawMenuBar(hwnd);
						}
					}
				break;

				case IDM_HELP:
					MessageBox (hwnd, TEXT("Choose which port you wish to communicate on and then hit data settings to modify the communication settings.\nConnect will begin a session, hit escape to end the current session.\nAny keyboard input will be transferred during a session."), 
						TEXT("Dumb Terminal"), MB_OK | MB_ICONINFORMATION);
				break;
				
				case ID_PORT_COMM1:
					io->port = TEXT("com1");
					checkItem(menuHnd, COMM1);
				break;
				
				case ID_PORT_COMM3:
					io->port = TEXT("com3");
					checkItem(menuHnd, COMM3);
				break;

          		case IDM_DATA_SETTINGS:
            		io->cc.dwSize = sizeof(COMMCONFIG);
					io->cc.wVersion = 0x100;
					GetCommConfig (hComm, &io->cc, &io->cc.dwSize);
            		if (!CommConfigDialog (io->port, io->hwnd, &io->cc))
               			break;
				break;
			}
		break;

		case WM_CHAR:	
			if(io->serialOn && wParam != VK_ESCAPE){
				writeOutputBuffer(io->hdSerial, wParam);
			}
		break;

		case WM_KEYDOWN:
			if(wParam == VK_ESCAPE && io->serialOn == true){
				io->serialOn = false;
				
				MessageBox (hwnd, TEXT("Client Disconnected"), TEXT("Dumb Terminal"), MB_OK | MB_ICONEXCLAMATION);
				InvalidateRect(hwnd, NULL, FALSE);
				EnableMenuItem(menuHnd, IDM_CONNECT, MF_ENABLED);
				DrawMenuBar(hwnd);
				
				endSession(io->hdSerial, io->readThrd);
			}
		break;

		case WM_DESTROY:	
      		PostQuitMessage (0);
		break;
		
		default:
			 return DefWindowProc (hwnd, Message, wParam, lParam);
	}
	return 0;
}