Heart 1.3.842.34c2ab5
Heart is base back end library for your c++ Qt projects.
workstate.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2024 QuasarApp.
3 * Distributed under the lgplv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
8#include "workstate.h"
9
10#include <hostaddress.h>
11
12namespace QH{
13
14bool WorkState::IsRun() const {
15 return isRun;
16}
17
18void WorkState::setIsRun(bool value) {
19 isRun = value;
20}
21
22const QList<HostAddress> &WorkState::getConnections() const {
23 return _connections;
24}
25
26void WorkState::setConnections(const QList<HostAddress> &connections) {
27 _connections = connections;
28}
29
30const QList<HostAddress> &WorkState::activeConnections() const {
31 return _activeConnections;
32}
33
34void WorkState::setActiveConnections(const QList<HostAddress> &newActiveConnections) {
35 _activeConnections = newActiveConnections;
36}
37
38QString WorkState::getWorkStateString() const {
39 if (isRun) {
40 if (_activeConnections.size() >= maxConnectionCount)
41 return "overload";
42 else {
43 return "Work";
44 }
45 }
46
47 return "Not running";
48}
49
51
52QString WorkState::toString() const {
53 QString result("State: %0 \n"
54 "Connections: %1 \n"
55 "Actived connections: %2 / %3 \n"
56 "Connected Addresses:\n"
57 "%4 \n"
58 "Baned: \n "
59 "%5");
60
61 result = result.arg(getWorkStateString()).
62 arg(_connections.size()).
63 arg(_activeConnections.size()).
64 arg(maxConnectionCount);
65
66 QString connections;
67 for (const auto &i: _activeConnections) {
68 connections += i.toString() + "\n";
69 }
70
71 result = result.arg(connections);
72
73 QString BanedList;
74 for (const auto &i: _banedList) {
75 BanedList += i.toString() + "\n";
76 }
77
78 result = result.arg(BanedList);
79
80 return result;
81}
82
84 return maxConnectionCount;
85}
86
88 maxConnectionCount = value;
89}
90
91QList<HostAddress> WorkState::getBanedList() const {
92 return _banedList;
93}
94
95void WorkState::setBanedList(const QList<HostAddress> &banedList) {
96 _banedList = banedList;
97}
98}
99
QList< HostAddress > getBanedList() const
getBanedList This method return banned list of server.
Definition workstate.cpp:91
void setActiveConnections(const QList< HostAddress > &newActiveConnections)
setActiveConnections this method sets new list of active connections.
Definition workstate.cpp:34
void setMaxConnectionCount(int value)
setMaxConnectionCount this method set a new value of limit of connections.
Definition workstate.cpp:87
const QList< HostAddress > & getConnections() const
getConnections This method return list of the current server connections.
Definition workstate.cpp:22
void setIsRun(bool value)
setIsRun This method set new value for run flag.
Definition workstate.cpp:18
bool IsRun() const
getIsRun This method return true if server is runed.
Definition workstate.cpp:14
void setBanedList(const QList< HostAddress > &banedList)
setBanedList -this method set banned list for this object.
Definition workstate.cpp:95
int getMaxConnectionCount() const
getMaxConnectionCount This method return of limit of connections.
Definition workstate.cpp:83
void setConnections(const QList< HostAddress > &connections)
setConnections This method sets connections list.
Definition workstate.cpp:26
WorkState()
WorkState.
Definition workstate.cpp:50
const QList< HostAddress > & activeConnections() const
activeConnections This method return list of actived connections.
Definition workstate.cpp:30
QString toString() const
toString This method convert state of work to string value.
Definition workstate.cpp:52
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition heart.cpp:13