-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperator.hpp
More file actions
92 lines (75 loc) · 1.78 KB
/
Operator.hpp
File metadata and controls
92 lines (75 loc) · 1.78 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#pragma once
#ifndef TERMINAL_OPERATOR_HPP
#define TERMINAL_OPERATOR_HPP
/* Terminal: Operator
#include "Operator.hpp"
The operator routes calls/packets to the correct destination,
or provides notification of failure to deliver. However for now
it's basically just a container for Server objects.
*/
#include <string>
#include "Server.hpp"
class Operator
{
public:
Vector <Server*> vServer;
Operator()
{
}
// 0 is no Server for that number.
Server* getServer(std::string _number)
{
for (int i=0;i<vServer.size();++i)
{
if ( vServer(i)->number == _number)
{
return vServer(i);
}
}
return 0;
}
void recievePacket(std::string _packet)
{
}
// return value is any potential rebound packet. Empty string for no response.
std::string sendPacket(std::string address, std::string _packet)
{
std::string _rebound = "";
Server* target = getServer(address);
if (target)
{
_rebound = target->recievePacket(_packet);
}
return _rebound;
}
bool dial(std::string _number)
{
std::cout<<"OPERATOR RECIEVED CALL\n";
for (int i=0;i<vServer.size();++i)
{
std::cout<<"Checking numbers: "<<_number<<" "<<vServer(i)->number<<".\n";
if ( vServer(i)->number == _number)
{
return true;
}
}
return false;
}
std::string servePage(std::string _number)
{
for (int i=0;i<vServer.size();++i)
{
if ( vServer(i)->number == _number)
{
return vServer(i)->servePage();
}
}
return "404";
}
void addServer(Server* server)
{
vServer.push(server);
}
};
Operator op;
#endif