void DispositivosThread::run(){
    mutex->lock();

    QFile reader("/proc/mounts");
    reader.open(QFile::ReadOnly | QFile::Text);
    QString contents = reader.readAll();
    reader.close();

    emit finishedReading(contents);
}
void InterruptsThread::run(){
    mutex->lock();

    QFile reader("/proc/interrupts");
    reader.open(QFile::ReadOnly | QFile::Text);
    //lectura del archivo que proporsciona informacion del sistema, esta lectura es la que va a cambiar con cada hilo
    QString contents = reader.readAll();
    reader.close();
    //Se emite la señal, indica que el hilo ya termino su objetivo
    emit finishedReading(contents);
}
ConsoleMaster::ConsoleMaster()
  :
  connected_(false),
  window_font_(QFont("Ubuntu Mono", 9))
{
  // The RosThread takes advantage of queued connections when emitting log messages
  // to ensure that the messages are processed in the console window's event thread.
  // In order for that to work, we have to manually register the message type with
  // Qt's QMetaType system.
  qRegisterMetaType<rosgraph_msgs::LogConstPtr>("rosgraph_msgs::LogConstPtr");

  QObject::connect(&bag_reader_, SIGNAL(logReceived(const rosgraph_msgs::LogConstPtr& )),
                   &db_, SLOT(queueMessage(const rosgraph_msgs::LogConstPtr&) ));
  QObject::connect(&bag_reader_, SIGNAL(finishedReading()),
                   &db_, SLOT(processQueue()));
}
Exemple #4
0
void Connection::read() {
    if (finishedReading()) {
        this->reading = Reading::LENGTH;
        this->reader = this->getLengthReader();
    }

    this->reader->readNextChunk();

    if (this->reader->finished()) {
        switch (this->reading) {
            case Reading::LENGTH:
                this->messageLength = (
                        (PrimitiveTypeReader<uint16_t >*)this->reader
                )->getValue();

                this->messageLength = ntohs(this->messageLength);

                delete this->reader;

                if (this->messageLength > 1000) {
                    throw invalid_message_error("message is too long");
                } else if (this->messageLength == 0) {
                    this->message = "";
                    this->reading = Reading::NOTHING;
                } else {
                    this->reader = getMessageReader();
                    this->reading = Reading::MESSAGE;
                }

                break;
            case Reading::MESSAGE:
                this->message = ((StringReader*)this->reader)->getValue();
                delete this->reader;
                this->reading = Reading::NOTHING;
                break;
            case Reading::NOTHING:
                throw std::logic_error("we cannot be reading nothing here!");
        }
    }
}
/**
 * @brief Called when new data is received on the associated socket, if sufficient data is available, it will call the virtual method handleMessage(int)
 */
void AbstractProtocol::newData()
{
    if (!active) {
        return;
    }

    qDebug() << "**** Start data ****";

    while (1) {


        qDebug() << "new data total size: " << socket->bytesAvailable();
        if (!headerRead) {
            if (socket->bytesAvailable() < SIZE_HEADER) {
                break;
            } else {
                header.read(socket);
                headerRead = true;
                qDebug() << "size: " << header.data.size;
                qDebug() << "Type: " << header.data.type;
            }
        }


        if (socket->bytesAvailable() < header.data.size) {
            break;
        }

        headerRead = false;
        int type = header.data.type;
        handleMessage(type);
        if (finishedReading()) {
            break;
        }
    }

    qDebug() << "**** End data *****";

}
void InterruptWindow::createThread(){
    InterruptsThread *hilo = new InterruptsThread(this,mutex);
    hilo->start();
    //Se conecta una señal que emite el hilo al terminar, y se cacha en un SLOT (entrada) del metodo mencionado:
    connect(hilo,SIGNAL(finishedReading(QString)),this,SLOT(onFinishedReading(QString)));
}