bool ClientLobbyRoomProtocol::notifyEventAsynchronous(Event* event) { assert(m_setup); // assert that the setup exists if (event->getType() == EVENT_TYPE_MESSAGE) { const NetworkString &data = event->data(); assert(data.size()); // assert that data isn't empty uint8_t message_type = data[0]; if (message_type == 0x03 || message_type == 0x06) return false; // don't treat the event event->removeFront(1); Log::info("ClientLobbyRoomProtocol", "Asynchronous message of type %d", message_type); if (message_type == 0x01) // new player connected newPlayer(event); else if (message_type == 0x02) // player disconnected disconnectedPlayer(event); else if (message_type == 0x04) // start race startGame(event); else if (message_type == 0x05) // start selection phase startSelection(event); else if (message_type == 0x80) // connection refused connectionRefused(event); else if (message_type == 0x81) // connection accepted connectionAccepted(event); else if (message_type == 0x82) // kart selection refused kartSelectionRefused(event); else if (message_type == 0xc0) // vote for major mode playerMajorVote(event); else if (message_type == 0xc1) // vote for race count playerRaceCountVote(event); else if (message_type == 0xc2) // vote for minor mode playerMinorVote(event); else if (message_type == 0xc3) // vote for track playerTrackVote(event); else if (message_type == 0xc4) // vote for reversed mode playerReversedVote(event); else if (message_type == 0xc5) // vote for laps playerLapsVote(event); return true; } // message else if (event->getType() == EVENT_TYPE_CONNECTED) { return true; } // connection else if (event->getType() == EVENT_TYPE_DISCONNECTED) // means we left essentially { NetworkManager::getInstance()->removePeer(m_server); m_server = NULL; NetworkManager::getInstance()->disconnected(); m_listener->requestTerminate(this); NetworkManager::getInstance()->reset(); // probably the same as m_server NetworkManager::getInstance()->removePeer(event->getPeer()); return true; } // disconnection return false; } // notifyEventAsynchronous
void Server :: acceptConnection() { clientConnection = sslServer -> getClientConnection(); qDebug() << "New connection received from "<< clientConnection->peerAddress().toString(); connect(clientConnection, SIGNAL(encrypted()), SLOT(connectionAccepted())); connect(clientConnection, SIGNAL(readyRead()), this, SLOT(readDataFromClient())); connect(clientConnection, SIGNAL(disconnected()), clientConnection, SLOT(deleteLater())); connect(clientConnection, SIGNAL(disconnected()), this, SLOT(notifyDisconnect())); connect(clientConnection, SIGNAL(sslErrors(QList<QSslError>)),SLOT(sslErrors(QList<QSslError>)) ); }
void EventHandler::accept() { if (m_parent->connection()->accept(m_parent->appData())) { emit connectionAccepted(); } else { emit connectionRejected(); } }
void EventHandler::runEventLoop() { Logger::logError(" EventHandler::runEventLoop() "); // Exit from event loop when invoker is ready to connect connect(this, SIGNAL(connectionAccepted()), MApplication::instance() , SLOT(quit())); connect(this, SIGNAL(connectionRejected()), MApplication::instance() , SLOT(quit())); // Enable theme change handler m_item = new MGConfItem(MEEGOTOUCH_THEME_GCONF_KEY, 0); connect(m_item, SIGNAL(valueChanged()), this, SLOT(notifyThemeChange())); // Start another thread to listen connection from invoker QtConcurrent::run(this, &EventHandler::accept); // Create socket pair for SIGHUP bool handlerIsSet = false; if (::socketpair(AF_UNIX, SOCK_STREAM, 0, m_sighupFd)) { Logger::logError("EventHandler: Couldn't create HUP socketpair"); } else { // Install signal handler e.g. to exit cleanly if launcher dies. // This is a problem because MBooster runs a Qt event loop. EventHandler::setupUnixSignalHandlers(); // Install a socket notifier on the socket connect(new QSocketNotifier(m_sighupFd[1], QSocketNotifier::Read, this), SIGNAL(activated(int)), this, SLOT(handleSigHup())); handlerIsSet = true; } // Run event loop so MApplication and MApplicationWindow objects can receive notifications MApplication::exec(); // Disable theme change handler disconnect(m_item, 0, this, 0); delete m_item; m_item = NULL; // Restore signal handlers to previous values if (handlerIsSet) { restoreUnixSignalHandlers(); } }
NetworkControl::NetworkControl() { client = new Client(); QObject::connect(client, SIGNAL(connected()), this, SLOT(onConnected())); QObject::connect(client, SIGNAL(hostFound()), this, SLOT(onHostFound())); QObject::connect(client, SIGNAL(loggingIn()), this, SLOT(onLoggingIn())); QObject::connect(client, SIGNAL(successfullJoin()), this, SLOT(onConnectionAccepted())); QObject::connect(client, SIGNAL(disconnected()), this, SLOT(onDisconnected())); QObject::connect(client, SIGNAL(presentationReceived(QString, QList<QImage>)), this, SLOT(onPresentationReceived(QString, QList<QImage>))); server = new Server(); QObject::connect(server, SIGNAL(listening()), this, SLOT(onStarted())); QObject::connect(server, SIGNAL(connectionAccepted()), this, SLOT(onClientConnected())); QObject::connect(server, SIGNAL(clientVerified()), this, SLOT(onClientVerified())); QObject::connect(server, SIGNAL(clientLeft()), this, SLOT(onClientLeft())); QObject::connect(server, SIGNAL(closing()), this, SLOT(onClosed())); }
bool ClientLobbyRoomProtocol::notifyEventAsynchronous(Event* event) { assert(m_setup); // assert that the setup exists if (event->getType() == EVENT_TYPE_MESSAGE) { NetworkString &data = event->data(); assert(data.size()); // assert that data isn't empty uint8_t message_type = data.getUInt8(); Log::info("ClientLobbyRoomProtocol", "Asynchronous message of type %d", message_type); switch(message_type) { case LE_NEW_PLAYER_CONNECTED: newPlayer(event); break; case LE_PLAYER_DISCONNECTED : disconnectedPlayer(event); break; case LE_START_RACE: startGame(event); break; case LE_START_SELECTION: startSelection(event); break; case LE_CONNECTION_REFUSED: connectionRefused(event); break; case LE_CONNECTION_ACCEPTED: connectionAccepted(event); break; case LE_KART_SELECTION_REFUSED: kartSelectionRefused(event); break; case LE_VOTE_MAJOR : playerMajorVote(event); break; case LE_VOTE_RACE_COUNT: playerRaceCountVote(event); break; case LE_VOTE_MINOR: playerMinorVote(event); break; case LE_VOTE_TRACK: playerTrackVote(event); break; case LE_VOTE_REVERSE: playerReversedVote(event); break; case LE_VOTE_LAPS: playerLapsVote(event); break; } // switch return true; } // message else if (event->getType() == EVENT_TYPE_DISCONNECTED) { // This means we left essentially. // We can't delete STKHost from this thread, since the main // thread might still test if STKHost exists and then call // the ProtocolManager, which might already have been deleted. // So only signal that STKHost should exit, which will be tested // from the main thread. STKHost::get()->requestShutdown(); return true; } // disconnection return false; } // notifyEventAsynchronous
int Server::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: readyToSendData(); break; case 1: messageReceived((*reinterpret_cast< QString(*)>(_a[1]))); break; case 2: serverDisconnected(); break; case 3: acceptConnection(); break; case 4: connectionAccepted(); break; case 5: readDataFromClient(); break; case 6: sslErrors((*reinterpret_cast< const QList<QSslError>(*)>(_a[1]))); break; case 7: notifyDisconnect(); break; } _id -= 8; } return _id; }
NetworkControl::NetworkControl(PresentationControl* p) { pc = p; QObject::connect(pc, SIGNAL(presentationChanged()), this, SLOT(onPresentationChanged())); QThread* networkThread = new QThread(); client = new Client(); QObject::connect(client, SIGNAL(currentPageReceived(qint64)), pc, SLOT(onCurrenPageChanged(qint64))); QObject::connect(client, SIGNAL(connected()), this, SLOT(onConnected())); QObject::connect(client, SIGNAL(hostFound()), this, SLOT(onHostFound())); QObject::connect(client, SIGNAL(loggingIn()), this, SLOT(onLoggingIn())); QObject::connect(client, SIGNAL(successfullJoin()), this, SLOT(onConnectionAccepted())); QObject::connect(client, SIGNAL(disconnected()), this, SLOT(onDisconnected())); QObject::connect(client, SIGNAL(presentationReceived(QString, QList<QImage>)), this, SLOT(onPresentationReceived(QString, QList<QImage>))); server = new Server(); server->setPresentation(p->getPresentation()); QObject::connect(server, SIGNAL(listening()), this, SLOT(onStarted())); QObject::connect(server, SIGNAL(connectionAccepted()), this, SLOT(onClientConnected())); QObject::connect(server, SIGNAL(clientVerified()), this, SLOT(onClientVerified())); QObject::connect(server, SIGNAL(clientLeft()), this, SLOT(onClientLeft())); QObject::connect(server, SIGNAL(closing()), this, SLOT(onClosed())); }