|
1 | 1 | /* |
2 | | -* (c) Copyright, Real-Time Innovations, 2025. All rights reserved. |
3 | | -* RTI grants Licensee a license to use, modify, compile, and create derivative |
4 | | -* works of the software solely for use with RTI Connext DDS. Licensee may |
5 | | -* redistribute copies of the software provided that all such copies are subject |
6 | | -* to this license. The software is provided "as is", with no warranty of any |
7 | | -* type, including any warranty for fitness for any purpose. RTI is under no |
8 | | -* obligation to maintain or support the software. RTI shall not be liable for |
9 | | -* any incidental or consequential damages arising out of the use or inability |
10 | | -* to use the software. |
11 | | -*/ |
| 2 | + * (c) Copyright, Real-Time Innovations, 2025. All rights reserved. |
| 3 | + * RTI grants Licensee a license to use, modify, compile, and create derivative |
| 4 | + * works of the software solely for use with RTI Connext DDS. Licensee may |
| 5 | + * redistribute copies of the software provided that all such copies are subject |
| 6 | + * to this license. The software is provided "as is", with no warranty of any |
| 7 | + * type, including any warranty for fitness for any purpose. RTI is under no |
| 8 | + * obligation to maintain or support the software. RTI shall not be liable for |
| 9 | + * any incidental or consequential damages arising out of the use or inability |
| 10 | + * to use the software. |
| 11 | + */ |
12 | 12 |
|
13 | 13 | #ifndef APPLICATION_H |
14 | 14 | #define APPLICATION_H |
|
19 | 19 |
|
20 | 20 | namespace application { |
21 | 21 |
|
22 | | - // Catch control-C and tell application to shut down |
23 | | - bool shutdown_requested = false; |
| 22 | +// Catch control-C and tell application to shut down |
| 23 | +bool shutdown_requested = false; |
24 | 24 |
|
25 | | - inline void stop_handler(int) |
26 | | - { |
27 | | - shutdown_requested = true; |
28 | | - std::cout << "preparing to shut down..." << std::endl; |
29 | | - } |
| 25 | +inline void stop_handler(int) |
| 26 | +{ |
| 27 | + shutdown_requested = true; |
| 28 | + std::cout << "preparing to shut down..." << std::endl; |
| 29 | +} |
30 | 30 |
|
31 | | - inline void setup_signal_handlers() |
32 | | - { |
33 | | - signal(SIGINT, stop_handler); |
34 | | - signal(SIGTERM, stop_handler); |
35 | | - } |
| 31 | +inline void setup_signal_handlers() |
| 32 | +{ |
| 33 | + signal(SIGINT, stop_handler); |
| 34 | + signal(SIGTERM, stop_handler); |
| 35 | +} |
36 | 36 |
|
37 | | - enum ParseReturn { PARSE_RETURN_OK, PARSE_RETURN_FAILURE, PARSE_RETURN_EXIT }; |
| 37 | +enum ParseReturn { PARSE_RETURN_OK, PARSE_RETURN_FAILURE, PARSE_RETURN_EXIT }; |
38 | 38 |
|
39 | | - struct ApplicationArguments { |
40 | | - ParseReturn parse_result; |
41 | | - unsigned int domain_id; |
42 | | - unsigned int sample_count; |
43 | | - NDDS_Config_LogVerbosity verbosity; |
44 | | - }; |
| 39 | +struct ApplicationArguments { |
| 40 | + ParseReturn parse_result; |
| 41 | + unsigned int domain_id; |
| 42 | + unsigned int sample_count; |
| 43 | + NDDS_Config_LogVerbosity verbosity; |
| 44 | +}; |
45 | 45 |
|
46 | | - inline void set_verbosity( |
47 | | - ApplicationArguments& arguments, |
48 | | - int verbosity) |
49 | | - { |
50 | | - switch (verbosity) { |
51 | | - case 0: |
52 | | - arguments.verbosity = NDDS_CONFIG_LOG_VERBOSITY_SILENT; |
53 | | - break; |
54 | | - case 1: |
55 | | - arguments.verbosity = NDDS_CONFIG_LOG_VERBOSITY_ERROR; |
56 | | - break; |
57 | | - case 2: |
58 | | - arguments.verbosity = NDDS_CONFIG_LOG_VERBOSITY_WARNING; |
59 | | - break; |
60 | | - case 3: |
61 | | - arguments.verbosity = NDDS_CONFIG_LOG_VERBOSITY_STATUS_ALL; |
62 | | - break; |
63 | | - default: |
64 | | - arguments.verbosity = NDDS_CONFIG_LOG_VERBOSITY_ERROR; |
65 | | - break; |
66 | | - } |
| 46 | +inline void set_verbosity(ApplicationArguments &arguments, int verbosity) |
| 47 | +{ |
| 48 | + switch (verbosity) { |
| 49 | + case 0: |
| 50 | + arguments.verbosity = NDDS_CONFIG_LOG_VERBOSITY_SILENT; |
| 51 | + break; |
| 52 | + case 1: |
| 53 | + arguments.verbosity = NDDS_CONFIG_LOG_VERBOSITY_ERROR; |
| 54 | + break; |
| 55 | + case 2: |
| 56 | + arguments.verbosity = NDDS_CONFIG_LOG_VERBOSITY_WARNING; |
| 57 | + break; |
| 58 | + case 3: |
| 59 | + arguments.verbosity = NDDS_CONFIG_LOG_VERBOSITY_STATUS_ALL; |
| 60 | + break; |
| 61 | + default: |
| 62 | + arguments.verbosity = NDDS_CONFIG_LOG_VERBOSITY_ERROR; |
| 63 | + break; |
67 | 64 | } |
| 65 | +} |
68 | 66 |
|
69 | | - // Parses application arguments for example. Returns whether to exit. |
70 | | - inline void parse_arguments( |
71 | | - ApplicationArguments& arguments, |
| 67 | +// Parses application arguments for example. Returns whether to exit. |
| 68 | +inline void parse_arguments( |
| 69 | + ApplicationArguments &arguments, |
72 | 70 | int argc, |
73 | 71 | char *argv[]) |
74 | | - { |
75 | | - int arg_processing = 1; |
76 | | - bool show_usage = false; |
77 | | - arguments.domain_id = 0; |
78 | | - arguments.sample_count = INT_MAX; |
79 | | - arguments.verbosity = NDDS_CONFIG_LOG_VERBOSITY_ERROR; |
80 | | - arguments.parse_result = PARSE_RETURN_OK; |
| 72 | +{ |
| 73 | + int arg_processing = 1; |
| 74 | + bool show_usage = false; |
| 75 | + arguments.domain_id = 0; |
| 76 | + arguments.sample_count = INT_MAX; |
| 77 | + arguments.verbosity = NDDS_CONFIG_LOG_VERBOSITY_ERROR; |
| 78 | + arguments.parse_result = PARSE_RETURN_OK; |
81 | 79 |
|
82 | | - while (arg_processing < argc) { |
83 | | - if ((argc > arg_processing + 1) |
| 80 | + while (arg_processing < argc) { |
| 81 | + if ((argc > arg_processing + 1) |
84 | 82 | && (strcmp(argv[arg_processing], "-d") == 0 |
85 | | - || strcmp(argv[arg_processing], "--domain") == 0)) { |
86 | | - arguments.domain_id = atoi(argv[arg_processing + 1]); |
87 | | - arg_processing += 2; |
88 | | - } else if ((argc > arg_processing + 1) |
89 | | - && (strcmp(argv[arg_processing], "-s") == 0 |
90 | | - || strcmp(argv[arg_processing], "--sample-count") == 0)) { |
91 | | - arguments.sample_count = atoi(argv[arg_processing + 1]); |
92 | | - arg_processing += 2; |
93 | | - } else if ((argc > arg_processing + 1) |
94 | | - && (strcmp(argv[arg_processing], "-v") == 0 |
95 | | - || strcmp(argv[arg_processing], "--verbosity") == 0)) { |
96 | | - set_verbosity(arguments, atoi(argv[arg_processing + 1])); |
97 | | - arg_processing += 2; |
98 | | - } else if (strcmp(argv[arg_processing], "-h") == 0 |
99 | | - || strcmp(argv[arg_processing], "--help") == 0) { |
100 | | - std::cout << "Example application." << std::endl; |
101 | | - show_usage = true; |
102 | | - arguments.parse_result = PARSE_RETURN_EXIT; |
103 | | - break; |
104 | | - } else { |
105 | | - std::cout << "Bad parameter." << std::endl; |
106 | | - show_usage = true; |
107 | | - arguments.parse_result = PARSE_RETURN_FAILURE; |
108 | | - break; |
109 | | - } |
110 | | - } |
111 | | - if (show_usage) { |
112 | | - std::cout << "Usage:\n"\ |
113 | | - " -d, --domain <int> Domain ID this application will\n" \ |
114 | | - " subscribe in. \n" |
115 | | - " Default: 0\n"\ |
116 | | - " -s, --sample_count <int> Number of samples to receive before\n"\ |
117 | | - " cleanly shutting down. \n" |
118 | | - " Default: infinite\n" |
119 | | - " -v, --verbosity <int> How much debugging output to show.\n"\ |
120 | | - " Range: 0-3 \n" |
121 | | - " Default: 1" |
122 | | - << std::endl; |
| 83 | + || strcmp(argv[arg_processing], "--domain") == 0)) { |
| 84 | + arguments.domain_id = atoi(argv[arg_processing + 1]); |
| 85 | + arg_processing += 2; |
| 86 | + } else if ( |
| 87 | + (argc > arg_processing + 1) |
| 88 | + && (strcmp(argv[arg_processing], "-s") == 0 |
| 89 | + || strcmp(argv[arg_processing], "--sample-count") == 0)) { |
| 90 | + arguments.sample_count = atoi(argv[arg_processing + 1]); |
| 91 | + arg_processing += 2; |
| 92 | + } else if ( |
| 93 | + (argc > arg_processing + 1) |
| 94 | + && (strcmp(argv[arg_processing], "-v") == 0 |
| 95 | + || strcmp(argv[arg_processing], "--verbosity") == 0)) { |
| 96 | + set_verbosity(arguments, atoi(argv[arg_processing + 1])); |
| 97 | + arg_processing += 2; |
| 98 | + } else if ( |
| 99 | + strcmp(argv[arg_processing], "-h") == 0 |
| 100 | + || strcmp(argv[arg_processing], "--help") == 0) { |
| 101 | + std::cout << "Example application." << std::endl; |
| 102 | + show_usage = true; |
| 103 | + arguments.parse_result = PARSE_RETURN_EXIT; |
| 104 | + break; |
| 105 | + } else { |
| 106 | + std::cout << "Bad parameter." << std::endl; |
| 107 | + show_usage = true; |
| 108 | + arguments.parse_result = PARSE_RETURN_FAILURE; |
| 109 | + break; |
123 | 110 | } |
124 | 111 | } |
| 112 | + if (show_usage) { |
| 113 | + std::cout << "Usage:\n" |
| 114 | + " -d, --domain <int> Domain ID this " |
| 115 | + "application will\n" |
| 116 | + " subscribe in. \n" |
| 117 | + " Default: 0\n" |
| 118 | + " -s, --sample_count <int> Number of samples to " |
| 119 | + "receive before\n" |
| 120 | + " cleanly shutting down. \n" |
| 121 | + " Default: infinite\n" |
| 122 | + " -v, --verbosity <int> How much debugging output " |
| 123 | + "to show.\n" |
| 124 | + " Range: 0-3 \n" |
| 125 | + " Default: 1" |
| 126 | + << std::endl; |
| 127 | + } |
| 128 | +} |
125 | 129 |
|
126 | 130 | } // namespace application |
127 | 131 |
|
|
0 commit comments