-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboothservice.cpp
More file actions
64 lines (55 loc) · 1.61 KB
/
boothservice.cpp
File metadata and controls
64 lines (55 loc) · 1.61 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
#include "boothservice.h"
#include "servicecategory.h"
#include "datamodel.h"
#include <stdio.h>
#include <QSettings>
#include <QDebug>
BoothService::BoothService(char iid)
: Booth(STB_ALIAS_SERVICEBOOTH, iid),
free(false),
online(false)
{
QSettings settings;
settings.beginReadArray("service_booth");
settings.setArrayIndex(iid);
char catID = settings.value("category", "A").toInt();
settings.endArray();
qDebug() << "Creating service booth "<<iid<< " with category " << catID;
serviceCategory = ServiceCategory::instance(catID);
}
Packet BoothService::getPingPacket() {
Packet packet;
if(isFree() && serviceCategory->isUserWaiting()) {
packet = getSkeletonPacket(STB_SERVER_NEW_USER);
sprintf(tokenStr, "%c%04d", serviceCategory->getCategoryID(), serviceCategory->getNextWaitingUserID());
DataModel::serviceStarted(tokenStr, getID());
strncpy(packet.data(), tokenStr, 5);
} else {
packet = getSkeletonPacket(STB_SERVER_PING_SERVICE);
}
return packet;
}
bool BoothService::processPacket(Packet &packet) {
bool nowFree = isFree();
switch(packet.commandType()) {
case STB_SERVICE_FREE:
isFree() = true;
if(!nowFree) {
DataModel::serviceStopped(tokenStr);
return true;
}
break;
case STB_SERVICE_BUSY:
isFree() = false;
break;
case STB_SERVICE_TAKEN_USER:
serviceCategory->removeWaitingUser();
isFree() = false;
break;
}
isOnline() = true;
return false;
}
void BoothService::onTimeout() {
isOnline() = false;
}