QStringList FKRealmComponent::serverList(const QString roomType){ if(roomType.isEmpty())return serverList(); QStringList lst; if(!FK_THREAD_GETTER_ARG(QStringList,lst,getServersForRoomType,QString,roomType)){ emit messageRequested(QString(tr("Unable get server list for %1 room type")).arg(roomType)); } return lst; }
bool ConnectWindow::eventFilter(QObject* object, QEvent* event) { if ((object == ui.cbServer && event->type() == QEvent::MouseButtonPress) && (state_ == STATE_DISCONNECTED)) { emit serverList(); } return false; }
ServerSettings ServerGroupSettings::serverByIndex(int index) const { ServerList servers = serverList(); if(index < servers.count()) { return servers[index]; } return ServerSettings(); }
MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags), loginWindow_(NULL), connectWindow_(NULL), serverListWindow_(0), timer_(NULL), settingsMenu_(0), connected_(0), getServers_(NULL) { QCoreApplication::setOrganizationName("CPPP"); QCoreApplication::setApplicationName("VPNht"); ui.setupUi(this); setWindowTitle("VPN.ht " + QString(VERSION)); g_openVPNConnection = new OpenVPNConnectorQt(this); if (!g_openVPNConnection->installHelper(SERVICE_NAME)) { QMessageBox::information(this, "VPNht", "Failed to install helper for program. Please contact support."); QTimer::singleShot(1, this, SLOT(close())); return; } #if defined Q_OS_MAC //setAttribute(Qt::WA_QuitOnClose, false); #endif trayIcon_ = new QSystemTrayIcon(this); trayMenu_ = new QMenu(this); actConnect_ = new QAction("Connect", this); actDisconnect_ = new QAction("Disconnect", this); actHelp_ = new QAction("Help", this); actLiveChat_ = new QAction("Live chat", this); actExit_ = new QAction("Quit", this); trayMenu_->addAction(actConnect_); trayMenu_->addAction(actDisconnect_); trayMenu_->addSeparator(); trayMenu_->addAction(actHelp_); trayMenu_->addAction(actLiveChat_); trayMenu_->addAction(actExit_); trayIcon_->setContextMenu(trayMenu_); trayIcon_->hide(); setTrayStatusDisconnected(false); settingsMenu_ = new QMenu(this); settingsMenu_->addAction("Settings", this, SLOT(onSettings())); settingsMenu_->addAction("Status", this, SLOT(onStatus())); settingsMenu_->addAction("Help", this, SLOT(onHelp())); settingsMenu_->addAction("Proxy", this, SLOT(onProxy())); settingsMenu_->addAction("Show logs", this, SLOT(onShowLogs())); settingsMenu_->addAction("Logout", this, SLOT(onReturnToSignUp())); settingsMenu_->setStyleSheet(ctxMenuStyle); loginWindow_ = new LoginWindow(this); ui.verticalLayout->addWidget(loginWindow_); loginWindow_->loadSettings(); loginWindow_->hide(); connect(loginWindow_, SIGNAL(signedIn(QString, QString)), SLOT(onSignIn(QString, QString))); waitWindow_ = new WaitWindow(this); ui.verticalLayout->addWidget(waitWindow_); settingsWindow_ = new SettingsWindow(settingsMenu_, this); connect(settingsWindow_, SIGNAL(back()), SLOT(onBack())); ui.verticalLayout->addWidget(settingsWindow_); settingsWindow_->hide(); connectWindow_ = new ConnectWindow(settingsMenu_, this); connect(connectWindow_, SIGNAL(serverList()), SLOT(onServerList())); connect(connectWindow_, SIGNAL(connected()), SLOT(onConnected())); ui.verticalLayout->addWidget(connectWindow_); ui.verticalLayout->addWidget(connectWindow_); connectWindow_->hide(); serverListWindow_ = new ServerListWindow(this); connect(serverListWindow_, SIGNAL(serverSelected(const QString &)), this, SLOT( onChangeServer(const QString &) )); ui.verticalLayout->addWidget(serverListWindow_); serverListWindow_->hide(); proxySettingsWindow_ = new ProxySettingsWindow(settingsMenu_, this); connect(proxySettingsWindow_, SIGNAL(back()), SLOT(onBack())); ui.verticalLayout->addWidget(proxySettingsWindow_); proxySettingsWindow_->hide(); // tray action connect(actConnect_, SIGNAL(triggered()), connectWindow_, SLOT(onClickConnect())); connect(actDisconnect_, SIGNAL(triggered()), connectWindow_, SLOT(onClickConnect())); connect(actHelp_, SIGNAL(triggered()), SLOT(onActHelp())); connect(actLiveChat_, SIGNAL(triggered()), SLOT(onLiveChat())); connect(actExit_, SIGNAL(triggered()), SLOT(onExit())); #if defined Q_OS_WIN connect(trayIcon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), SLOT( onTrayActivated(QSystemTrayIcon::ActivationReason) )); #endif QSettings settings; if (settings.value("savePass", "true").toString() == "true") { QString username = settings.value("login", "").toString(); QString password = settings.value("password", "").toString(); if (!username.isEmpty() && !password.isEmpty()) { adjustSize(); setFixedSize(size()); skipLoginScreen(username, password); } else { waitWindow_->hide(); loginWindow_->show(); adjustSize(); setFixedSize(size()); } } else { waitWindow_->hide(); loginWindow_->show(); adjustSize(); setFixedSize(size()); } }
BOOL OPCEngine::getStatistics( OUT OPCStatistics *statAll, OUT OPCStatistics *statSinceLastCall, OUT DWORD *msSinceLastCall) { OPCStatistics curStat; ULONG reads; ULONG writes; _TRACE(TL_DEB, TG_ENG, (_T("get statistics >"))); m_curStatLock.Lock(); memcpy(&curStat, &m_curStat, sizeof(OPCStatistics)); memset(&m_curStat, 0, sizeof(OPCStatistics)); m_curStatLock.Unlock(); DWORD now = ::GetTickCount(); if (getTimeSpan(m_allStat.startTime, now) > 86400000) { // reset all statistics after 1 day memset(&m_allStat, 0, sizeof(OPCStatistics)); m_allStat.startTime = ::GetTickCount(); } //-- calculate current statistics -- // times if (reads = (curStat.req.asyncDeviceRead + curStat.req.syncDeviceRead + curStat.req.cyclicRead - curStat.req.asyncDeviceReadBad - curStat.req.syncDeviceReadBad - curStat.req.cyclicReadBad)) curStat.req.averageTimeRead = (curStat.req.timeRead / reads); if (writes = (curStat.req.asyncWrite + curStat.req.syncWrite - curStat.req.asyncWriteBad - curStat.req.syncWriteBad)) curStat.req.averageTimeWrite = (curStat.req.timeWrite / writes); // objects { GenericList<GenericBranch> serverList(m_opcRoot->getBranchList()); GenericList<GenericBranch> groupList; GenericList<GenericLeaf> itemList; POSITION posSrv; POSITION posGrp; GenericServer *server; GenericGroup *group; curStat.obj.serverObjects = 0; curStat.obj.groupObjects = 0; curStat.obj.publicGroupObjects = 0; curStat.obj.publicGroupTemplates = 0; curStat.obj.itemObjects = 0; posSrv = serverList.getStartPosition(); while(posSrv) { server = (GenericServer *)serverList.getNext(posSrv); if (server) { groupList = server->getBranchList(); groupList.lock(); if (!server->isPublicGroups()) { curStat.obj.serverObjects++; posGrp = groupList.getStartPosition(); while(posGrp) { group = (GenericGroup *)groupList.getNext(posGrp); if (!group->isPublic()) { curStat.obj.groupObjects++; } else { curStat.obj.publicGroupObjects++; } itemList = group->getLeafList(); curStat.obj.itemObjects += itemList.getCount(); } } else { curStat.obj.publicGroupTemplates = groupList.getCount();; } groupList.unlock(); } } } //-- add current to all statistics -- m_allStat.req.asyncCacheRead += curStat.req.asyncCacheRead; m_allStat.req.asyncDeviceRead += curStat.req.asyncDeviceRead; m_allStat.req.asyncWrite += curStat.req.asyncWrite; m_allStat.req.syncCacheRead += curStat.req.syncCacheRead; m_allStat.req.syncDeviceRead += curStat.req.syncDeviceRead; m_allStat.req.syncWrite += curStat.req.syncWrite; m_allStat.req.cyclicRead += curStat.req.cyclicRead; m_allStat.req.reportRead += curStat.req.reportRead; m_allStat.req.asyncCacheReadBad += curStat.req.asyncCacheReadBad; m_allStat.req.asyncDeviceReadBad += curStat.req.asyncDeviceReadBad; m_allStat.req.asyncWriteBad += curStat.req.asyncWriteBad; m_allStat.req.syncCacheReadBad += curStat.req.syncCacheReadBad; m_allStat.req.syncDeviceReadBad += curStat.req.syncDeviceReadBad; m_allStat.req.syncWriteBad += curStat.req.syncWriteBad; m_allStat.req.cyclicReadBad += curStat.req.cyclicReadBad; m_allStat.req.reportReadBad += curStat.req.reportReadBad; m_allStat.req.timeRead += curStat.req.timeRead; m_allStat.req.timeWrite += curStat.req.timeWrite; //-- calculate all statistics -- if (curStat.req.maxTimeRead > m_allStat.req.maxTimeRead) m_allStat.req.maxTimeRead = curStat.req.maxTimeRead; if (curStat.req.maxTimeWrite > m_allStat.req.maxTimeWrite) m_allStat.req.maxTimeWrite = curStat.req.maxTimeWrite; if (reads = (m_allStat.req.asyncDeviceRead + m_allStat.req.syncDeviceRead + m_allStat.req.cyclicRead - m_allStat.req.asyncDeviceReadBad - m_allStat.req.syncDeviceReadBad - m_allStat.req.cyclicReadBad)) m_allStat.req.averageTimeRead = (m_allStat.req.timeRead / reads); if (writes = (m_allStat.req.asyncWrite + m_allStat.req.syncWrite - m_allStat.req.asyncWriteBad - m_allStat.req.syncWriteBad)) m_allStat.req.averageTimeWrite = (m_allStat.req.timeWrite / writes); if (curStat.obj.serverObjects > m_allStat.obj.serverObjects) m_allStat.obj.serverObjects = curStat.obj.serverObjects; if (curStat.obj.groupObjects > m_allStat.obj.groupObjects) m_allStat.obj.groupObjects = curStat.obj.groupObjects; if (curStat.obj.publicGroupObjects > m_allStat.obj.publicGroupObjects) m_allStat.obj.publicGroupObjects = curStat.obj.publicGroupObjects; if (curStat.obj.publicGroupTemplates > m_allStat.obj.publicGroupTemplates) m_allStat.obj.publicGroupTemplates = curStat.obj.publicGroupTemplates; if (curStat.obj.itemObjects > m_allStat.obj.itemObjects) m_allStat.obj.itemObjects = curStat.obj.itemObjects; m_allStat.allCount++; curStat.allCount = 1; //-- copy to output buffer -- if (statAll) { memcpy(statAll, &m_allStat, sizeof(OPCStatistics)); } if (statSinceLastCall) { memcpy(statSinceLastCall, &curStat, sizeof(OPCStatistics)); } if (msSinceLastCall) { *msSinceLastCall = getTimeSpan(m_lastStatTime, now); } m_lastStatTime = now; _TRACE(TL_DEB, TG_ENG, (_T("< get statistics"))); return TRUE; }
DWORD OPCEngine::mainOPCThread(void) { DWORD ret; BOOL end = FALSE; try { _TRACE(TL_INF, TG_ENG, (_T("started engine thread"))); //-- initialize engine thread -- _TRACE(TL_DEB, TG_ENG, (_T("COM initialize (multithreaded)"))); HRESULT res = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); if( FAILED(res)) { _ERROR(TG_ENG, OPCENGINE_ERR_COM,(_T("Can't initialize COM: 0x%X"), res)); return res; } if (m_type == OutProc) { _TRACE(TL_DEB, TG_ENG, (_T("register class objects"))); _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER, REGCLS_MULTIPLEUSE); } //-- wait till engine termiantion -- while (!end) { ret = ::WaitForMultipleObjects(2, m_events, FALSE, m_clientCheckInterval); switch (ret - WAIT_OBJECT_0) { case END_EVENT: { // end event end = TRUE; _TRACE(TL_DEB, TG_ENG, (_T("received end event"))); } break; case SHUTDOWN_EVENT: { // shutdown event OPCShutdownRequest *sreq; _TRACE(TL_DEB, TG_ENG, (_T("received shutdown event"))); while(!m_shutdownList.IsEmpty()) { sreq = m_shutdownList.RemoveHead(); if (sreq->server) { sreq->server->sendShutdownRequest(sreq->reason); if (sreq->event != INVALID_HANDLE_VALUE) ::SetEvent(sreq->event); sreq->server->release(); } delete sreq; } } break; default: { // timeout //-- check client connections -- GenericList<GenericBranch> serverListCopy; POSITION posSrv; GenericServer *server; BOOL conOK; serverListCopy.create(); { GenericList<GenericBranch> serverList(m_opcRoot->getBranchList()); posSrv = serverList.getStartPosition(); while(posSrv) { server = (GenericServer *)serverList.getNext(posSrv); server->addRef(); serverListCopy.add(server); } } posSrv = serverListCopy.getStartPosition(); while(posSrv) { server = (GenericServer *)serverListCopy.getNext(posSrv); conOK = server->checkClientConnection(); if (!conOK) { server->disconnectClient(); } server->release(); } serverListCopy.free(); } break; } } //-- terminated engine -- if (m_type == OutProc) { _TRACE(TL_DEB, TG_ENG, (_T("revoke class objects"))); _Module.RevokeClassObjects(); } //-- disconnect all clients -- GenericList<GenericBranch> serverList(m_opcRoot->getBranchList()); POSITION posSrv; GenericServer *server; posSrv = serverList.getStartPosition(); while(posSrv) { server = (GenericServer *)serverList.getNext(posSrv); server->disconnectClient(); } serverList.unlock(); _TRACE(TL_DEB, TG_ENG, (_T("COM uninitialize"))); ::CoUninitialize(); _TRACE(TL_INF, TG_ENG, (_T("terminated engine thread"))); } catch(CException* e) { TCHAR excText[100]; CRuntimeClass* rt = e->GetRuntimeClass(); e->GetErrorMessage(excText, 100); _ERROR(TG_ENG, OPCENGINE_ERR_EXCEPTION,(_T("MFC EXCEPTION in OPC Engine Main Thread: %s (%s)"), rt->m_lpszClassName, excText)); return 1; } catch(...) { _ERROR(TG_ENG, OPCENGINE_ERR_EXCEPTION,(_T("EXCEPTION in OPC Engine Main Thread"))); return 1; } return S_OK; }