Exemple #1
0
AMReadOnlyPVControl::AMReadOnlyPVControl(const QString& name, const QString& readPVname, QObject* parent, const QString description)
	: AMControl(name, "?", parent, description)  {

	wasConnected_ = false;
	readPV_ = new AMProcessVariable(readPVname, true, this);

	lowLimitPV_ = 0;
	highLimitPV_ = 0;

	allowLowLimitValuePVUpdates_ = true;
	allowHighLimitValuePVUpdates_ = true;

	lowLimitValue_ = -1;
	highLimitValue_ = -1;

	connect(readPV_, SIGNAL(valueChanged(double)), this, SIGNAL(valueChanged(double)));
	connect(readPV_, SIGNAL(alarmChanged(int,int)), this, SIGNAL(alarmChanged(int,int)));
	connect(readPV_, SIGNAL(readReadyChanged(bool)), this, SLOT(onPVConnected(bool)));
	connect(readPV_, SIGNAL(connectionTimeout()), this, SIGNAL(readConnectionTimeoutOccurred()));
	connect(readPV_, SIGNAL(error(int)), this, SLOT(onReadPVError(int)));
	connect(readPV_, SIGNAL(connectionTimeout()), this, SLOT(onConnectionTimeout()));

	connect(readPV_, SIGNAL(initialized()), this, SLOT(onReadPVInitialized()));

	// If the readPV_ is already initialized as soon as we create it [possible if it's sharing an existing connection], we'll never get the inialized() signal, do it here now:
	wasConnected_ = readPV_->readReady();	// same as isConnected(), but we cannot call virtual functions from a constructor, potentially breaks subclasses.
	if(readPV_->isInitialized())
		onReadPVInitialized();

}
Exemple #2
0
AMPVControl::AMPVControl(const QString& name, const QString& readPVname, const QString& writePVname, const QString& stopPVname, QObject* parent, double tolerance, double completionTimeoutSeconds, int stopValue, const QString &description)
	: AMReadOnlyPVControl(name, readPVname, parent, description)
{
	setTolerance(tolerance);
	allowsMovesWhileMoving_ = true;

	//not moving yet:
	moveInProgress_ = false;

	// not connected:
	wasConnected_ = false;

	// setpoint is initialized:
	setpoint_ = 0;

	// this is what to use for our timeout:
	completionTimeout_ = completionTimeoutSeconds;

	// connect the timer to the timeout handler:
	connect(&completionTimer_, SIGNAL(timeout()), this, SLOT(onCompletionTimeout()));

	// process variable:
	writePV_ = new AMProcessVariable(writePVname, true, this);
	// instead of connected(), use writeRead: connect(writePV_, SIGNAL(connected(bool)), this, SLOT(onPVConnected(bool)))
	connect(writePV_, SIGNAL(writeReadyChanged(bool)), this, SLOT(onPVConnected(bool)));
	connect(writePV_, SIGNAL(error(int)), this, SLOT(onWritePVError(int)));
	connect(writePV_, SIGNAL(connectionTimeout()), this, SIGNAL(writeConnectionTimeoutOccurred()));
	connect(writePV_, SIGNAL(connectionTimeout()), this, SLOT(onConnectionTimeout()));
	connect(writePV_, SIGNAL(valueChanged(double)), this, SLOT(onSetpointChanged(double)));
	connect(writePV_, SIGNAL(initialized()), this, SLOT(onWritePVInitialized()));

	// We now need to monitor the feedback position ourselves, to see if we get where we want to go:
	connect(readPV_, SIGNAL(valueChanged(double)), this, SLOT(onNewFeedbackValue(double)));

	// Do we have a stopPV?
	noStopPV_ = stopPVname.isEmpty();
	if(noStopPV_) {
		stopPV_ = 0;
	}
	else {
		stopPV_ = new AMProcessVariable(stopPVname, false, this);
		connect(stopPV_, SIGNAL(error(int)), this, SLOT(onReadPVError(int)));	/// \todo Does this need separate error handling? What if the stop write fails? That's really important.
	}
	stopValue_ = stopValue;


	// If any PVs are already connected [possible if they're sharing an existing connection]:
	wasConnected_ = (readPV_->readReady() && writePV_->writeReady());	// equivalent to isConnected(), but we cannot call virtual functions inside a constructor, that will break subclasses.
	if(writePV_->isInitialized())
		onWritePVInitialized();
}
Exemple #3
0
AMPVwStatusControl::AMPVwStatusControl(const QString& name, const QString& readPVname, const QString& writePVname, const QString& movingPVname, const QString& stopPVname, QObject* parent, double tolerance, double moveStartTimeoutSeconds, AMAbstractControlStatusChecker* statusChecker, int stopValue, const QString &description)
	: AMReadOnlyPVwStatusControl(name, readPVname, movingPVname, parent, statusChecker, description) {

	// Initialize:
	moveInProgress_ = false;
	stopInProgress_ = false;
	startInProgress_ = false;
	settlingInProgress_ = false;
	settlingTime_ = 0.0;	/// \todo Once tested, this should maybe be enabled by default. All systems with separate status and feedback PVs will need it. How much time?
	setTolerance(tolerance);
	setpoint_ = 0;
	moveStartTimeout_ = moveStartTimeoutSeconds;
	hardwareWasMoving_ = false;

	// create new setpoint PV. Monitor it, in case someone else changes it
	writePV_ = new AMProcessVariable(writePVname, true, this);

	// connect:
	// use writeReadyChanged() instead of connected() here: connect(writePV_, SIGNAL(connected(bool)), this, SLOT(onPVConnected(bool)))
	connect(writePV_, SIGNAL(writeReadyChanged(bool)), this, SLOT(onPVConnected(bool)));
	connect(writePV_, SIGNAL(error(int)), this, SLOT(onWritePVError(int)));
	connect(writePV_, SIGNAL(connectionTimeout()), this, SIGNAL(writeConnectionTimeoutOccurred()));
	connect(writePV_, SIGNAL(connectionTimeout()), this, SLOT(onConnectionTimeout()));
	connect(writePV_, SIGNAL(valueChanged(double)), this, SLOT(onSetpointChanged(double)));
	connect(writePV_, SIGNAL(initialized()), this, SLOT(onWritePVInitialized()));

	// connect the timer to the timeout handler:
	connect(&moveStartTimer_, SIGNAL(timeout()), this, SLOT(onMoveStartTimeout()));
	connect(&settlingTimer_, SIGNAL(timeout()), this, SLOT(onSettlingTimeFinished()));

	// Do we have a stopPV?
	noStopPV_ = stopPVname.isEmpty();
	if(noStopPV_) {
		stopPV_ = 0;
	}
	else {
		stopPV_ = new AMProcessVariable(stopPVname, false, this);
		connect(stopPV_, SIGNAL(error(int)), this, SLOT(onReadPVError(int)));	/// \todo Does this need separate error handling? What if the stop write fails? That's really important.
	}
	stopValue_ = stopValue;


	// If any PVs were already connected on creation [possible if sharing an existing connection]:
	wasConnected_ = (readPV_->readReady() && writePV_->writeReady() && movingPV_->readReady());	// equivalent to isConnected(), but we cannot call virtual functions from the constructor, potentially breaks subclasses.
	if(writePV_->isInitialized())
		setMoveEnumStates(writePV_->enumStrings());
	if(movingPV_->readReady())
		hardwareWasMoving_ = (*statusChecker_)((int)movingPV_->lastValue());

}
bool RedisClient::SshTransporter::openTcpSocket()
{
    auto config = m_connection->getConfig();
    m_socket = m_sshClient->openTcpSocket(config.host(), config.port());

    if (!m_socket) {
        emit errorOccurred("SSH connection established, but socket failed");
        return false;
    }

    SignalWaiter socketWaiter(config.connectionTimeout());
    socketWaiter.addAbortSignal(m_socket, &QxtSshTcpSocket::destroyed);
    socketWaiter.addSuccessSignal(m_socket, &QxtSshTcpSocket::readyRead);

    connect(m_socket, &QxtSshTcpSocket::readyRead, this, &RedisClient::AbstractTransporter::readyRead);
    connect(m_socket, &QxtSshTcpSocket::destroyed, this, &RedisClient::SshTransporter::OnSshSocketDestroyed);

    if (!m_socket->isOpen() && !socketWaiter.wait()) {
        emit errorOccurred(QString("SSH connection established, but redis connection failed"));
        return false;
    }

    emit connected();
    emit logEvent(QString("%1 > reconnected").arg(m_connection->getConfig().name()));

    return true;
}
void GaduSocketNotifiers::socketTimeout()
{
	kdebugf();

	if (!handleSoftTimeout())
		connectionTimeout();
}
SearchLocationID::~SearchLocationID()
{
	disconnect(timerTimeout_, SIGNAL(timeout()), this, SLOT(connectionTimeout()));

	if (weatherConfig_)
		delete weatherConfig_;
}
SearchLocationID::SearchLocationID()
:
	weatherConfig_(0),
	searchAllServers_(false),
	redirected_(false)
{
	timerTimeout_ = new QTimer(this);

	connect(timerTimeout_, SIGNAL(timeout()), this, SLOT(connectionTimeout()));
}
Exemple #8
0
    void EtherIPC::waitConnect() {
        if ( fStarting == 1 ) {
            return init();
        }

        if ( fStarting != 1 && fStarting != 2 ) {
            return connectionTimeout();
        }

        if ( ++fConnectAttempts < 10 ) {
            if ( fSocket.state() == QLocalSocket::ConnectingState ) {
                fSocket.abort();
            }

            connectToServer();
        } else {
            connectionTimeout();
        }
    }
