readerthread.cpp
author Markus Bröker <mbroeker@largo.homelinux.org>
Tue, 02 Feb 2010 13:26:30 +0100
changeset 8 6097dc1fe2cf
parent 4 fdf04a93faeb
permissions -rw-r--r--
perror is declared in cstdio

/*
 *  $Id: readerthread.cpp 54 2008-01-10 00:24:52Z mbroeker $
 * $URL: http://localhost/svn/cpp/qMonitor/trunk/readerthread.cpp $
 */

#include "include/readerthread.h"
#include <exception>

readerThread::readerThread (Monitor * parent)
{
    handle = parent;
}

void readerThread::run ()
{
    std::string s;
    DataChangeEvent *dce;

    try {
        PacketParser reader (-1);

        for (;;) {
            while (reader.dataAvailable ()) {
                reader.setProtocol (handle->getProtocol ());
                reader.setPort (handle->getPort ());

                s = reader.read ();

                if (s != "") {
                    dce = new DataChangeEvent (s.c_str ());
                    QApplication::postEvent ((QObject *) handle, (QEvent *) dce);
                }
            }
        }
    } catch (std::exception const &e) {
        dce = new DataChangeEvent (e.what ());
        QApplication::postEvent ((QObject *) handle, (QEvent *) dce);
        std::cerr << e.what () << std::endl;
    }
}