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); }
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 SetupWindow::MessageReceived(BMessage* msg) { switch (msg->what) { case M_SETUP_CHOOSE_NETWORK: { BMenuItem* item(NULL); msg->FindPointer("source", reinterpret_cast<void**>(&item)); if (item && vision_app->CheckNetworkValid(item->Label())) connectButton->SetEnabled(true); else connectButton->SetEnabled(false); } break; case M_CONNECT_NETWORK: { BMessage connMsg(M_CONNECT_NETWORK); connMsg.AddString("network", netList->MenuItem()->Label()); be_app_messenger.SendMessage(&connMsg); } break; case M_PREFS_SHOW: { // forwarding Cmd+Shift+/ message be_app_messenger.SendMessage(msg); } break; default: BWindow::MessageReceived(msg); } }
void ConnAliveThread::closeConnection(int reason) { //qDebug()<<"closeConnection(reason)"<<*ptr_ConnPtr<<URI; keep_alive = false; switch (reason) { case VIR_CONNECT_CLOSE_REASON_ERROR: emit connMsg("Connection closed: Misc I/O error"); break; case VIR_CONNECT_CLOSE_REASON_EOF: emit connMsg("Connection closed: End-of-file from server"); break; case VIR_CONNECT_CLOSE_REASON_KEEPALIVE: emit connMsg("Connection closed: Keepalive timer triggered"); break; case VIR_CONNECT_CLOSE_REASON_CLIENT: emit connMsg("Connection closed: Client requested it"); break; default: emit connMsg("Connection closed: Unknown reason"); break; }; }
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); }
void VisionApp::MessageReceived(BMessage* msg) { switch (msg->what) { case M_ABOUT_CLOSE: { fAboutWin = 0; if (fShuttingDown) PostMessage(B_QUIT_REQUESTED); } break; case M_SETUP_SHOW: { if (fSetupWin) fSetupWin->Activate(); else { fSetupWin = new SetupWindow(); fSetupWin->Show(); } } break; case M_SETUP_CLOSE: { SaveSettings(); fSetupWin = 0; if (fClientWin == NULL) PostMessage(B_QUIT_REQUESTED); } break; case M_PREFS_SHOW: { if (fPrefsWin) fPrefsWin->Activate(); else { fPrefsWin = new PrefsWindow(); fPrefsWin->Show(); } } break; case M_PREFS_CLOSE: { SaveSettings(); fPrefsWin = 0; } break; case M_NETWORK_SHOW: { if (fNetWin) fNetWin->Activate(); else { fNetWin = new NetworkWindow(); fNetWin->Show(); } } break; case M_NETWORK_CLOSE: { SaveSettings(); fNetWin = 0; } break; case M_CONNECT_NETWORK: { BRect clientWinRect(GetRect("clientWinRect")); BMessage netData = GetNetwork(msg->FindString("network")); // sanity check if (netData.IsEmpty()) break; if (netData.FindBool("useDefaults")) { netData.RemoveName("nick"); netData.RemoveName("realname"); netData.RemoveName("ident"); BMessage netDefaults(GetNetwork("defaults")); netData.AddString("realname", netDefaults.FindString("realname")); netData.AddString("ident", netDefaults.FindString("ident")); const char* nick(NULL); for (int32 i = 0; (nick = netDefaults.FindString("nick", i)) != NULL; i++) netData.AddString("nick", nick); } if (fClientWin == NULL) { fClientWin = new ClientWindow(clientWinRect); fWinThread = fClientWin->Thread(); fClientWin->Show(); } BMessage connMsg(M_MAKE_NEW_NETWORK); connMsg.AddMessage("network", &netData); fClientWin->PostMessage(&connMsg); } break; case M_JOIN_CHANNEL: { if (fClientWin == NULL) break; fClientWin->PostMessage(msg); } break; case M_DCC_FILE_WIN: { if (fDccFileWin) { fDccFileWin->PostMessage(msg); } else { DCCConnect* view; msg->FindPointer("view", reinterpret_cast<void**>(&view)); fDccFileWin = new DCCFileWindow(view); fDccFileWin->Show(); } } break; case M_DCC_MESSENGER: if (msg->IsSourceWaiting()) { BMessenger msgr(fDccFileWin); BMessage reply; reply.AddMessenger("msgr", msgr); msg->SendReply(&reply); } break; case M_DCC_FILE_WIN_DONE: { fDccFileWin = 0; } break; case M_DCC_COMPLETE: { Broadcast(msg); } break; case M_LOAD_URL: { BString url(msg->FindString("url")); if (url.Length() > 0) { LoadURL(url.String()); } } break; default: BApplication::MessageReceived(msg); } }
void MainWindow::doReInit() { static DRUID::ConnectionPackagePtr nullConnection; resetStatusBar(); trackedstate->clearDisplay(); if (automatic_update_checks && (rand() % 127) > 109) availableUpdateCheck(true); // if we already have a connection, close that down and come back later if (connection) { pingTimer->Stop(); connection->destroy(); connection = nullConnection; SetStatusText(wxT("Closing current connection")); autoInitTimer->Start(MAINWINDOW_CONNECTION_CLOSE_DELAY_MS, true); return; } // no matter what, if we get here we (no longer?) have a connection and // need to init one... if (!loadConfig()) { // first time use if (! doGetSettings(true)) { currentlyEnabledSUIWindown()->setError(wxT("Did not specify serial port, please do so prior to initializing.")); SetStatusText(wxT("Could not automatically set serial port")); return; } } // figure out--or request--the port to connect to DRUID::SerialEnumerator sEnumerator; if (serial_port.size() && sEnumerator.portExists(serial_port)) { DRUID4ARDUINO_DEBUG("Connecting"); wxString connMsg(wxT("Connecting to ")); connMsg += DRUID_STDSTRING_TOWX(serial_port); SetStatusText(connMsg); } else { DRUID::PortNameList ports = sEnumerator.listPorts(); if (! ports.size()) { currentlyEnabledSUIWindown()->setError(wxT("Cannot automatically determine serial port -- specify please.")); SetStatusText(wxT("Could not automatically set serial port")); return; } else if (ports.size() > 1) { currentlyEnabledSUIWindown()->setError(wxT("Cannot automatically determine serial port -- multiple options available, please select.")); SetStatusText(wxT("Could not automatically set serial port")); } else { // 1 port avail... try that one. serial_port = ports[0]; std::string statusTxt("Automatic connection to port "); statusTxt += serial_port; SetStatusText(DRUID_STDSTRING_TOWX(statusTxt)); } } // ok, actually get the connection connection = DRUID::Util::getConnection(baud_rate, serial_port); if (! connection) { currentlyEnabledSUIWindown()->setError(wxT("Could not create new connection package")); DRUID4ARDUINO_DEBUG("Could not create new connection package"); SetStatusText(wxT("Could not create new connection package")); return; } if (! connection->active()) { wxString errMsg(wxT("Could not connect to ")); errMsg += DRUID_STDSTRING_TOWX(serial_port); errMsg += wxT("\r\nEnsure a valid SerialUI device is connected, and confirm settings."); currentlyEnabledSUIWindown()->setError(errMsg); SetStatusText(errMsg); return; } // we have an active connection now crawlMenusTimer->Start(MAINWINDOW_CONNECTION_STARTCRAWL_DELAY_MS, true); return; }