readerthread.cpp
author Markus Bröker <mbroeker@largo.homelinux.org>
Sat, 13 Dec 2008 15:47:44 +0100
changeset 1 9de88b525a59
parent 0 826dd5531eb0
child 4 fdf04a93faeb
permissions -rw-r--r--
missing ui files added

/*
 *  $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;
    }
}