-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage.cpp
More file actions
77 lines (66 loc) · 1.49 KB
/
message.cpp
File metadata and controls
77 lines (66 loc) · 1.49 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "message.h"
#include <QDebug>
Message::Message(QObject *parent) :
QObject(parent)
, m_type(Unknown)
{
}
Message::~Message()
{
}
QByteArray Message::serialize()
{
QByteArray serialized;
serialized.append((char)m_type);
serialized.append(';');
serialized.append(serializeMessagePart());
return serialized;
}
Message *Message::buildMessage(const QByteArray & message)
{
MessageType type = (MessageType)message.at(0);
switch(type)
{
case Capture:
{
return new CaptureMessage;
break;
}
case TimeLapse:
{
QList<QByteArray> messagesData = message.split(';');
if( messagesData.size() != 3)
return 0;
int nbShot = messagesData.at(1).toInt();
int time = messagesData.at(2).toInt();
TimeLapseMessage* message = new TimeLapseMessage(nbShot, time);
return message;
break;
}
default:
{
qDebug() << "Unknown id";
break;
}
}
return 0;
}
CaptureMessage::CaptureMessage(QObject *parent):
Message(parent)
{
m_type = Message::Capture;
}
TimeLapseMessage::TimeLapseMessage(int nbShot, int time, QObject *parent):
Message(parent)
{
m_nbShot = nbShot;
m_time= time;
m_type = Message::TimeLapse;
}
QByteArray TimeLapseMessage::serializeMessagePart()
{
QString nbShot = QString::number(m_nbShot);
QString time = QString::number(m_time);
QString serialized = (nbShot+";"+time);
return serialized.toLatin1();
}