-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGCommandExecution.h
192 lines (162 loc) · 7.39 KB
/
GCommandExecution.h
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: GCommandExecution.h
* Author: gedas
*
* Created on Šeštadienis, 2016, balandis 23, 14.04
*/
#ifndef GCOMMANDEXECUTION_H
#define GCOMMANDEXECUTION_H
#include "GCommandExecution.h"
#include "GObject.h"
#include "GLogger.h"
#include "GClientContainer.h"
#include "GSocket.h"
#include "GTunnelContainer.h"
#include <map>
namespace GServer {
class GSocket;
class GTagGenerator;
class UDPServerGSocket;
class TCPServerGSocket;
class TCPClientGSocket;
class UDPClientGSocket;
class GCommandExecution : public GObject {
public:
// ##### Kintamieji #####
// ##### END Kintamieji #####
// #####################################################################
// ##### Metodai #####
/*** GCommandExecution ***
* Metodas skirtas sukurti GCommandExecution. Si klase analizuoja ir
* vykdo gautas komandas.
logger- pranesimu isvedimo objektas
tagGenerato- objektas, generuojantis zymas
clients- klientu sarao objektas
clientSocketList- klientu ir socketu sarasas
conf- nuododa i objekta, kuris dirba su konfiguraciniu failu
tunnels- nuoroda i tuneliu saugojimo objekta*/
GCommandExecution(GLogger* logger, GTagGenerator* tagGenerator,
GClientContainer* clients,
std::map<int, GServer::GSocket*>* clientSocketList,
GConfig* conf, GTunnelContainer* tunnels);
virtual ~GCommandExecution();
/*** executeCommand ***
* Metodas ksirtas nuskaityti is buferio komanda ir grazinti atsakyma i
* ta pati buferi. Rezultatas- true, jei pavyko apdoroti komanda, false,
* jei ne
buffer- buferis, kuriame gauti ir apdorojimi duomenys
size- apdoroto atsakymo dydis buferyje
socket- kliento objektas, kuris gavo duomenis */
bool executeCommand(vector<char>& buffer, int& size, GSocket* socket);
/*** registerUDPAccept ***
* Metodas sksirtas uzregistruoti UDP kliento jungti */
void registerUDPAccept(GSocket* udp);
// ##### END Metodai #####
protected:
// ##### Kintamieji #####
/*** clientSocketList ***
* Kintamasis sksirtas saugoti nurooda i klientu ir ju objektu sarasa */
std::map<int, GServer::GSocket*>* clientSocketList;
/*** clientSocketListIterator ***
* Kintamasis sksirtas veikscioti po klientu sarasa clientSocketList */
std::map<int, GServer::GSocket*>::iterator clientSocketListIterator;
// ##### END Kintamieji #####
// #####################################################################
// ##### Metodai #####
// ##### END Metodai #####
private:
// ##### Kintamieji #####
/*** logger ***
* Kintamassis skirtas saugoti nuoroda i pranesimu isvedimo objekta */
GLogger* logger;
/*** tagGenerator ***
* Kintamasis skirtas asugoti nuoroda i zymy generavimo objekta */
GTagGenerator* tagGenerator;
/*** clients ***
* Kintamasis saugo nuoroda i klientu saraso objekta */
GClientContainer* clients;
/*** config ***
* Kintamasis saugnatis nuoroda i objekta, kuris dirba su nustatymu
* failu */
GServer::GConfig* config;
/*** tunnels ***
* Kintamasis skirtas saugoti nuoroda i tuneliu saro objekta */
GServer::GTunnelContainer* tunnels;
// ##### END Kintamieji #####
// #####################################################################
// ##### Metodai #####
/*** analizeHeader ***
* Metodas skirtas nustatyti atejusiu duomenu headerio reiksmems.
* Rezultatas- true, pavykus nustatyti, false- nepavykus
buffer- buferis, kuraime ieskoma
tag- nustatyta tag reiksme
size- nustatyta duomenu dydzio reiksme*/
bool analizeHeader(char* buffer, int& tag, int& size);
/*** analizeCommandHeader ***
* Metodas skirtas nustatyti atejusios koamndos lauku reiksmes.
* Rezultatas- true, pavykus nustatyti, false- nepavykus
buffer- buferis, kuraime ieskoma
command- nustatyta komandos reiksme*/
bool analizeCommandHeader(char* buffer, int& command);
/*** commandHello ***
* Metodas skirtas ivykdyti HELLO komandai. Rezultatas pridetas kliento
* objektas
buffer- buferis, kuriame saugomi duomenys
socket- socketas, kuriame gauta si komanda*/
Client commandHello(char* buffer, int socket);
/*** commandList ***
* Metodas skirtas ivygdyti LIST komanda, kuri grazina klientui
* prisjungusiu kientu sarasa. Rezultatas- suformuotas klientu sarasa
* tame paciame masyve, kuris paduotas komandai
buffer- nuoroda i buferi
duomCount- suformuoto atsakymo duomenu kiekis
socket- kintamasis nusakantis kurios soketo nereikai grazinti*/
void commandList(vector<char>& buffer, int& duomCount, int socket);
/*** commandJsonList ***
* Metodas skirtas ivygdyti JSON_LIST komanda, kuri grazina klientui
* prisjungusiu kientu sarasa. Rezultatas- suformuotas klientu sarasa
* tame paciame masyve, kuris paduotas komandai
buffer- nuoroda i buferi
duomCount- suformuoto atsakymo duomenu kiekis
socket- kintamasis nusakantis kurios soketo nereikai grazinti*/
void commandJsonList(vector<char>& buffer, int& duomCount, int socket);
/*** commandInitCommand ***
* Metodas skirtas inicijuosti sujungimui */
void commandInitCommand(vector<char>& buffer, int& duomCount,
int socket, int& reciverID);
/*** commandInitCommand ***
* Metodas skirtas inicijuosti sujungimui */
void commandJsonInitCommand(vector<char>& buffer, int& duomCount,
int socket, int& reciverID);
/*** commandConnecACK ***
* Metodas skirtas realizuoti CONNECT_AK komandai */
void commandConnecACK(vector<char>& buffer, int& duomCount, int socket,
int& reciverSocket);
/*** commandJsonConnecACK ***
* Metodas skirtas realizuoti CONNECT_AK komandai */
void commandJsonConnecACK(vector<char>& buffer, int& duomCount, int socket,
int& reciverSocket);
/*** commandClientConnect ***
* Metodas skirtasigyvnedinti CLIENT_CONNECT komandai */
void commandClientConnect(vector<char>& buffer, int& duomCount,
int socket, int& reciver);
/*** commandBeginReadAck ***
* Metodas skirtasigyvnedinti CLIENT_CONNECT komandai */
void commandBeginReadAck(vector<char>& buffer, int& duomCount,
int socket, int& reciver);
/*** commandCloseTunnel ***
* Metodas skirtasigyvnedinti CLIENT_CONNECT komandai */
void commandCloseTunnel(vector<char>& buffer, int& duomCount,
int socket, int& reciver);
/*** printClientList ***
* Metodas skirtas isspausdinti klientu sarasa */
void printClientList();
// ##### END Metodai #####
};
}
#endif /* GCOMMANDEXECUTION_H */