ConnElement::ConnElement(QObject *parent) : QObject(parent) { waitTimerId = 0; connAliveThread = new ConnAliveThread(this); connect(connAliveThread, SIGNAL(connMsg(QString)), this, SLOT(receiveConnMessage(QString))); connect(connAliveThread, SIGNAL(changeConnState(CONN_STATE)), this, SLOT(setConnectionState(CONN_STATE))); connect(connAliveThread, SIGNAL(authRequested(QString&)), this, SLOT(getAuthCredentials(QString&))); connect(connAliveThread, SIGNAL(domStateChanged(Result)), this, SIGNAL(domStateChanged(Result))); connect(connAliveThread, SIGNAL(netStateChanged(Result)), this, SIGNAL(netStateChanged(Result))); connect(connAliveThread, SIGNAL(connClosed(bool)), this, SLOT(forwardConnClosedSignal(bool))); connect(connAliveThread, SIGNAL(errorMsg(QString&,uint)), this, SLOT(writeErrorToLog(QString&,uint))); // change element state in the thread's state changed case only connect(connAliveThread, SIGNAL(started()), this, SLOT(connAliveThreadStarted())); connect(connAliveThread, SIGNAL(finished()), this, SLOT(connAliveThreadFinished())); connect(connAliveThread, SIGNAL(domainEnd(QString&)), this, SLOT(emitDomainKeyToCloseViewer(QString&))); }
void ConnAliveThread::closeConnection() { //qDebug()<<"closeConnection0"<<*ptr_ConnPtr<<URI; if ( keep_alive ) { keep_alive = false; return; }; //qDebug()<<"closeConnection1"<<*ptr_ConnPtr<<URI; CONN_STATE state; if ( *ptr_ConnPtr!=NULL ) { //qDebug()<<"closeConnection2"<<*ptr_ConnPtr<<URI; unregisterConnEvents(); //qDebug()<<"closeConnection3"<<*ptr_ConnPtr<<URI; int ret = virConnectClose(*ptr_ConnPtr); //qDebug()<<"virConnectRef -1"<<"ConnAliveThread"<<URI<<(ret+1>0); if ( ret<0 ) { state = FAILED; sendConnErrors(); } else { emit connMsg( QString("close exit code: %1").arg(ret) ); state = CLOSED; emit connClosed(onView); }; *ptr_ConnPtr = NULL; } else { emit connMsg( QString("connect is NULL") ); state = FAILED; }; emit changeConnState(state); }
void ConnAliveThread::openConnection() { //*ptr_ConnPtr = virConnectOpen(URI.toUtf8().constData()); auth.cb = authCallback; auth.cbdata = this; _connPtr = virConnectOpenAuth(URI.toUtf8().constData(), &auth, 0); ptr_ConnPtr = &_connPtr; if (*ptr_ConnPtr==NULL) { sendConnErrors(); keep_alive = false; emit connMsg( "Connection to the Hypervisor is failed." ); emit changeConnState(FAILED); } else { //qDebug()<<" openConnection"<<*ptr_ConnPtr<<URI; keep_alive = true; emit connMsg( QString("connect opened: %1") .arg(QVariant(*ptr_ConnPtr!=NULL) .toString()) ); emit changeConnState(RUNNING); registerConnEvents(); }; //qDebug()<<"virConnectRef +1"<<"ConnAliveThread"<<URI<<(*ptr_ConnPtr!=NULL); }