-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
93 lines (87 loc) · 3.06 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
87
88
89
90
91
92
93
// ======================================================================
// \title Main.cpp
// \brief main program for the F' application. Intended for CLI-based systems (Linux, macOS)
//
// ======================================================================
// Used to access topology functions
#include <TestDeployment/Top/TestDeploymentTopology.hpp>
// OSAL initialization
#include <Os/Os.hpp>
// Used for signal handling shutdown
#include <signal.h>
// Used for command line argument processing
#include <getopt.h>
// Used for printf functions
#include <cstdlib>
/**
* \brief print command line help message
*
* This will print a command line help message including the available command line arguments.
*
* @param app: name of application
*/
void print_usage(const char* app) {
(void)printf("Usage: ./%s [options]\n-a\thostname/IP address\n-p\tport_number\n", app);
}
/**
* \brief shutdown topology cycling on signal
*
* The reference topology allows for a simulated cycling of the rate groups. This simulated cycling needs to be stopped
* in order for the program to shutdown. This is done via handling signals such that it is performed via Ctrl-C
*
* @param signum
*/
static void signalHandler(int signum) {
TestDeployment::stopSimulatedCycle();
}
/**
* \brief execute the program
*
* This F´ program is designed to run in standard environments (e.g. Linux/macOs running on a laptop). Thus it uses
* command line inputs to specify how to connect.
*
* @param argc: argument count supplied to program
* @param argv: argument values supplied to program
* @return: 0 on success, something else on failure
*/
int main(int argc, char* argv[]) {
I32 option = 0;
CHAR* hostname = nullptr;
U16 port_number = 0;
Os::init();
// Loop while reading the getopt supplied options
while ((option = getopt(argc, argv, "hp:a:")) != -1) {
switch (option) {
// Handle the -a argument for address/hostname
case 'a':
hostname = optarg;
break;
// Handle the -p port number argument
case 'p':
port_number = static_cast<U16>(atoi(optarg));
break;
// Cascade intended: help output
case 'h':
// Cascade intended: help output
case '?':
// Default case: output help and exit
default:
print_usage(argv[0]);
return (option == 'h') ? 0 : 1;
}
}
// Object for communicating state to the reference topology
TestDeployment::TopologyState inputs;
inputs.hostname = hostname;
inputs.port = port_number;
// Setup program shutdown via Ctrl-C
signal(SIGINT, signalHandler);
signal(SIGTERM, signalHandler);
(void)printf("Hit Ctrl-C to quit\n");
// Setup, cycle, and teardown topology
TestDeployment::setupTopology(inputs);
TestDeployment::startSimulatedCycle(Fw::TimeInterval(1,0)); // Program loop cycling rate groups at 1Hz
TestDeployment::teardownTopology(inputs);
(void)printf("Exiting...\n");
return 0;
}