Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others. 4 : // This program and the accompanying materials are made available under the 5 : // terms of the Eclipse Public License 2.0 which is available at 6 : // https://www.eclipse.org/legal/epl-2.0/ 7 : // This Source Code may also be made available under the following Secondary 8 : // Licenses when the conditions for such availability set forth in the Eclipse 9 : // Public License 2.0 are satisfied: GNU General Public License, version 2 10 : // or later which is available at 11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 13 : /****************************************************************************/ 14 : /// @file tracitestclient_main.cpp 15 : /// @author Friedemann Wesner 16 : /// @author Axel Wegener 17 : /// @author Michael Behrisch 18 : /// @author Daniel Krajzewicz 19 : /// @date 2008/04/07 20 : /// 21 : // Main method for TraCITestClient 22 : /****************************************************************************/ 23 : #include <config.h> 24 : 25 : #include <iostream> 26 : #include <string> 27 : #include <cstdlib> 28 : #include "TraCITestClient.h" 29 : 30 : 31 : // =========================================================================== 32 : // method definitions 33 : // =========================================================================== 34 1184 : int main(int argc, char* argv[]) { 35 1184 : std::string defFile = ""; 36 1184 : std::string outFileName = "testclient_out.txt"; 37 : int port = -1; 38 1184 : std::string host = "localhost"; 39 : 40 1184 : if ((argc == 1) || (argc % 2 == 0)) { 41 : std::cout << "Usage: TraCITestClient -def <definition_file> -p <remote port>" 42 : << "[-h <remote host>] [-o <outputfile name>]" << std::endl; 43 : return 0; 44 : } 45 : 46 4736 : for (int i = 1; i < argc; i++) { 47 3552 : std::string arg = argv[i]; 48 3552 : if (arg.compare("-def") == 0) { 49 1184 : defFile = argv[i + 1]; 50 1184 : i++; 51 2368 : } else if (arg.compare("-o") == 0) { 52 1184 : outFileName = argv[i + 1]; 53 1184 : i++; 54 1184 : } else if (arg.compare("-p") == 0) { 55 1184 : port = atoi(argv[i + 1]); 56 1184 : i++; 57 0 : } else if (arg.compare("-h") == 0) { 58 0 : host = argv[i + 1]; 59 0 : i++; 60 : } else { 61 0 : std::cerr << "unknown parameter: " << argv[i] << std::endl; 62 : return 1; 63 : } 64 : } 65 : 66 1184 : if (port == -1) { 67 : std::cerr << "Missing port" << std::endl; 68 : return 1; 69 : } 70 1184 : if (defFile.compare("") == 0) { 71 : std::cerr << "Missing definition file" << std::endl; 72 : return 1; 73 : } 74 : 75 : try { 76 2368 : TraCITestClient client(outFileName); 77 2368 : return client.run(defFile, port, host); 78 1185 : } catch (tcpip::SocketException& e) { 79 1 : std::cerr << "Socket error running the test client: " << e.what(); 80 : return 1; 81 1 : } catch (libsumo::TraCIException& e) { 82 0 : std::cerr << "TraCI error running the test client: " << e.what(); 83 : return 1; 84 0 : } 85 : }