-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
86 lines (69 loc) · 1.78 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
83
84
85
86
#include <iostream>
#include <string>
#include <memory>
#include "asyncPrimeSearching.h"
#include "networkcontroller.h"
#include "commandparser.h"
#include "prime.h"
#include "pal.h"
#include "fileio.h"
// Global program state
// (Currently used for signal handlers)
AllPrimebotSettings ProgramSettings;
NetworkController* Controller = nullptr;
Primebot* Bot = nullptr;
int main(int argc, char** argv)
{
/*
mpz_class a = 3;
mpz_class b = 5000;
auto primes = findPrimes(8, a, b);
for (auto v : primes)
std::cout << v.get_str() << std::endl; //TODO: strange bug isn't linking operator<< properly.
int dummy = 0;
std::cin >> dummy;
return 0;
*/
CommandParser Parse(argc, argv);
ProgramSettings = Parse.ParseArguments();
if (!ProgramSettings.Run)
{
return EXIT_FAILURE;
}
if (!RegisterSignalHandler())
{
return EXIT_FAILURE;
}
if (ProgramSettings.NetworkSettings.Server)
{
// Configure for Server
NetworkController netsrv(ProgramSettings);
Controller = &netsrv;
netsrv.Start();
}
else if(ProgramSettings.NetworkSettings.Client)
{
// Configure for client
NetworkController netcon(ProgramSettings);
Primebot pb(ProgramSettings, &netcon);
Bot = &pb;
netcon.SetPrimebot(&pb);
pb.Start();
pb.WaitForStop();
}
else if (ProgramSettings.FileSettings.Flags.Print)
{
PrimeFileIo PrimeIo(ProgramSettings);
PrimeIo.PrintPrimes();
}
else
{
// Configure standalone
Primebot pb(ProgramSettings, nullptr);
Bot = &pb;
pb.Start();
// Only way to stop is to CTRL+C, but shutdown cleanly anyway
pb.WaitForStop();
}
return EXIT_SUCCESS;
}