| 140 | }; |
| 141 | |
| 142 | int main(int argc, char** argv) { |
| 143 | bool use_static_routing(false); |
| 144 | |
| 145 | std::string static_routing_enable("--static-routing"); |
| 146 | |
| 147 | for (int i = 1; i < argc; i++) { |
| 148 | if (static_routing_enable == argv[i]) { |
| 149 | use_static_routing = true; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | #ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING |
| 154 | #if defined(__linux__) || defined(__QNX__) |
| 155 | sigset_t its_signals; |
| 156 | sigemptyset(&its_signals); |
| 157 | sigaddset(&its_signals, SIGINT); |
| 158 | sigaddset(&its_signals, SIGTERM); |
| 159 | pthread_sigmask(SIG_BLOCK, &its_signals, nullptr); |
| 160 | #endif |
| 161 | #endif |
| 162 | |
| 163 | service_sample its_sample(use_static_routing); |
| 164 | if (its_sample.init()) { |
| 165 | #ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING |
| 166 | #if defined(__linux__) || defined(__QNX__) |
| 167 | std::thread signal_watcher([&its_sample]() { |
| 168 | sigset_t its_wait_set; |
| 169 | sigemptyset(&its_wait_set); |
| 170 | sigaddset(&its_wait_set, SIGINT); |
| 171 | sigaddset(&its_wait_set, SIGTERM); |
| 172 | |
| 173 | int its_signal = 0; |
| 174 | while (sigwait(&its_wait_set, &its_signal) == 0) { |
| 175 | if (its_signal == SIGINT || its_signal == SIGTERM) { |
| 176 | its_sample.stop(); |
| 177 | return; |
| 178 | } |
| 179 | } |
| 180 | }); |
| 181 | #endif |
| 182 | #endif |
| 183 | its_sample.start(); |
| 184 | #ifdef VSOMEIP_ENABLE_SIGNAL_HANDLING |
| 185 | its_sample.stop(); |
| 186 | #endif |
| 187 | #ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING |
| 188 | #if defined(__linux__) || defined(__QNX__) |
| 189 | if (signal_watcher.joinable()) { |
| 190 | signal_watcher.join(); |
| 191 | } |
| 192 | #endif |
| 193 | #endif |
| 194 | return 0; |
| 195 | } else { |
| 196 | return 1; |
| 197 | } |
| 198 | } |