Changeset View
Changeset View
Standalone View
Standalone View
core/backends/devicelinereader.cpp
Context not available. | |||||
23 | 23 | | |||
---|---|---|---|---|---|
24 | DeviceLineReader::DeviceLineReader(QIODevice* device, QObject* parent) | 24 | DeviceLineReader::DeviceLineReader(QIODevice* device, QObject* parent) | ||
25 | : QObject(parent) | 25 | : QObject(parent) | ||
26 | , mDevice(device) | 26 | , m_device(device) | ||
27 | { | 27 | { | ||
28 | connect(mDevice, SIGNAL(readyRead()), | 28 | connect(m_device, SIGNAL(readyRead()), | ||
29 | this, SLOT(dataReceived())); | 29 | this, SLOT(dataReceived())); | ||
30 | connect(mDevice, SIGNAL(disconnected()), | 30 | connect(m_device, SIGNAL(disconnected()), | ||
31 | this, SIGNAL(disconnected())); | 31 | this, SIGNAL(disconnected())); | ||
32 | } | 32 | } | ||
33 | 33 | | |||
34 | void DeviceLineReader::dataReceived() | 34 | void DeviceLineReader::dataReceived() | ||
35 | { | 35 | { | ||
36 | while(mDevice->canReadLine()) { | 36 | while(m_device->canReadLine()) { | ||
37 | const QByteArray line = mDevice->readLine(); | 37 | const QByteArray line = m_device->readLine(); | ||
38 | if (line.length() > 1) { | 38 | if (line.length() > 1) { | ||
39 | mPackages.enqueue(line);//we don't want single \n | 39 | m_packages.enqueue(line);//we don't want single \n | ||
40 | } | 40 | } | ||
41 | } | 41 | } | ||
42 | 42 | | |||
43 | //If we still have things to read from the device, call dataReceived again | 43 | //If we still have things to read from the device, call dataReceived again | ||
44 | //We do this manually because we do not trust readyRead to be emitted again | 44 | //We do this manually because we do not trust readyRead to be emitted again | ||
45 | //So we call this method again just in case. | 45 | //So we call this method again just in case. | ||
46 | if (mDevice->bytesAvailable() > 0) { | 46 | if (m_device->bytesAvailable() > 0) { | ||
47 | QMetaObject::invokeMethod(this, "dataReceived", Qt::QueuedConnection); | 47 | QMetaObject::invokeMethod(this, "dataReceived", Qt::QueuedConnection); | ||
48 | return; | 48 | return; | ||
49 | } | 49 | } | ||
50 | 50 | | |||
51 | //If we have any packages, tell it to the world. | 51 | //If we have any packages, tell it to the world. | ||
52 | if (!mPackages.isEmpty()) { | 52 | if (!m_packages.isEmpty()) { | ||
53 | Q_EMIT readyRead(); | 53 | Q_EMIT readyRead(); | ||
54 | } | 54 | } | ||
55 | } | 55 | } | ||
Context not available. |