void AMProcessVariable::onConnectionTimeout() {

	// If we haven't connected by now:
	if(!isConnected()) {
		// Reporting an error monitor here is expensive (especially if you have a lot of timeouts on startup) ... so we'll let the process variable support take care of it with a deferred call
		AMProcessVariableSupport::reportTimeoutError(pvName());
		emit connectionTimeout();
	}

	// Channel access will keep on trying in the background. (Channel access handles this automatically for us.)  Will emit connected() signal when successful.
}
Exemple #10
0
AMReadOnlyPVwStatusControl::AMReadOnlyPVwStatusControl(const QString& name, const QString& readPVname, const QString& movingPVname, QObject* parent, AMAbstractControlStatusChecker* statusChecker, const QString &description)
	: AMReadOnlyPVControl(name, readPVname, parent, description)
{
	// Initializing:
	statusChecker_ = statusChecker;
	wasMoving_ = false;

	// Create the movingPV and hook it up:
	movingPV_ = new AMProcessVariable(movingPVname, true, this);
	connect(movingPV_, SIGNAL(valueChanged(int)), this, SLOT(onMovingChanged(int)));
	connect(movingPV_, SIGNAL(readReadyChanged(bool)), this, SLOT(onPVConnected(bool)));
	connect(movingPV_, SIGNAL(error(int)), this, SLOT(onStatusPVError(int)));
	connect(movingPV_, SIGNAL(connectionTimeout()), this, SIGNAL(movingConnectionTimeoutOccurred()));
	connect(movingPV_, SIGNAL(connectionTimeout()), this, SLOT(onConnectionTimeout()));

	// If any PVs were already connected on creation [possible if sharing an existing connection]:
	wasConnected_ = (readPV_->readReady() && movingPV_->readReady());	// equivalent to isConnected(), but we cannot call virtual functions inside a constructor, potentially breaks subclasses.
	if(movingPV_->readReady())
		wasMoving_ = (*statusChecker_)((int)movingPV_->lastValue());

}
Exemple #11
0
DccTransferRecv::DccTransferRecv(QObject* parent)
    : DccTransfer( DccTransfer::Receive, parent )
{
    kdDebug() << "DccTransferRecv::DccTransferRecv()" << endl;

    m_serverSocket = 0;
    m_recvSocket = 0;
    m_writeCacheHandler = 0;

    m_connectionTimer = new QTimer( this );
    connect( m_connectionTimer, SIGNAL( timeout() ), this, SLOT( connectionTimeout() ) );
    //timer hasn't started yet.  qtimer will be deleted automatically when 'this' object is deleted
}
Exemple #12
0
Server::Server()
:   tcpServer(0), networkSession(0)
{
    remote_port = 51015;
    local_port = 51016;
    device_id = 0;
    thisIPAddress = "";
    remoteIPAddress = "127.0.0.1";
    is_init_connection = false;
    is_config_mode = false;
    tcpServer = NULL;
    networkSession = NULL;
    remote_server_socket = NULL;
    shotTimer = new QTimer(this);
    shotTimer->setInterval(100000);
    shotTimer->setSingleShot(false);
    connect(shotTimer, SIGNAL(timeout()), this, SLOT(sendingTimeout()));
    connectionTimer = new QTimer(this);
    connectionTimer->setInterval(20000);
    connectionTimer->setSingleShot(false);
    connect(connectionTimer, SIGNAL(timeout()), this, SLOT(connectionTimeout()));

    sensors = new QHash<QString, ClientSensor *>();
    actions = new QHash<QString, ClientAction *>();

    sensors->insert("activity", new ClientSensorActivity(this));
    sensors->insert("button_activity", new ClientSensorBtnActivity(this));
    //sensors->insert("mouse", new ClientSensor(this));
    //sensors->insert("keyboard", new ClientSensor(this));
    //sensors->insert("activity_direction", new ClientSensor(this));
    //sensors->insert("internet_speed", new ClientSensor(this));

    actions->insert("tone", new ClientActionTone(this));
    actions->insert("melody", new ClientActionToneMelody(this));
    actions->insert("lcd", new ClientActionLcd(this));
    actions->insert("led", new ClientActionIndication(this));
    actions->insert("led_state", new ClientActionIndicationState(this));
    actions->insert("reset", new ClientActionReset(this));
    actions->insert("config", new ClientActionConfig(this));
    actions->insert("display_state", new ClientActionSetDisplayState(this));
    //actions->insert("activity_direction", new ClientAction(this));

    initSensors();
}
Exemple #13
0
    void EtherIPC::connectToServer(const QString& path) {
        if ( fAborted ) {
            bail();
            return;
        }

        fActiveRequest = RequestIPC(Full);
        emit busyChanged(getBusy());
        fPath = path;
        if ( fSocket.state() != QLocalSocket::UnconnectedState ) {
            setError("Already connected");
            return bail();
        }

        fSocket.connectToServer(path);
        EtherLog::logMsg("Connecting to IPC socket");

        QTimer::singleShot(2000, this, SLOT(connectionTimeout()));
    }
