void Video::setPause(bool enable) { if (isRunning()) { emit requestPause(enable); Function::setPause(enable); } }
/** Simple finite state machine. First get the public ip address. Once this * is known, register the server and its address with the stk server so that * client can find it. */ void ServerLobbyRoomProtocol::update() { switch (m_state) { case NONE: // Start the protocol to find the public ip address. m_current_protocol = new GetPublicAddress(this); m_current_protocol->requestStart(); m_state = GETTING_PUBLIC_ADDRESS; // The callback from GetPublicAddress will wake this protocol up requestPause(); break; case GETTING_PUBLIC_ADDRESS: { Log::debug("ServerLobbyRoomProtocol", "Public address known."); // Free GetPublicAddress protocol delete m_current_protocol; // Register this server with the STK server. This will block // this thread, but there is no need for the protocol manager // to react to any requests before the server is registered. registerServer(); Log::info("ServerLobbyRoomProtocol", "Server registered."); m_state = ACCEPTING_CLIENTS; } break; case ACCEPTING_CLIENTS: { // Only poll the STK server if this is a WAN server. if(NetworkConfig::get()->isWAN()) checkIncomingConnectionRequests(); if (m_in_race && World::getWorld() && RaceEventManager::getInstance<RaceEventManager>()->isRunning()) { checkRaceFinished(); } break; } case SELECTING_KARTS: break; // Nothing to do, this is event based case DONE: m_state = EXITING; requestTerminate(); break; case EXITING: break; } } // update
GstPlayer::GstPlayer(QObject *parent): IMediaPlayer(parent), playing(false), loaded(false), error(false), playingRequested(false), mustSeek(true), duration(-1), position(0), formatTime(GST_FORMAT_TIME), pipeline(0), gstObjectName("player") { GstPlayer::ensureInitGst(); connect(this,SIGNAL(requestPause()),this,SLOT(doPause())); connect(this,SIGNAL(requestPlay()),this,SLOT(doPlay())); connect(this,SIGNAL(requestStop()),this,SLOT(doStop())); //watcher = NULL; theVol = new GValue(); g_value_init(theVol,G_TYPE_DOUBLE); positionQueryTimer = new QTimer(this); }
/** Simple finite state machine. First get the public ip address. Once this * is known, register the server and its address with the stk server so that * client can find it. */ void ServerLobbyRoomProtocol::update(float dt) { switch (m_state) { case NONE: // Start the protocol to find the public ip address. m_current_protocol = new GetPublicAddress(this); m_current_protocol->requestStart(); m_state = GETTING_PUBLIC_ADDRESS; // The callback from GetPublicAddress will wake this protocol up requestPause(); break; case GETTING_PUBLIC_ADDRESS: { Log::debug("ServerLobbyRoomProtocol", "Public address known."); // Free GetPublicAddress protocol delete m_current_protocol; // Register this server with the STK server. This will block // this thread, but there is no need for the protocol manager // to react to any requests before the server is registered. registerServer(); Log::info("ServerLobbyRoomProtocol", "Server registered."); m_state = ACCEPTING_CLIENTS; } break; case ACCEPTING_CLIENTS: { // Only poll the STK server if this is a WAN server. if(NetworkConfig::get()->isWAN()) checkIncomingConnectionRequests(); break; } case SELECTING: break; // Nothing to do, this is event based case RACING: if (World::getWorld() && RaceEventManager::getInstance<RaceEventManager>()->isRunning()) { checkRaceFinished(); } break; case RESULT_DISPLAY: if(StkTime::getRealTime() > m_timeout) { // Send a notification to all clients to exit // the race result screen NetworkString *exit_result_screen = getNetworkString(1); exit_result_screen->setSynchronous(true); exit_result_screen->addUInt8(LE_EXIT_RESULT); sendMessageToPeersChangingToken(exit_result_screen, /*reliable*/true); delete exit_result_screen; m_state = ACCEPTING_CLIENTS; RaceResultGUI::getInstance()->backToLobby(); // notify the network world that it is stopped RaceEventManager::getInstance()->stop(); // stop race protocols findAndTerminateProtocol(PROTOCOL_CONTROLLER_EVENTS); findAndTerminateProtocol(PROTOCOL_KART_UPDATE); findAndTerminateProtocol(PROTOCOL_GAME_EVENTS); } break; case DONE: m_state = EXITING; requestTerminate(); break; case EXITING: break; } } // update
ThreadProcess::~ThreadProcess(void) { requestPause(); _jobs.cancelWait(); terminate(); }
// ---------------------------------------------------------------------------- void ConnectToServer::asynchronousUpdate() { switch(m_state) { case NONE: { Log::info("ConnectToServer", "Protocol starting"); // This protocol will write the public address of this // instance to STKHost. m_current_protocol = new GetPublicAddress(this); m_current_protocol->requestStart(); // This protocol will be unpaused in the callback from // GetPublicAddress requestPause(); m_state = GETTING_SELF_ADDRESS; break; } case GETTING_SELF_ADDRESS: { delete m_current_protocol; // delete GetPublicAddress m_current_protocol = NULL; registerWithSTKServer(); // Register us with STK server if (m_quick_join) { handleQuickConnect(); // Quick connect will give us the server details, // so we can immediately try to connect to the server m_state = REQUESTING_CONNECTION; } else { m_state = GOT_SERVER_ADDRESS; } } break; case GOT_SERVER_ADDRESS: { assert(!m_quick_join); delete m_current_protocol; m_current_protocol = NULL; Log::info("ConnectToServer", "Server's address known"); // we're in the same lan (same public ip address) !! if (m_server_address.getIP() == NetworkConfig::get()->getMyAddress().getIP()) { Log::info("ConnectToServer", "Server appears to be in the same LAN."); } m_state = REQUESTING_CONNECTION; m_current_protocol = new RequestConnection(m_server_id); m_current_protocol->requestStart(); break; } case REQUESTING_CONNECTION: // In case of a LAN server, m_crrent_protocol is NULL if (!m_current_protocol || m_current_protocol->getState() == PROTOCOL_STATE_TERMINATED) { delete m_current_protocol; m_current_protocol = NULL; // Server knows we want to connect Log::info("ConnectToServer", "Connection request made"); if (m_server_address.getIP() == 0 || m_server_address.getPort() == 0 ) { // server data not correct, hide address and stop m_state = HIDING_ADDRESS; Log::error("ConnectToServer", "Server address is %s", m_server_address.toString().c_str()); m_current_protocol = new HidePublicAddress(); m_current_protocol->requestStart(); return; } if (m_server_address.getIP() == NetworkConfig::get()->getMyAddress().getIP() || NetworkConfig::get()->isLAN()) { // We're in the same lan (same public ip address). // The state will change to CONNECTING handleSameLAN(); } else { m_state = CONNECTING; m_current_protocol = new PingProtocol(m_server_address, 2.0); m_current_protocol->requestStart(); } } break; case CONNECTING: // waiting the server to answer our connection { static double timer = 0; if (StkTime::getRealTime() > timer+5.0) // every 5 seconds { STKHost::get()->connect(m_server_address); timer = StkTime::getRealTime(); Log::info("ConnectToServer", "Trying to connect to %s", m_server_address.toString().c_str()); } break; } case CONNECTED: { Log::info("ConnectToServer", "Connected"); if(m_current_protocol) { // Kill the ping protocol because we're connected m_current_protocol->requestTerminate(); } delete m_current_protocol; m_current_protocol = NULL; // LAN networking does not use the stk server tables. if(NetworkConfig::get()->isWAN()) { m_current_protocol = new HidePublicAddress(); m_current_protocol->requestStart(); } m_state = HIDING_ADDRESS; break; } case HIDING_ADDRESS: // Wait till we have hidden our address if (!m_current_protocol || m_current_protocol->getState() == PROTOCOL_STATE_TERMINATED) { if(m_current_protocol) { delete m_current_protocol; m_current_protocol = NULL; Log::info("ConnectToServer", "Address hidden"); } m_state = DONE; // lobby room protocol if we're connected only if(STKHost::get()->getPeers()[0]->isConnected()) { Protocol *p = new ClientLobbyRoomProtocol(m_server_address); p->requestStart(); } } break; case DONE: requestTerminate(); m_state = EXITING; break; case EXITING: break; } } // asynchronousUpdate