-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessagehandler.cpp
46 lines (40 loc) · 1.41 KB
/
messagehandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*************************************************************************
**
** (C) Copyright 2013 Reach Technology Inc.
**
** This code is protected by international copyright laws. This file may
** only be used in accordance with a license and cannot be used on
** hardware other than supplied by Reach Technology Inc. We appreciate
** your understanding and fairness.
**
*************************************************************************/
#include "messagehandler.h"
MessageHandler::MessageHandler(QObject *parent) :
QObject(parent)
{
}
void MessageHandler::onMessageAvailable(QByteArray ba)
{
//trim \r\n characters
ba.replace('\n', "");
ba.replace('\r', "");
QByteArray msg(ba);
//check for empty message
if (msg.startsWith('\0')) {
qDebug() << "[QML] message handler: null message";
return;
}
if (msg.contains("=") && msg.contains(".")) {
QList<QByteArray> value = msg.split('=');
QList<QByteArray> item = value[0].split('.');
if(value.count() != 2 && item.count() != 2) {
emit messageSyntaxError(msg);
} else {
emit messageAvailable(QString(item[0]),QString(item[1]),QVariant(value[1]));
qDebug() << "[QML] item available: " << item[0] << item [1] << value[1];
}
} else {
emit messageSyntaxError(msg);
qDebug() << "[QML] invalid message: " << msg;
}
}