// private functions RyConnection * RyProxyServer::_getConnection(int handle){ //QMutexLocker locker(&connectionOpMutex); //Q_UNUSED(locker) //QDateTime time = QDateTime::currentDateTime(); //qDebug()<<"getConnection:" // <<time.toMSecsSinceEpoch(); //if(!_cacheConnections.contains(handle)){ //qDebug()<<"_lastConnectionId"<<_lastConnectionId; _lastConnectionId++; QMutexLocker locker(&connectionOpMutex); QThread *newThread = new QThread(); RyConnection *connection = new RyConnection(handle,_lastConnectionId); _connections.append(connection); _threads[connection] = newThread; locker.unlock(); connect(connection,SIGNAL(idleTimeout()),SLOT(onConnectionIdleTimeout())); connect(connection,SIGNAL(pipeBegin(RyPipeData_ptr)), SLOT(onPipeBegin(RyPipeData_ptr))); connect(connection,SIGNAL(pipeComplete(RyPipeData_ptr)), SLOT(onPipeComplete(RyPipeData_ptr))); connect(connection,SIGNAL(pipeError(RyPipeData_ptr)), SLOT(onPipeError(RyPipeData_ptr))); connect(connection,SIGNAL(connectionClose()), SLOT(onConnectionClosed())); connect(connection,SIGNAL(pipeBegin(RyPipeData_ptr)), SIGNAL(pipeBegin(RyPipeData_ptr))); connect(connection,SIGNAL(pipeComplete(RyPipeData_ptr)), SIGNAL(pipeComplete(RyPipeData_ptr))); connect(connection,SIGNAL(pipeError(RyPipeData_ptr)), SIGNAL(pipeError(RyPipeData_ptr))); connection->moveToThread(newThread); connect(newThread,SIGNAL(started()),connection,SLOT(run())); connect(newThread,SIGNAL(finished()),SLOT(onThreadTerminated())); newThread->start(); /* qDebug()<<"=== create connection cost:" <<time.msecsTo(QDateTime::currentDateTime()) <<time.toMSecsSinceEpoch(); */ return connection; }
cmd::Result IDLECommand::Execute() { namespace pt = boost::posix_time; if (args.size() == 1) { std::ostringstream os; os << "Your current IDLE timeout is " << client.IdleTimeout().total_seconds() << " seconds."; control.Reply(ftp::CommandOkay, os.str()); } else { pt::seconds idleTimeout(0); try { idleTimeout = pt::seconds(boost::lexical_cast<long>(args[1])); } catch (const boost::bad_lexical_cast&) { return cmd::Result::SyntaxError; } const cfg::Config& config = cfg::Get(); if (idleTimeout < config.IdleTimeout().Minimum() || idleTimeout > config.IdleTimeout().Maximum()) { std::ostringstream os; os << "IDLE timeout must be between " << config.IdleTimeout().Minimum().total_seconds() << " and " << config.IdleTimeout().Maximum().total_seconds() << " seconds."; control.Reply(ftp::SyntaxError, os.str()); return cmd::Result::Okay; } client.SetIdleTimeout(idleTimeout); std::ostringstream os; os << "IDLE timeout set to " << idleTimeout.total_seconds() << " seconds."; control.Reply(ftp::CommandOkay, os.str()); } return cmd::Result::Okay; }
void IdlenessWatcher::screenUnlocked(int exitCode, QProcess::ExitStatus exitStatus) { mIsLocked = false; emit ActiveChanged(false); if (exitCode == 0) { restartTimer(); } else { mErrorNotification.setSummary(tr("ERROR: Screen unlocked")); if (exitStatus == QProcess::NormalExit) mErrorNotification.setBody(tr("Locking program \"%1\" exited with error code %2").arg(mLockCommand).arg(exitCode)); else mErrorNotification.setBody(tr("Locking program \"%1\" crashed with error code %2").arg(mLockCommand).arg(exitCode)); mErrorNotification.update(); mTimer.stop(); connect(&mErrorNotification, SIGNAL(notificationClosed(CloseReason)), SLOT(idleTimeout())); } }
IdlenessWatcher::IdlenessWatcher(QObject* parent): Watcher(parent), mPSettings(), mErrorNotification(tr("LxQt Idleness watcher failed to start")), mDBusWatcher(this), mInhibitorCookie(0), mIsLocked(false) { qDebug() << "Starting idlenesswatcher"; mConn = X11Helper::connection(); xcb_prefetch_extension_data(mConn, &xcb_screensaver_id); xcb_prefetch_extension_data(mConn, &xcb_dpms_id); xcb_screensaver_query_version_cookie_t verCookie = xcb_screensaver_query_version_unchecked(mConn, XCB_SCREENSAVER_MAJOR_VERSION, XCB_SCREENSAVER_MINOR_VERSION); xcb_dpms_get_version_cookie_t dpmsVerCookie = xcb_dpms_get_version_unchecked(mConn, XCB_DPMS_MAJOR_VERSION, XCB_DPMS_MINOR_VERSION); // Note that XCB is asynchronous, so we want to make requests ASAP and get the responses as late as possible. mScreen = screenOfDisplay(mConn, 0); mErrorNotification.setUrgencyHint(LxQt::Notification::UrgencyCritical); mErrorNotification.setIcon("object-unlocked"); mErrorNotification.setTimeout(0); new ScreenSaverAdaptor(this); QDBusConnection sessionBus = QDBusConnection::sessionBus(); if (!sessionBus.registerService("org.freedesktop.ScreenSaver") || !sessionBus.registerObject("/ScreenSaver", this)) { mErrorNotification.setBody(tr("D-Bus interface org.freedesktop.ScreenSaver is already registered")); mErrorNotification.update(); qWarning() << "ERROR: D-Bus interface org.freedesktop.ScreenSaver is already registered"; } mDBusWatcher.setConnection(QDBusConnection::sessionBus()); mDBusWatcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration); connect(&mTimer, SIGNAL(timeout()), SLOT(idleTimeout())); connect(&mPSettings, SIGNAL(settingsChanged()), SLOT(restartTimer())); connect(&mDBusWatcher, SIGNAL(serviceUnregistered(QString)), SLOT(serviceUnregistered(QString))); connect(&mLockProcess, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(screenUnlocked(int,QProcess::ExitStatus))); connect(&mErrorNotification, SIGNAL(actionActivated(int)), SLOT(notificationAction(int))); // Get XCB responses ... const xcb_query_extension_reply_t* extReply = xcb_get_extension_data(mConn, &xcb_screensaver_id); const xcb_query_extension_reply_t* dpmsExtReply = xcb_get_extension_data(mConn, &xcb_dpms_id); xcb_screensaver_query_version_reply_t* verReply = xcb_screensaver_query_version_reply(mConn, verCookie, NULL); xcb_dpms_get_version_reply_t* dpmsVerReply = xcb_dpms_get_version_reply(mConn, dpmsVerCookie, NULL); if (mScreen && extReply && extReply->present && dpmsExtReply && dpmsExtReply->present && verReply && dpmsVerReply && verReply->server_major_version == XCB_SCREENSAVER_MAJOR_VERSION && verReply->server_minor_version >= XCB_SCREENSAVER_MINOR_VERSION //&& dpmsVerReply->server_major_version == XCB_DPMS_MAJOR_VERSION //&& dpmsVerReply->server_minor_version >= XCB_DPMS_MINOR_VERSION ) { free(verReply); free(dpmsVerReply); } else { mErrorNotification.setBody(tr("The X11 Screensaver extension is not usable")); mErrorNotification.update(); if (verReply) free(verReply); qCritical() << "ERROR: Can't use the X11 Screensaver Extension!"; } mErrorNotification.setActions(QStringList(tr("Configure..."))); qDebug() << "LxQt Screenlocker started."; qDebug() << "timeout:" << getMaxIdleTimeoutMs() << "ms, lock command:" << mLockCommand; restartTimer(); }
void Transaction::emitIdleTimeout() { emit idleTimeout(this); }