readerthread.cpp
author Markus Bröker <mbroeker@largo.homelinux.org>
Sat, 13 Dec 2008 15:45:18 +0100
changeset 0 826dd5531eb0
child 4 fdf04a93faeb
permissions -rw-r--r--
svn copy of qmonitor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     1
/*
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     2
 *  $Id: readerthread.cpp 54 2008-01-10 00:24:52Z mbroeker $
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     3
 * $URL: http://localhost/svn/cpp/qMonitor/trunk/readerthread.cpp $
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     4
 */
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     5
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     6
#include "include/readerthread.h"
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     7
#include <exception>
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     8
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     9
readerThread::readerThread (Monitor * parent)
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    10
{
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    11
    handle = parent;
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    12
}
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    13
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    14
void readerThread::run ()
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    15
{
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    16
    std::string s;
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    17
    DataChangeEvent *dce;
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    18
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    19
    try {
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    20
        PacketParser reader (-1);
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    21
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    22
        for (;;) {
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    23
            while (reader.dataAvailable ()) {
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    24
                reader.setProtocol (handle->getProtocol ());
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    25
                reader.setPort (handle->getPort ());
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    26
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    27
                s = reader.read ();
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    28
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    29
                if (s != "") {
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    30
                    dce = new DataChangeEvent (s.c_str ());
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    31
                    QApplication::postEvent ((QObject *) handle, (QEvent *) dce);
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    32
                }
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    33
            }
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    34
        }
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    35
    }
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    36
    catch (std::exception const &e) {
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    37
        dce = new DataChangeEvent (e.what ());
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    38
        QApplication::postEvent ((QObject *) handle, (QEvent *) dce);
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    39
        std::cerr << e.what () << std::endl;
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    40
    }
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    41
}