Modify logging functions to use inbuilt function naming identifiers
[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 #define _POSIX_C_SOURCE 200809L // For strsignal to work
7
8 // --- Standard headers --- //
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <signal.h> // for signal handling
12 #include <string.h> // string functions
13
14 // --- Custom headers --- //
15 #include "log.h"
16 #include "options.h"
17
18 // --- Variable definitions --- //
19 Options g_options; // options passed to program through command line arguments
20
21 // --- Function definitions --- //
22
23 /**
24  * @funct ParseArguments
25  * @purpose Parse command line arguments, set up an options variable
26  * @param argc - Num args
27  * @param argv - Array of args
28  * @param opts - Pointer to options.  &g_options
29  */
30 void ParseArguments(int argc, char ** argv, Options * opts)
31 {
32         opts->program = argv[0]; // program name
33         opts->verbosity = LOGDEBUG; // default log level
34         Log(LOGDEBUG, "Called as %s with %d arguments.", opts->program, argc);
35 }
36
37 /**
38  * @funct SignalHandler
39  * @purpose Handle signals
40  * @param sig - The signal
41  */
42 void SignalHandler(int sig)
43 {
44         // At the moment just always exit.
45         // Call `exit` so that Cleanup will be called to... clean up.
46         Log(LOGWARN, "Got signal %d (%s). Exiting.", sig, strsignal(sig));
47         exit(sig);
48 }
49
50 /**
51  * @funct Cleanup
52  * @purpose Called when program exits
53  */
54 void Cleanup()
55 {
56         Log(LOGDEBUG, "Begin cleanup.");
57         Log(LOGDEBUG, "Finish cleanup.");
58
59 }
60
61 /**
62  * @funct main
63  * @purpose Main entry point; start worker threads, setup signal handling, wait for threads to exit, exit
64  * @param argc - Num args
65  * @param argv - Args
66  * @returns 0 on success, error code on failure
67  */
68 int main(int argc, char ** argv)
69 {
70         ParseArguments(argc, argv, &g_options);
71         return 0;
72 }
73
74

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