-
Notifications
You must be signed in to change notification settings - Fork 2
/
dogcomcontroller.cpp
48 lines (38 loc) · 1.21 KB
/
dogcomcontroller.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
#include "dogcomcontroller.h"
#include <QDebug>
DogcomController::DogcomController()
{
sleeper = new InterruptibleSleeper();
dogcom = new DogCom(sleeper);
connect(dogcom, &DogCom::ReportOnline, this, &DogcomController::HandleDogcomOnline);
connect(dogcom, &DogCom::ReportOffline, this, &DogcomController::HandleDogcomOffline);
connect(dogcom, &DogCom::ReportIpAddress, this, &DogcomController::HandleIpAddress);
}
DogcomController::~DogcomController(){
if(sleeper!=nullptr) delete sleeper;
if(dogcom!=nullptr) delete dogcom;
}
void DogcomController::Login(const QString &account, const QString &password, const QString &mac_addr) {
qDebug() << "Filling config...";
dogcom->FillConfig(account, password, mac_addr);
qDebug() << "Fill config done.";
dogcom->start();
}
void DogcomController::LogOut()
{
dogcom->Stop();
}
void DogcomController::HandleDogcomOffline(int reason)
{
emit HaveBeenOffline(reason);
}
void DogcomController::HandleDogcomOnline()
{
emit HaveLoggedIn();
}
void DogcomController::HandleIpAddress(unsigned char x1, unsigned char x2, unsigned char x3, unsigned char x4)
{
QString ip = QString::asprintf("%d.%d.%d.%d", x1, x2, x3, x4);
qDebug() << "IP ADDRESS:" << ip;
emit HaveObtainedIp(ip);
}