forked from Goles/cChord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
84 lines (75 loc) · 2.12 KB
/
main.cc
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
using namespace std;
#include "lib/TextHandler.hh"
#include "lib/Modification.hh"
#include <stdlib.h>
#include <protocols/ProtocolSingleton.h>
// This application receives args, "ip", "port" [, "ip2", "port2"]
int main(int argc, char * const argv[]) {
Modification m(time(NULL),"coucou",0,1);
string s;
m.applyTo(s);
cout << "s : '" << s << "'" << endl;
m.cancelOn(s);
cout << "s : '" << s << "'" << endl;
cout << m << endl;
stringstream ss;
ss << m;
Modification m2;
m2 << ss;
cout << m2 << endl;
if(argc<3) {
cout << "usage : " << argv[0] << " myIp myPort [otherIp otherPort]" << endl;
return EXIT_SUCCESS;
}
TextHandler *th = new TextHandler(argv[1], atoi(argv[2]));
P_SINGLETON->setProtocolNode(th);
if(argc>4) {
cout << "connecting to " << argv[3] << ":" << argv[4] << endl;
th->connect(argv[3], atoi(argv[4]));
}
int chx;
bool quit = false;
int pos;
string value;
while (!quit) { // sleep...
cout << "0) Print status" << endl
<< "1) Insert Text" << endl
<< "2) Display Text" << endl
<< "3) Erase Test" << endl
<< "4) Exit" << endl
/*<< "5) Cancel" << endl*/;
cout << "---> ";
cin >> chx;
switch (chx) {
case 0:
cout << th->printStatus();
break;
case 1:
cout << "Pos = ";
cin >> pos;
cout << "Value = ";
cin >> value;
th->insertText(pos, value);
break;
case 2:
cout << th->getText() << endl;
break;
case 3:
cout << "pos = ";
cin >> pos;
cin >> value;
th->insertText(pos, value, true);
break;
case 4:
th->shutDown();
quit = true;
break;
//case 5:
// th->;
// break;
default:
break;
}
}
delete th;
}