-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkServer.h
More file actions
75 lines (61 loc) · 2.42 KB
/
Copy pathNetworkServer.h
File metadata and controls
75 lines (61 loc) · 2.42 KB
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
#ifndef NETWORK_SERVER_H
#define NETWORK_SERVER_H
#include <unordered_map>
#include <memory>
#include<map>
#include <string>
#include "NetworkServiceDescriptor.h"
class NetworkServer {
private:
std::string networkAddress;
std::string networkName;
double costPerMinute;
double costPerMB;
std::map<std::string, NetworkServiceDescriptor*> connectionTable;
public:
NetworkServer(const std::string &address, const std::string &name, double costMinute, double costMB)
: networkAddress(address), networkName(name), costPerMinute(costMinute), costPerMB(costMB) {}
// Getters
std::string getNetworkAddress() const { return networkAddress; }
double getCostPerMinute() const { return costPerMinute; }
double getCostPerMB() const { return costPerMB; }
// Add/Delete/Find connection
void addConnection(const std::string& address, NetworkServiceDescriptor* descriptor) {
if (connectionTable.find(address) != connectionTable.end()) {
std::cerr << "Îøèáêà: Ñîåäèíåíèå ñ àäðåñîì " << address << " óæå ñóùåñòâóåò." << std::endl;
} else {
connectionTable[address] = descriptor;
}
}
void deleteConnection(const std::string& address) {
auto it = connectionTable.find(address);
if (it == connectionTable.end()) {
std::cerr << "Îøèáêà: Ñîåäèíåíèå ñ àäðåñîì " << address << " íå íàéäåíî." << std::endl;
} else {
connectionTable.erase(it);
}
}
NetworkServiceDescriptor* findConnection(const std::string& address) {
auto it = connectionTable.find(address);
if (it == connectionTable.end()) {
std::cerr << "Îøèáêà: Ñîåäèíåíèå ñ àäðåñîì " << address << " íå íàéäåíî." << std::endl;
return nullptr;
} else {
return it->second;
}
}
void displayAllConnections() {
if (connectionTable.empty()) {
std::cout << "Íåò àêòèâíûõ ñîåäèíåíèé." << std::endl;
return;
}
std::cout << "Àêòèâíûå ñîåäèíåíèÿ:" << std::endl;
for (const auto& pair : connectionTable) {
std::cout << "Àäðåñ: " << pair.first
<< ", Ñåðâèñ: " << pair.second->getServiceType()
// Äîïîëíèòåëüíûå äåòàëè ñîåäèíåíèÿ
<< std::endl;
}
}
};
#endif // NETWORK_SERVER_H