Exemple #14
0
void Server::sessionOpen()
{
    emit write_message(tr("Network session opened."));

    // Save the used configuration
    if (networkSession) {
        QNetworkConfiguration config = networkSession->configuration();
        QString id;
        if (config.type() == QNetworkConfiguration::UserChoice)
            id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString();
        else
            id = config.identifier();

        QSettings settings(QSettings::UserScope, QLatin1String("QtProject"));
        settings.beginGroup(QLatin1String("QtNetwork"));
        settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id);
        settings.endGroup();
    }

    if (!tcpServer) tcpServer = new QTcpServer(this);
    if (!tcpServer->listen(QHostAddress::Any, local_port)) {
        emit error(tr("Unable to start the server: %1.").arg(tcpServer->errorString()));
        return;
    }

    QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
    // use the first non-localhost IPv4 address
    for (int i = 0; i < ipAddressesList.size(); ++i) {
        if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
            ipAddressesList.at(i).toIPv4Address()) {
            thisIPAddress = ipAddressesList.at(i).toString();
            break;
        }
    }
    // if we did not find one, use IPv4 localhost
    if (thisIPAddress.isEmpty())
        thisIPAddress = QHostAddress(QHostAddress::LocalHost).toString();

    emit write_message(tr("The server is running on IP: %1 port: %2\n").arg(thisIPAddress).arg(tcpServer->serverPort()));

    connectionTimeout();
}
bool WorkStation::qt_invoke( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->slotOffset() ) {
    case 0: updateTimer(); break;
    case 1: status(); break;
    case 2: user(); break;
    case 3: connectionClosedByClient(); break;
    case 4: readFromClient(); break;
    case 5: socketError((int)static_QUType_int.get(_o+1)); break;
    case 6: sendCommand(); break;
    case 7: sendCommandTime(); break;
    case 8: blockSlot(); break;
    case 9: delayBlocked(); break;
    case 10: wakeUp(); break;
    case 11: connectionTimeout(); break;
    default:
	return QObject::qt_invoke( _id, _o );
    }
    return TRUE;
}
QConnectionManager::QConnectionManager(QObject *parent) :
    QObject(parent),
     netman(NetworkManagerFactory::createInstance()),
     currentNetworkState(QString()),
     currentType(QString()),
     currentNotification(0),
     askForRoaming(false),
     isEthernet(false),
     connmanAvailable(false),
     handoverInProgress(false),
     oContext(0),
     tetheringWifiTech(0),
     tetheringEnabled(false),
     flightModeSuppression(false)
{
    qDebug() << Q_FUNC_INFO;

    manualConnnectionTimer.invalidate();

    connect(netman,SIGNAL(availabilityChanged(bool)),this,SLOT(connmanAvailabilityChanged(bool)));

    connectionAdaptor = new ConnAdaptor(this);
    QDBusConnection dbus = QDBusConnection::sessionBus();

    if (!dbus.registerService(CONND_SERVICE)) {
        qDebug() << "XXXXXXXXXXX could not register service XXXXXXXXXXXXXXXXXX";
    }

    if (!dbus.registerObject(CONND_PATH, this)) {
        qDebug() << "XXXXXXXXXXX could not register object XXXXXXXXXXXXXXXXXX";
    }

    askForRoaming = askRoaming();

    connect(&clockModel,SIGNAL(timeUpdatesChanged()),this,SLOT(timeUpdatesChanged()));
    ua = new UserAgent(this);

    connect(ua,SIGNAL(userInputRequested(QString,QVariantMap)),
            this,SLOT(onUserInputRequested(QString,QVariantMap)));

    connect(ua,SIGNAL(connectionRequest()),this,SLOT(onConnectionRequest()));
    connect(ua,SIGNAL(errorReported(QString, QString)),this,SLOT(onErrorReported(QString, QString)));
    connect(ua,SIGNAL(userInputCanceled()),this,SLOT(onUserInputCanceled()));
    connect(ua,SIGNAL(userInputRequested(QString,QVariantMap)),
            this,SLOT(onUserInputRequested(QString,QVariantMap)), Qt::UniqueConnection);
    connect(ua,SIGNAL(browserRequested(QString,QString)),
            this,SLOT(browserRequest(QString,QString)), Qt::UniqueConnection);

    connect(netman,SIGNAL(servicesListChanged(QStringList)),this,SLOT(servicesListChanged(QStringList)));
    connect(netman,SIGNAL(stateChanged(QString)),this,SLOT(networkStateChanged(QString)));
    connect(netman,SIGNAL(servicesChanged()),this,SLOT(setup()));
    connect(netman,SIGNAL(offlineModeChanged(bool)),this,SLOT(offlineModeChanged(bool)));

    QFile connmanConf("/etc/connman/main.conf");
    if (connmanConf.open(QIODevice::ReadOnly | QIODevice::Text)) {
        while (!connmanConf.atEnd()) {
            QString line = connmanConf.readLine();
            if (line.startsWith("DefaultAutoConnectTechnologies")) {
                QString token = line.section(" = ",1,1).simplified();
                techPreferenceList = token.split(",");
                break;
            }
        }
        connmanConf.close();
    }
    if (techPreferenceList.isEmpty())
        //ethernet,bluetooth,cellular,wifi is default
        techPreferenceList << "wifi" << "cellular" << "bluetooth" << "ethernet";

    mceWatch = new WakeupWatcher(this);
    connect(mceWatch,SIGNAL(displayStateChanged(QString)),this,SLOT(displayStateChanged(QString)));
    connect(mceWatch,SIGNAL(sleepStateChanged(bool)),this,SLOT(sleepStateChanged(bool)));

    connmanAvailable = QDBusConnection::systemBus().interface()->isServiceRegistered("net.connman");
    if (connmanAvailable)
        setup();
    goodConnectTimer = new QTimer(this);
    goodConnectTimer->setSingleShot(true);
    goodConnectTimer->setInterval(12 * 1000);
    connect(goodConnectTimer,SIGNAL(timeout()),this,SLOT(connectionTimeout()));

}
Exemple #17
0
bool KMSmtpClient::connectToHost()
{
    //Check out the socket pointer.
    if(socket()==nullptr)
    {
        qCritical()<<"Socket pointer is NULL.";
        return false;
    }
    //Check out the connection type.
    switch (connectionType())
    {
    case TlsConnection:
    case TcpConnection:
        qDebug()<<"Start normal link, host:"<<host()<<"port:"<<port();
        //Simply call the connect to host function.
        socket()->connectToHost(host(), port());
        break;
    case SslConnection:
        qDebug()<<"Start SSL link, host:"<<host()<<"port:"<<port();
        //Recast socket as a QSslSocket.
        static_cast<QSslSocket *>(socket())->connectToHostEncrypted(host(),
                                                                    port());
        break;
    }
    qDebug()<<"Start to connect.";
    //Tries to connect to server
    if(!socket()->waitForConnected(connectionTimeout()))
    {
        //Emit the error.
        emit clientError(ConnectionTimeoutError);
        //Failed to connect.
        return false;
    }
    // If the response code is not 220 (Service ready)
    // means that is something wrong with the server
    //The response code needs to be 220.
    if(!waitAndCheckResponse(220, ServerError))
    {
        //Failed to login.
        return false;
    }
    qDebug()<<"Start EHLO";
    // Send a EHLO/HELO message to the server
    // The client's first command must be EHLO/HELO
    sendMessage("EHLO " + userName());
    //The response code needs to be 250.
    if(!waitAndCheckResponse(250, ServerError))
    {
        //Failed to login.
        return false;
    }
    //If the connection type is TLS connection, we have to start TLS.
    if(connectionType() == TlsConnection)
    {
        //Send a request to start TLS handshake.
        sendMessage("STARTTLS");
        //The response code needs to be 220.
        if(!waitAndCheckResponse(220, ServerError))
        {
            //Failed to login.
            return false;
        }
        //Recast the socket into ssl socket.
        QSslSocket *sslSocket=static_cast<QSslSocket *>(socket());
        //Start encryption.
        qDebug()<<"Start encryption.";
        sslSocket->startClientEncryption();
        sslSocket->ignoreSslErrors();
        //Check out result.
        if(!sslSocket->waitForEncrypted(connectionTimeout()))
        {
            //Print out the error information.
            qCritical()<<sslSocket->errorString();
            //Emit the smtp error.
            emit clientError(ConnectionTimeoutError);
            //Failed to connect.
            return false;
        }
        qDebug()<<"Start EHLO again";
        // Send ELHO one more time
        sendMessage("EHLO " + userName());
        //The response code needs to be 250.
        if(!waitAndCheckResponse(250, ServerError))
        {
            //Failed to login.
            return false;
        }
    }
    //Mission complete.
    return true;
}