Ejemplo n.º 1
0
void Server::runLoop(){

timeval timeValue;
char* data;
bool resend = false;
int x;
int y;
timeval returnedTime;


	while(true){

		//sleep(1);//for testng only. Otherwise it is way too fast
		if(!resend){
			//NOTE: TO BE REPLACED WITH SYSTEM CALL TO BLAST BUS SOMEHOW
			gettimeofday(&timeValue, NULL);//gets a time value
			
			if(abs(lagTime.tv_sec - timeValue.tv_sec) > 300){
				updateLag();
				gettimeofday(&timeValue, NULL);
			}
		}
		printf("sending data: %ld seconds, %ld microseconds\n", timeValue.tv_sec, timeValue.tv_usec);
		sendData(timeValue);//sends the query time to the laptop
		resend = false;		
		
		data = recieveData();//recieves the response

		if(!strcmp(data, "resend\n")){//if there was a resend request
			printf("Resending old data\n");
			resend = true;
			free(data);
			continue;
		}else{
			if(!strcmp(data, "")){//if there was an error
				printf("Exiting\n");
				free(data);
				return;
			}
			//extracts data from the string
			sscanf(data, "X=%d;Y=%d;s=%ld;us=%ld\n", &x, &y, &returnedTime.tv_sec, &returnedTime.tv_usec);
			passData(x, y, returnedTime);//passes data back to the blast bus
			free(data);
		}
	}
}
Ejemplo n.º 2
0
void Session::handleMessage(IrcMessage* message)
{
    // 20s delay since the last message was received
    setPingInterval(20);

    if (message->type() == IrcMessage::Join)
    {
        if (message->isOwn())
            addChannel(static_cast<IrcJoinMessage*>(message)->channel());
    }
    else if (message->type() == IrcMessage::Part)
    {
        if (message->isOwn())
            removeChannel(static_cast<IrcPartMessage*>(message)->channel());
    }
    else if (message->type() == IrcMessage::Pong)
    {
        if (message->parameters().contains("_C_o_m_m_u_n_i_"))
        {
            // slow down to 60s intervals
            setPingInterval(60);

            updateLag(static_cast<int>(m_lagTimer.elapsed()));
            m_lagTimer.invalidate();
        }
    }
    else if (message->type() == IrcMessage::Numeric)
    {
        int code = static_cast<IrcNumericMessage*>(message)->code();
        if (code == Irc::RPL_ISUPPORT)
        {
            foreach (const QString& param, message->parameters().mid(1))
            {
                QStringList keyValue = param.split("=", QString::SkipEmptyParts);
                m_info.insert(keyValue.value(0), keyValue.value(1));
            }
            if (m_info.contains("NETWORK"))
                emit networkChanged(network());
            emit serverInfoReceived();
        }