-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGTagGenerator.cpp
executable file
·56 lines (46 loc) · 1.48 KB
/
GTagGenerator.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
/*
* File: TagGenerator.cpp
* Author: developer
*
* Created on May 7, 2014, 11:07 PM
*/
#include "GTagGenerator.h"
#include "GTunnelContainer.h"
#include "GLogger.h"
GServer::GTagGenerator::GTagGenerator( GServer::GLogger* logger ) {
// Nustatau objekto pavadinima
this->className = this->className + ":TagGenerator";
// Priskiriu pranesimu isvedimu objekta
this->logger = logger;
// Nustatau kritines reiksmes
this->MIN = 1000;
this->MAX = 65534;
// Nustatau pradine reiksme
this->Reset();
// Pranesu apie objekto sukurima
this->logger->logDebug(this->className, "Objektas sukurtas");
}
GServer::GTagGenerator::~GTagGenerator() {
this->logger->logDebug(this->className, "Objektas sunaikintas");
}
void GServer::GTagGenerator::Reset() {
this->logger->logDebug(this->className, "Nustatau skaitliuka i pradine "
"maziausia reiksme: " + std::to_string(this->MIN));
this->tag = this->MIN;
}
int GServer::GTagGenerator::Generate(GTunnelContainer* tunnels) {
if (this->tag >= MAX)
this->Reset();
// Padidinam paskutine zyme
this->tag = this->tag + 1;
// Tikrinam ar tokia jau yra naudojama
while (tunnels->IsClient(this->tag)) {
// Jei naudojama tada dar didinam
this->tag = this->tag + 1;
if (this->tag >= MAX)
this->Reset();
}
this->logger->logDebug(this->className, "Sugeneruota reiksme: " +
std::to_string(this->tag));
return this->tag;
}