GCC Code Coverage Report


Directory: ./
File: Ref/Main.cpp
Date: 2026-09-03 22:12:29
Exec Total Coverage
Lines: 26 32 81.2%
Functions: 2 3 66.7%
Branches: 11 13 84.6%

Line Branch Exec Source
1 // ======================================================================
2 // \title Main.cpp
3 // \author mstarch
4 // \brief main program for reference application. Intended for CLI-based systems (Linux, macOS)
5 //
6 // \copyright
7 // Copyright 2009-2022, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 // ======================================================================
11 // Used to access topology functions
12 #include <Ref/Top/RefTopology.hpp>
13 // Used for signal handling shutdown
14 #include <signal.h>
15 // Used for command line argument processing
16 #include <getopt.h>
17 // Used for atoi
18 #include <cstdlib>
19 // Used to get the Os::Console
20 #include <Os/Os.hpp>
21 // Used for logging to the console
22 #include <Fw/Logger/Logger.hpp>
23
24 /**
25 * \brief print commandline help message
26 *
27 * This will print a command line help message including the available command line arguments.
28 *
29 * @param app: name of application
30 */
31 void print_usage(const char* app) {
32 Fw::Logger::log("Usage: ./%s [options]\n-a\thostname/IP address\n-p\tport_number\n", app);
33 }
34
35 /**
36 * \brief shutdown topology cycling on signal
37 *
38 * The reference topology allows for a simulated cycling of the rate groups. This simulated cycling needs to be stopped
39 * in order for the program to shutdown. This is done via handling signals such that it is performed via Ctrl-C
40 *
41 * @param signum
42 */
43 1 static void signalHandler(int signum) {
44 1 Ref::stopRateGroups();
45 1 }
46
47 /**
48 * \brief execute the program
49 *
50 * This F´ program is designed to run in standard environments (e.g. Linux/macOs running on a laptop). Thus it uses
51 * command line inputs to specify how to connect.
52 *
53 * @param argc: argument count supplied to program
54 * @param argv: argument values supplied to program
55 * @return: 0 on success, something else on failure
56 */
57 1 int main(int argc, char* argv[]) {
58
1/1
✓ Branch 1 taken 1 times.
1 Os::init();
59 1 U16 port_number = 0;
60 1 I32 option = 0;
61 1 char* hostname = nullptr;
62
63 // Loop while reading the getopt supplied options
64
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
3 while ((option = getopt(argc, argv, "hp:a:")) != -1) {
65
2/3
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 switch (option) {
66 // Handle the -a argument for address/hostname
67 1 case 'a':
68 1 hostname = optarg;
69 1 break;
70 // Handle the -p port number argument
71 1 case 'p':
72 1 port_number = static_cast<U16>(atoi(optarg));
73 1 break;
74 // Cascade intended: help output
75 case 'h':
76 // Cascade intended: help output
77 case '?':
78 // Default case: output help and exit
79 default:
80 print_usage(argv[0]);
81 return (option == 'h') ? 0 : 1;
82 }
83 }
84 // Object for communicating state to the reference topology
85 Ref::TopologyState inputs;
86 1 inputs.hostname = hostname;
87 1 inputs.port = port_number;
88
89 // Setup program shutdown via Ctrl-C
90 1 signal(SIGINT, signalHandler);
91 1 signal(SIGTERM, signalHandler);
92
1/1
✓ Branch 1 taken 1 times.
1 Fw::Logger::log("Hit Ctrl-C to quit\n");
93
94 // Setup, cycle, and teardown topology
95
1/1
✓ Branch 1 taken 1 times.
1 Ref::setupTopology(inputs);
96
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
1 Ref::startRateGroups(Fw::TimeInterval(1, 0)); // Program loop cycling rate groups at 1Hz
97
1/1
✓ Branch 1 taken 1 times.
1 Ref::teardownTopology(inputs);
98
1/1
✓ Branch 1 taken 1 times.
1 Fw::Logger::log("Exiting...\n");
99 1 return 0;
100 }
101