-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
82 lines (69 loc) · 2.1 KB
/
main.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
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
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <iomanip>
#include <thread>
#include <stdlib.h> // atoi
#include "constant.h"
#include "connections.h"
#include "Membership.h"
using namespace std;
std::ofstream logFile;
/* User thread: Waits for user to input a grep command
When receiving the grep command from command line (test cases uses this),
it will bypass the cin*/
void listeningCin(Membership* m)
{
std::string input;
while (true)
{
std::cout << "Type a command (table, leave, join or quit): ";
getline(std::cin, input);
//std::cout << "You entered: " << input << std::endl;
if (input.compare("quit") == 0 || input.compare("q") == 0)
{
std::cout << "Exiting normally " << std::endl;
break;
}
else if (input.compare("table") == 0 || input.compare("t") == 0)
{
std::cout << m->printMember();
}
else if (input.compare("leave") == 0 || input.compare("l") == 0)
{
m->leave();
}
else if (input.compare("join") == 0 || input.compare("j") == 0)
{
m->join();
}
else if (input.compare("leader") == 0 || input.compare("ml") == 0)
{
std::cout << m->getLeader() << std::endl;
}
else if (input.compare("netstat") == 0 || input.compare("n") == 0)
{
std::cout << "UDP Stats: Sent: " << getUDPSent();
std::cout << " Received: " << getUDPReceived() << std::endl;
}
else{
std::cout << "PLEASE CHECK AGAIN THE POSSIBLE OPTIONS" << std::endl;
}
}
return;
}
int main (int argc, char* argv[])
{
srand (time(NULL));
std::cout << std::endl << "CS425 - MP2: Membership Protocol." ;
std::cout << std::endl << std::endl;
logFile.open("log.log");
logFile << "Inicializing! " << std::endl;
int port = atoi(argv[1]);
bool isIntroducer = atoi(argv[2]);
Membership m(isIntroducer, port);
std::thread cinListening(listeningCin, &m);
cinListening.join();
return 0;
}