| 201 | }; |
| 202 | |
| 203 | int main(int argc, char** argv) { |
| 204 | uint32_t cycle = 1000; // default 1s |
| 205 | |
| 206 | std::string cycle_arg("--cycle"); |
| 207 | |
| 208 | for (int i = 1; i < argc; i++) { |
| 209 | if (cycle_arg == argv[i] && i + 1 < argc) { |
| 210 | i++; |
| 211 | std::stringstream converter; |
| 212 | converter << argv[i]; |
| 213 | converter >> cycle; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | #ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING |
| 218 | #if defined(__linux__) || defined(__QNX__) |
| 219 | sigset_t its_signals; |
| 220 | sigemptyset(&its_signals); |
| 221 | sigaddset(&its_signals, SIGINT); |
| 222 | sigaddset(&its_signals, SIGTERM); |
| 223 | pthread_sigmask(SIG_BLOCK, &its_signals, nullptr); |
| 224 | #endif |
| 225 | #endif |
| 226 | |
| 227 | service_sample its_sample(cycle); |
| 228 | if (its_sample.init()) { |
| 229 | #ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING |
| 230 | #if defined(__linux__) || defined(__QNX__) |
| 231 | std::thread signal_watcher([&its_sample]() { |
| 232 | sigset_t its_wait_set; |
| 233 | sigemptyset(&its_wait_set); |
| 234 | sigaddset(&its_wait_set, SIGINT); |
| 235 | sigaddset(&its_wait_set, SIGTERM); |
| 236 | |
| 237 | int its_signal = 0; |
| 238 | while (sigwait(&its_wait_set, &its_signal) == 0) { |
| 239 | if (its_signal == SIGINT || its_signal == SIGTERM) { |
| 240 | its_sample.stop(); |
| 241 | return; |
| 242 | } |
| 243 | } |
| 244 | }); |
| 245 | #endif |
| 246 | #endif |
| 247 | its_sample.start(); |
| 248 | #ifdef VSOMEIP_ENABLE_SIGNAL_HANDLING |
| 249 | its_sample.stop(); |
| 250 | #endif |
| 251 | #ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING |
| 252 | #if defined(__linux__) || defined(__QNX__) |
| 253 | if (signal_watcher.joinable()) { |
| 254 | signal_watcher.join(); |
| 255 | } |
| 256 | #endif |
| 257 | #endif |
| 258 | return 0; |
| 259 | } else { |
| 260 | return 1; |