-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathservicemanager.cpp
71 lines (60 loc) · 1.79 KB
/
servicemanager.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
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
/*
* Copyright 2020 Sinodun Internet Technologies Ltd.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <stdexcept>
#include <QDebug>
#include <QRegularExpression>
#include <QMessageBox>
#include "mainwindow.h"
ServiceMgr::ServiceMgr(MainWindow *parent) :
QObject(parent),
m_mainwindow(parent),
m_serviceState(ServiceMgr::Unknown)
{
qInfo("Creating service mgr");
}
ServiceMgr::~ServiceMgr()
{
}
int ServiceMgr::getState() {
//qInfo("gettting state");
return getStateofService();
}
int ServiceMgr::start(ConfigMgr& configMgr)
{
QString message = "Action: Starting Stubby service wtih ";
message.append(configMgr.getCurrentProfileString().c_str());
message.append(" profile...");
m_mainwindow->statusMsg(message);
try {
std::string stubby_yml = configMgr.generateStubbyConfig();
if (stubby_yml.empty()) {
m_mainwindow->statusMsg("ERROR: Configuration generated for the active profile was invalid. Stubby has not been restarted.");
return 1;
}
m_mainwindow->statusMsg("Status: Stubby service configuration generated.");
m_serviceState = Starting;
return startService(QString::fromStdString(stubby_yml));
}
catch(const std::runtime_error& err)
{
qCritical("Error: %s", err.what());
return 1;
}
}
int ServiceMgr::stop()
{
m_mainwindow->statusMsg("Action: Stopping Stubby service...");
m_serviceState = Stopping;
return stopService();
}
int ServiceMgr::restart()
{
m_mainwindow->statusMsg("Action: Re-starting Stubby service...");
m_serviceState = Restarting;
return restartService();
}