Remove HTTP server, get ready to write basic threaded program
[matches/MCTX3420.git] / rpi / main.c
1 /**
2  * @file main.c
3  * @purpose Entry point to the program, starts threads, handles cleanup on program exit
4  */
5
6 // --- Standard headers --- //
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <signal.h> // for signal handling
10
11 // --- Custom headers --- //
12 #include "options.h"
13
14 // --- Variable definitions --- //
15 Options g_options; // options passed to program through command line arguments
16
17 // --- Function definitions --- //
18
19 /**
20  * @funct ParseArguments
21  * @purpose Parse command line arguments, set up an options variable
22  * @param argc - Num args
23  * @param argv - Array of args
24  * @param opts - Pointer to options.  &g_options
25  */
26 void ParseArguments(int argc, char ** argv, Options * opts)
27 {
28         options.program = argv[0]; // program name
29         options.verbosity = LOGDEBUG; // default log level
30         if (argc > 1)
31                 options.port = atoi(argv[1]); // Allow us change the port for testing (I keep getting "address in use" errors)
32         else
33                 options.port = 8080; // Using 8080 instead of 80 for now because to use 80 you have to run the program as root
34
35         Log(LOGDEBUG, "ParseArguments", "Called as %s with %d arguments.", options.program, argc);
36 }
37
38 /**
39  * @funct SignalHandler
40  * @purpose Handle signals
41  * @param sig - The signal
42  */
43 void SignalHandler(int sig)
44 {
45         // At the moment just always exit.
46         // Call `exit` so that Cleanup will be called to... clean up.
47         Log(LOGWARN, "SignalHandler", "Got signal %d (%s). Exiting.", sig, strsignal(sig));
48         exit(sig);
49 }
50
51 /**
52  * @funct Cleanup
53  * @purpose Called when program exits
54  */
55 void Cleanup()
56 {
57         Log(LOGDEBUG, "Cleanup", "Begin cleanup.");
58         Log(LOGDEBUG, "Cleanup", "Finish cleanup.");
59
60 }
61
62

UCC git Repository :: git.ucc.asn.au