-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
77 lines (63 loc) · 1.82 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
#include "client/Client.h"
#include "server/Server.h"
#include <algorithm>
#include <fstream>
#include <iostream>
#include <memory>
#include <cstring>
#include <stdio.h>
void printHelp() {
std::cout << " Server: \n"
" ./StateMachine -server <source_file_name> \n"
" Client \n"
" ./StateMachine -client <target_directory> [-start] \n"
<< std::endl;
}
int main(int argc, char *argv[]) {
bool aIsServer;
if (argc == 1) {
std::cout << "Can' detect server or client option use: [./StateMachine -h]"
<< std::endl;
exit(0);
}
if (strcmp(argv[1], "-h") == 0) {
printHelp();
exit(0);
}
if (strcmp(argv[1], "-server") == 0) {
aIsServer = true;
} else if (strcmp(argv[1], "-client") == 0) {
aIsServer = false;
} else {
std::cout << "Can' detect server or client option [./StateMachine -h]"
<< std::endl;
exit(0);
}
std::unique_ptr<StateMachine> aStateMachine;
if (aIsServer) {
if (argc == 2) {
std::cout << "FileName hasn't been specified [./StateMachine -h]"
<< std::endl;
exit(0);
}
std::string aFileName = argv[2];
aStateMachine = std::make_unique<Server>(aFileName);
} else {
if (argc == 2) {
std::cout << "Target directory hasn't been specified [./StateMachine -h]"
<< std::endl;
exit(0);
}
std::string aTargetDirectory = argv[2];
bool aStartTransfer;
if (argc > 3) {
aStartTransfer = strcmp(argv[3], "-start") == 0;
} else {
aStartTransfer = false;
}
aStateMachine = std::make_unique<Client>(aStartTransfer,aTargetDirectory);
}
std::cout << "Running " << (aIsServer ? "Server" : "Client") << std::endl;
aStateMachine->run();
std::cout << "Shutting down" << std::endl;
}