// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /*! * @file main.cxx * This file acts as a main entry point to the application. * * This file was generated by the tool fastddsgen. */ #include #include #include #include #include #include #include #include "Subscriber.hpp" #include "Publisher.hpp" #include "httpserver.hpp" #include "DEBUG.hpp" using eprosima::fastdds::dds::Log; std::function stop_handler; void signal_handler( int signum) { stop_handler(signum); } std::string parse_signal( const int& signum) { switch (signum) { case SIGINT: return "SIGINT"; case SIGTERM: return "SIGTERM"; #ifndef _WIN32 case SIGQUIT: return "SIGQUIT"; case SIGHUP: return "SIGHUP"; #endif // _WIN32 default: return "UNKNOWN SIGNAL"; } } int main(int argc, char** argv) { auto ret = EXIT_SUCCESS; // std::shared_ptr sub; std::shared_ptr pub; std::shared_ptr dev; int domain_id = 0; int port = 8080; for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "--domain") == 0 && i + 1 < argc) { domain_id = atoi(argv[++i]); } else if (strcmp(argv[i], "--port") == 0 && i + 1 < argc) { port = atoi(argv[++i]); } else if (strcmp(argv[i], "--version") == 0) { std::cout << "Vesrion: " << PROGRAM_VERSION << "\n"; return EXIT_SUCCESS; } else if (strcmp(argv[i], "--help") == 0) { std::cout << "Usage: [options]\n" << "Options:\n" << " --domain Set domain ID\n" << " --port Set port name (e.g., 8080)\n" << " --version Show software Version\n" << " --help Show this help message\n"; return EXIT_SUCCESS; } else { std::cerr << "Unknown option: " << argv[i] << "\n"; std::cout << "Usage: [options]\n" << "Options:\n" << " --domain Set domain ID\n" << " --port Set port name (e.g., 8080)\n" << " --version Show software Version\n" << " --help Show this help message\n"; return EXIT_FAILURE; } } // sub = std::make_shared(domain_id); pub = std::make_shared(domain_id); dev = std::make_shared(); dev->SetPort(port); dev->start(); std::thread pub_thread(&PublisherApp::run, pub, dev); DEBUG("Program is running. Please press Ctrl+C to stop at any time."); stop_handler = [&](int signum) { std::cout << "\n" << parse_signal(signum) << " received, stopping " << argv[1] << " execution." << std::endl; pub->stop(); }; signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); #ifndef _WIN32 signal(SIGQUIT, signal_handler); signal(SIGHUP, signal_handler); #endif // _WIN32 pub_thread.join(); Log::Reset(); return ret; }