Esempio n. 1
0
		void processMessage(const char * buffer, int length){
			std::string message = std::string(buffer, length);

			Json::Reader reader;
			Json::Value jmessage;
			if (!reader.parse(message, jmessage)) {
				std::cerr << "[SIG] error : cannot parse JSON message" << std::endl;
				return;
			}


			std::string func;
			rtc::GetStringFromJsonObject(jmessage,"func", &func);

			if(func.empty()){
				return ; //no command specified, ignore message
			}

			int peerid = -1;
			//Get Client ID
			rtc::GetIntFromJsonObject(jmessage, "peerId", &peerid);

			//If client ID not defined, abort
			if(peerid == -1) return ;

			if(func.compare("ListChannels") == 0){
				processListChannels(peerid, jmessage);
			}else if(func.compare("Connect") == 0){
				processConnect(peerid, jmessage);
			}else if(func.compare("ICECandidate") == 0){
				processICECandidate(peerid, jmessage);
			}else if(func.compare("Answer") == 0){
				processAnswer(peerid, jmessage);
			}
		}
Esempio n. 2
0
void ICServer::processPendingDatagrams()
{
    QByteArray datagram;
    QUdpSocket *socket = isRunning ? udpSocket : testUdpSocket;

    do {
        QHostAddress *address = new QHostAddress;
        datagram.resize(socket->pendingDatagramSize());
        socket->readDatagram(datagram.data(), datagram.size(), address);

        ICMessageHandler *messageHandler = new ICMessageHandler(this);
        connect(messageHandler, SIGNAL(connectionOffer(QString)), this, SLOT(processSidCollision(QString)));
        connect(messageHandler, SIGNAL(serverDiscovery(QHostAddress,QString)), this, SLOT(processDiscovery(QHostAddress,QString)));
        connect(messageHandler, SIGNAL(questionRequest(QHostAddress)), this, SLOT(processRequest(QHostAddress)));
        connect(messageHandler, SIGNAL(answerReady(ICAnswer,QString)), this, SLOT(processAnswer(ICAnswer,QString)));

        ICMessageProcessor *processor = new ICMessageProcessor(messageHandler, *address, datagram);

        QThreadPool::globalInstance()->start(processor);

        qDebug()<< "[1] Received from " << *address << datagram;

        delete address;
    } while (socket->hasPendingDatagrams());
}
Esempio n. 3
0
void Game::makeCpuPlay(){
	char buffer[256];
	char ans[256];

	sprintf(buffer, "cpuPlay(%i, %s).\n", this->currentPlayer, this->tabProlog);
	envia(buffer, strlen(buffer));
	recebe(ans);
	processAnswer(ans);
}
Esempio n. 4
0
void Letterbox::mistakeDetector(const QString &text)
{
	m_keystrokes++;

	QString upperText(text.toUpper());

	if (upperText.length() == 0)
		return;

	for (Dict::WordList::iterator it = (*m_answersIterator).begin(); it != (*m_answersIterator).end(); ++it)
	{
		if (LetterboxSettings::self()->spaceComplete)
		{
			if (upperText[0] == ' ')
			{
				if (!m_submittedAnswers.contains((*it).word))
				{
					processAnswer((*it).word);
					return;
				}
			}
		}
		else
		{
			if ((*it).word.startsWith(upperText) && !m_submittedAnswers.contains((*it).word))
			{
				if (m_mistakeMade)
					statusBar()->clearMessage();

				if (LetterboxSettings::self()->autoCompleteLength > 0)  
					if (upperText.length() == LetterboxSettings::self()->autoCompleteLength)
						processAnswer((*it).word);

				return;
			}
		}
	}

	m_mistakeMade = true;	
	
	statusBar()->showMessage(tr("MISTAKE DETECTED!"), /* show for 2 seconds */ 2000);
}
Esempio n. 5
0
Message *ServerComponent::doCall(Message *msg_in, Message *msg_out, bool sync, int timeout)
{
	if (respondTo(msg_in->destination)) {
		if (msg_in->answer) {
			processAnswer(msg_in);
			return NULL;
		}
		else
		{
			if(!msg_out) {
				msg_out = new Message();
			} else {
				msg_out->clear();
			}
			msg_out->uid = msg_in->uid;
			msg_out->destination = msg_in->source;
			msg_out->source = msg_in->destination;
			msg_out->command = msg_in->command;
			msg_out->answer = true;

			if(isAsync(msg_in))
			{
				 processAsync(msg_in);
				 return NULL;
			}
			else
			{
				Message * answer = process(msg_in, msg_out, true, timeout);
				if (answer)
					answer->write_header();
				return answer;
			}

		}
	} else if (hub) {
		if (sync) {
			return hub->callSync(msg_in, msg_out, timeout);
		} else {
			return hub->call(msg_in, msg_out);
		}
	} else {
		throw string("Cannot route message to destination ") + my_itoa(msg_in->destination);
	}
};
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    resetPortList();

    //////////////////////////////////////////////////// for .svg display
    scene = new QGraphicsScene(this);
    ui->graphicsView->setScene(scene);
    ////////////////////////////////////////////////////

    this->bot = new spherebot();
    Receiver = new rxThread(this->bot);

    penDownAngle = DEFAULTPENDOWN;
    penUpAngle = DEFAULTPENUP;

    layerIndex = 0;

    connect(bot->port,  SIGNAL(readyRead()), Receiver,      SLOT(receiveData()));
    connect(bot,        SIGNAL(dataSent(QString)),this,     SLOT(sendDataUI(QString)));
    connect(bot,        SIGNAL(progressChanged(int)),this,  SLOT(refreshSendProgress(int)));
    //connect(bot,        SIGNAL(fileTransmitted()),this,     SLOT(finishedTransmission()));
    connect(Receiver,   SIGNAL(lineReceived(QString)),this, SLOT(processReceivedData(QString)));
    connect(Receiver,   SIGNAL(lineReceived(QString)),this->bot,  SLOT(processAnswer(QString)));

    initUI();
    initSateMachine();

    if(LoadSettings())
    {
        FitInTimer.setInterval(10);
        FitInTimer.setSingleShot(true);
        connect(&FitInTimer,SIGNAL(timeout()),this,SLOT(fitgraphicsView()));
        FitInTimer.start();
    }

    setWindowTitle("Spherebot Controll");

    qDebug()<<"mainwindow initialised: ";
    connect(restartLayerMsgBox,SIGNAL(accepted()),this,SLOT(hey()));
}
Esempio n. 7
0
void Game::makePlay(GLuint selected){
	char buffer[256];
	char ans[256];
	int i=3;
	//De 1 a size do tabuleiro - BACK-NUMBER
	if(selected >=1 && selected <= this->gameboard->size){
		printf("Back %d\n", selected);
		//comunicação - é pedida a avaliação da jogada
		// caso positivo - desenha a animaçao
		//desenha novo tabuleiro
		sprintf(buffer, "executePlay(%d, %s, %d, %s).\n", this->currentPlayer, "'B'", selected, this->tabProlog);
	}

	//De size+1 até size*2 - 1
	else if(selected >= this->gameboard->size+1 && selected <= (this->gameboard->size*2)){
		int position = selected - this->gameboard->size;
		printf("Front %d", position);
		sprintf(buffer, "executePlay(%d, %s, %d, %s).\n", this->currentPlayer, "'F'", position, this->tabProlog);
	}

	//De size*2 até size*3 - 1
	else if(selected >= (this->gameboard->size)*2+1 && selected <= (this->gameboard->size*3)){
		int position = selected - this->gameboard->size*2;
		printf("Left: %d", position);
		sprintf(buffer, "executePlay(%d, %s, %d, %s).\n", this->currentPlayer, "'L'", position, this->tabProlog);
		//Partir a resposta em tabuleiro - x - y
	}

	//De size*3 até ao fim
	else if(selected >= (this->gameboard->size)*3+1){
		int position = selected - this->gameboard->size*3;
		printf("Right: %d", position);
		sprintf(buffer, "executePlay(%d, %s, %d, %s).\n", this->currentPlayer, "'R'", position, this->tabProlog);
	}
	envia(buffer, strlen(buffer));
	recebe(ans);

	processAnswer(ans);
}
Esempio n. 8
0
void Letterbox::lineEditReturnPressed()
{
	processAnswer(m_lineEdit->text());
}